️ 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 { color } from '@material-tailwind/react/types/components/button';
import React, { ReactNode } from 'react';
import { Modal, ModalProps } from './Modal';
import { Button } from './Button';
import { Button, ButtonOrLinkProps } from './Button';
type ConfirmDialogProp = ModalProps & {
children: React.ReactNode;
dialogTitle: string;
export type ConfirmDialogProps = ModalProps & {
children?: ReactNode;
dialogTitle?: string;
open: boolean;
handleOpen: () => void;
confirmButtonTitle: string;
handleCancel: () => void;
confirmButtonTitle?: string;
handleConfirm?: () => void;
color: color;
cancelButtonProps?: ButtonOrLinkProps;
confirmButtonProps?: ButtonOrLinkProps;
};
const ConfirmDialog = ({
children,
dialogTitle,
handleOpen,
handleCancel,
confirmButtonTitle,
handleConfirm,
cancelButtonProps,
confirmButtonProps,
...props
}: ConfirmDialogProp) => {
}: ConfirmDialogProps) => {
// Close the dialog when the user clicks outside of it
const handleOpenChange = (open: boolean) => {
if (!open) return handleCancel?.();
};
return (
<Modal {...props}>
<Modal {...props} onOpenChange={handleOpenChange}>
<Modal.Content>
<Modal.Header>{dialogTitle}</Modal.Header>
<Modal.Body>{children}</Modal.Body>
<Modal.Footer className="flex justify-start gap-2">
<Button variant="tertiary" onClick={handleOpen}>
<Modal.Footer>
<Button
variant="tertiary"
onClick={handleCancel}
{...cancelButtonProps}
>
Cancel
</Button>
<Button onClick={handleConfirm}>{confirmButtonTitle}</Button>
<Button onClick={handleConfirm} {...confirmButtonProps}>
{confirmButtonTitle}
</Button>
</Modal.Footer>
</Modal.Content>
</Modal>