-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fe): confirm modal when leaving settings page (#2261)
* feat(fe): confirm modal when leaving settings page * feat(fe): add dark and bright mode * chore(fe): add comments for basemodal * fix(fe): decide darkmode at ConfirmModal * chore(fe): add explanation for BaseModal component * chore(fe): add explanation for Basemodal component_2 * chore(fe): change comment for BaseModal * fix(fe): change description props type to string from ReactNode * chore(fe): import types * chore(fe): change comment for basemodal * chore(fe): change comment for confirmmodal * fix(fe): move confirmNavigation to utils file * chore(fe): change darkmode props name for BaseModal * chore(fe): change frament tag to p tag * chore(fe): remove duplicate backdrop blur by setting it as a default class * fix(fe): change dependency for ConfirmNavigation * fix(fe): change dependency for ConfirmNavigation
- Loading branch information
1 parent
a82e9f0
commit b945f8e
Showing
5 changed files
with
155 additions
and
13 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
apps/frontend/app/(client)/(main)/settings/_components/ConfirmModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import BaseModal from '@/components/BaseModal' | ||
import { | ||
AlertDialogAction, | ||
AlertDialogCancel, | ||
AlertDialogFooter | ||
} from '@/components/shadcn/alert-dialog' | ||
|
||
interface ModalProps { | ||
open: boolean | ||
handleOpen: () => void | ||
handleClose: () => void | ||
confirmAction: () => void | ||
title?: string | ||
description?: string | ||
} | ||
|
||
/** | ||
* | ||
* ConfirmModal component renders a modal dialog with confirm and cancel actions. | ||
* | ||
* @param open - Determines if the modal is open. | ||
* @param handleClose - Function to close the modal. | ||
* @param confirmAction - Function to execute when the user confirms. | ||
* @param title - Title of the modal. | ||
* @param description - Description of the modal. | ||
* | ||
* @remarks | ||
* * AlertDialogFooter section (Button section) is separated using ConfirmModal component for reusability. | ||
*/ | ||
export default function ConfirmModal({ | ||
open, | ||
handleClose, | ||
confirmAction, | ||
title = '', | ||
description = '' | ||
}: ModalProps) { | ||
return ( | ||
<BaseModal | ||
handleClose={handleClose} | ||
title={title} | ||
open={open} | ||
description={description} | ||
darkMode={false} | ||
> | ||
<AlertDialogFooter> | ||
<AlertDialogAction | ||
className="border-none bg-slate-100 text-[#3333334D] hover:bg-slate-200" | ||
onClick={confirmAction} | ||
> | ||
Leave | ||
</AlertDialogAction> | ||
<AlertDialogCancel | ||
className="bg-primary hover:bg-primary-strong border-none text-white" | ||
onClick={handleClose} | ||
> | ||
Stay | ||
</AlertDialogCancel> | ||
</AlertDialogFooter> | ||
</BaseModal> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Loader2 } from 'lucide-react' | ||
import React, { type ReactNode } from 'react' | ||
import { | ||
AlertDialog, | ||
AlertDialogContent, | ||
AlertDialogDescription, | ||
AlertDialogHeader, | ||
AlertDialogOverlay, | ||
AlertDialogTitle | ||
} from './shadcn/alert-dialog' | ||
|
||
interface BaseModalProps { | ||
open: boolean | ||
handleClose: () => void | ||
children?: ReactNode | ||
loading?: boolean | ||
loadingMessage?: string | ||
title?: string | ||
description?: string | ||
darkMode?: boolean | ||
} | ||
|
||
/** | ||
* | ||
* @remarks | ||
* * Use BaseModal Component by creating a new component(which includes 'AlertDialogFooter') that extends BaseModal. | ||
* * AlertDialogFooter section (Button section) is separated using ConfirmModal component for reusability. | ||
*/ | ||
export default function BaseModal({ | ||
open, | ||
handleClose, | ||
children, | ||
loading = false, | ||
loadingMessage = '', | ||
title = '', | ||
description = '', | ||
darkMode = false | ||
}: BaseModalProps) { | ||
const formattedDescription = | ||
description.split('\n').map((line, index) => <p key={index}>{line}</p>) ?? | ||
'' | ||
|
||
return ( | ||
<AlertDialog open={open} onOpenChange={handleClose}> | ||
<AlertDialogOverlay darkMode={darkMode} /> | ||
<AlertDialogContent className="max-w-[428px]"> | ||
<AlertDialogHeader> | ||
<AlertDialogTitle>{title}</AlertDialogTitle> | ||
<AlertDialogDescription className="min-w-72"> | ||
{loading ? ( | ||
<div className="flex flex-col items-center justify-center"> | ||
<Loader2 size={32} className="animate-spin" /> | ||
<span className="mt-2 text-sm">{loadingMessage}</span> | ||
</div> | ||
) : ( | ||
formattedDescription | ||
)} | ||
</AlertDialogDescription> | ||
</AlertDialogHeader> | ||
{children} | ||
</AlertDialogContent> | ||
</AlertDialog> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters