⚡️ feat: update confirm dialog to use new modal component
This commit is contained in:
parent
102c861617
commit
3674750011
@ -1,37 +1,49 @@
|
|||||||
import React from 'react';
|
import React, { ReactNode } from 'react';
|
||||||
|
|
||||||
import { color } from '@material-tailwind/react/types/components/button';
|
|
||||||
import { Modal, ModalProps } from './Modal';
|
import { Modal, ModalProps } from './Modal';
|
||||||
import { Button } from './Button';
|
import { Button, ButtonOrLinkProps } from './Button';
|
||||||
|
|
||||||
type ConfirmDialogProp = ModalProps & {
|
export type ConfirmDialogProps = ModalProps & {
|
||||||
children: React.ReactNode;
|
children?: ReactNode;
|
||||||
dialogTitle: string;
|
dialogTitle?: string;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
handleOpen: () => void;
|
handleCancel: () => void;
|
||||||
confirmButtonTitle: string;
|
confirmButtonTitle?: string;
|
||||||
handleConfirm?: () => void;
|
handleConfirm?: () => void;
|
||||||
color: color;
|
cancelButtonProps?: ButtonOrLinkProps;
|
||||||
|
confirmButtonProps?: ButtonOrLinkProps;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ConfirmDialog = ({
|
const ConfirmDialog = ({
|
||||||
children,
|
children,
|
||||||
dialogTitle,
|
dialogTitle,
|
||||||
handleOpen,
|
handleCancel,
|
||||||
confirmButtonTitle,
|
confirmButtonTitle,
|
||||||
handleConfirm,
|
handleConfirm,
|
||||||
|
cancelButtonProps,
|
||||||
|
confirmButtonProps,
|
||||||
...props
|
...props
|
||||||
}: ConfirmDialogProp) => {
|
}: ConfirmDialogProps) => {
|
||||||
|
// Close the dialog when the user clicks outside of it
|
||||||
|
const handleOpenChange = (open: boolean) => {
|
||||||
|
if (!open) return handleCancel?.();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal {...props}>
|
<Modal {...props} onOpenChange={handleOpenChange}>
|
||||||
<Modal.Content>
|
<Modal.Content>
|
||||||
<Modal.Header>{dialogTitle}</Modal.Header>
|
<Modal.Header>{dialogTitle}</Modal.Header>
|
||||||
<Modal.Body>{children}</Modal.Body>
|
<Modal.Body>{children}</Modal.Body>
|
||||||
<Modal.Footer className="flex justify-start gap-2">
|
<Modal.Footer>
|
||||||
<Button variant="tertiary" onClick={handleOpen}>
|
<Button
|
||||||
|
variant="tertiary"
|
||||||
|
onClick={handleCancel}
|
||||||
|
{...cancelButtonProps}
|
||||||
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={handleConfirm}>{confirmButtonTitle}</Button>
|
<Button onClick={handleConfirm} {...confirmButtonProps}>
|
||||||
|
{confirmButtonTitle}
|
||||||
|
</Button>
|
||||||
</Modal.Footer>
|
</Modal.Footer>
|
||||||
</Modal.Content>
|
</Modal.Content>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
Loading…
Reference in New Issue
Block a user