2025-11-11 14:46:30 +01:00

50 lines
1.2 KiB
TypeScript

import React from "react";
import { Stack, Typography, Button } from "@mui/material";
interface ConfirmProps {
onSubmit: () => void | Promise<void>;
onClose: () => void;
message?: string;
confirmLabel?: string;
cancelLabel?: string;
disabled?: boolean;
}
/**
* Simple confirmation content to be rendered inside the shared Modal.
* Shows an "Are you sure?" message and calls the parent's onSubmit when confirmed.
*/
const Confirm: React.FC<ConfirmProps> = ({
onSubmit,
onClose,
message = "Are you sure you want to continue?",
confirmLabel = "Yes, continue",
cancelLabel = "Cancel",
disabled = false,
}) => {
const handleConfirm = async () => {
await Promise.resolve(onSubmit());
};
return (
<Stack spacing={3}>
<Typography variant="body1">{message}</Typography>
<Stack direction="row" spacing={2} justifyContent="flex-end">
<Button variant="outlined" onClick={onClose} disabled={disabled}>
{cancelLabel}
</Button>
<Button
color="primary"
variant="contained"
onClick={handleConfirm}
disabled={disabled}
>
{confirmLabel}
</Button>
</Stack>
</Stack>
);
};
export default Confirm;