️ feat: update confirm dialog to use new modal component

This commit is contained in:
Wahyu Kurniawan 2024-03-14 21:49:45 +07:00
parent 102c861617
commit 3674750011
No known key found for this signature in database
GPG Key ID: 040A1549143A8E33

View File

@ -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>