2024-03-16 19:39:20 +01:00
|
|
|
"use client";
|
|
|
|
|
|
2024-04-25 12:31:03 +02:00
|
|
|
import { FC, useState } from "react";
|
|
|
|
|
import { Box, Grid } from "@mui/material";
|
2024-03-16 19:39:20 +01:00
|
|
|
import { useRouter } from "next/navigation";
|
2024-04-25 12:31:03 +02:00
|
|
|
import { Dialog, Button, colors, typography } from "ui";
|
2024-03-16 19:39:20 +01:00
|
|
|
|
|
|
|
|
interface DetailProps {
|
|
|
|
|
title: string;
|
|
|
|
|
entity: string;
|
2024-04-24 21:44:05 +02:00
|
|
|
id: string;
|
2024-03-16 19:39:20 +01:00
|
|
|
children: any;
|
2024-04-25 12:31:03 +02:00
|
|
|
deleteAction?: Function;
|
2024-03-16 19:39:20 +01:00
|
|
|
}
|
|
|
|
|
|
2024-04-25 12:31:03 +02:00
|
|
|
export const Detail: FC<DetailProps> = ({
|
|
|
|
|
title,
|
|
|
|
|
entity,
|
|
|
|
|
id,
|
|
|
|
|
children,
|
|
|
|
|
deleteAction,
|
|
|
|
|
}) => {
|
2024-03-16 19:39:20 +01:00
|
|
|
const router = useRouter();
|
2024-04-25 12:31:03 +02:00
|
|
|
const { almostBlack } = colors;
|
|
|
|
|
const { bodyLarge } = typography;
|
|
|
|
|
const [showDeleteConfirmation, setShowDeleteConfirmation] = useState(false);
|
|
|
|
|
|
|
|
|
|
const continueDeleteAction = async () => {
|
|
|
|
|
await deleteAction?.(id);
|
|
|
|
|
setShowDeleteConfirmation(false);
|
|
|
|
|
router.push(`/${entity}`);
|
|
|
|
|
};
|
2024-03-16 19:39:20 +01:00
|
|
|
|
|
|
|
|
return (
|
2024-04-25 12:31:03 +02:00
|
|
|
<>
|
|
|
|
|
<Dialog
|
|
|
|
|
open
|
|
|
|
|
title={title}
|
|
|
|
|
onClose={() => router.push(`/${entity}`)}
|
|
|
|
|
buttons={
|
|
|
|
|
<Grid container justifyContent="space-between">
|
|
|
|
|
<Grid item container xs="auto" spacing={2}>
|
|
|
|
|
{deleteAction && (
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Button
|
|
|
|
|
text="Delete"
|
|
|
|
|
kind="destructive"
|
|
|
|
|
onClick={() => setShowDeleteConfirmation(true)}
|
|
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
)}
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Button
|
|
|
|
|
text="Edit"
|
|
|
|
|
kind="secondary"
|
|
|
|
|
href={`/${entity}/${id}/edit`}
|
|
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Grid>
|
2024-04-24 21:44:05 +02:00
|
|
|
<Grid item>
|
2024-04-25 12:31:03 +02:00
|
|
|
<Button text="Done" kind="primary" href={`/${entity}`} />
|
2024-04-24 21:44:05 +02:00
|
|
|
</Grid>
|
2024-04-25 12:31:03 +02:00
|
|
|
</Grid>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</Dialog>
|
|
|
|
|
<Dialog
|
|
|
|
|
open={showDeleteConfirmation}
|
|
|
|
|
size="xs"
|
|
|
|
|
title="Really delete?"
|
|
|
|
|
buttons={
|
|
|
|
|
<Grid container justifyContent="space-between">
|
2024-04-24 21:44:05 +02:00
|
|
|
<Grid item>
|
|
|
|
|
<Button
|
2024-04-25 12:31:03 +02:00
|
|
|
text="Cancel"
|
2024-04-24 21:44:05 +02:00
|
|
|
kind="secondary"
|
2024-04-25 12:31:03 +02:00
|
|
|
onClick={() => setShowDeleteConfirmation(false)}
|
|
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Button
|
|
|
|
|
text="Delete"
|
|
|
|
|
kind="destructive"
|
|
|
|
|
onClick={continueDeleteAction}
|
2024-04-24 21:44:05 +02:00
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Grid>
|
2024-04-25 12:31:03 +02:00
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<Box sx={{ ...bodyLarge, color: almostBlack }}>
|
|
|
|
|
Are you sure you want to delete this record?
|
|
|
|
|
</Box>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</>
|
2024-03-16 19:39:20 +01:00
|
|
|
);
|
|
|
|
|
};
|