Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add custom alert modal #474

Merged
merged 3 commits into from
Dec 12, 2024
Merged

Add custom alert modal #474

merged 3 commits into from
Dec 12, 2024

Conversation

hikasap
Copy link
Contributor

@hikasap hikasap commented Dec 12, 2024

Motivation

This feature introduces a reusable and customizable alert modal component, enhancing user interactions with consistent and visually appealing confirmation dialogs. It allows developers to easily invoke modals for confirmation and alert purposes without duplicating code, improving maintainability and user experience.

Key Changes

  1. Added React Modal Library

    • Installed react-modal version 3.16.1 for modal functionality.
  2. Alert Modal Component

    • Created AlertModal.js to display a customizable modal dialog.
    • Supports customizable messages, confirm/cancel buttons, and danger styling.
  3. Alert Modal Context

    • Added AlertModalContext.js to manage modal states using React Context API.
    • Provides showModal and hideModal functions for ease of use.
  4. Integrated Context in Application

    • Wrapped the application in AlertModalProvider in App.js for global modal access.
  5. Styling

    • Created AlertModal.css for consistent modal styling across the application.
  6. Updated Dependencies

    • Modified package.json and package-lock.json to include the new library.

How to Use

  • Import useAlertModal from AlertModalContext.js in any component.
  • Call showModal with the required parameters to display the modal.
  • Customize button texts, actions, and styles as needed.

Example Usage

import { useAlertModal } from "./components/alert/AlertModalContext";

const ExampleComponent = () => {
  const { showModal } = useAlertModal();

  const handleDelete = () => {
    showModal(
      "Are you sure you want to delete this item?",
      () => console.log("Confirmed!"),
      () => console.log("Cancelled!"),
      true // isDanger
    );
  };

  return <button onClick={handleDelete}>Delete Item</button>;
};

@hikasap hikasap added the frontend issue related with frontend label Dec 12, 2024
@hikasap hikasap added this to the 451 - Milestone 3 milestone Dec 12, 2024
@hikasap hikasap self-assigned this Dec 12, 2024
Copy link
Contributor

@rukiyeaslan rukiyeaslan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! lgtm

@hikasap hikasap merged commit 53777fe into dev Dec 12, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
frontend issue related with frontend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants