2024-04-24 21:44:05 +02:00
|
|
|
"use client";
|
|
|
|
|
|
2024-04-25 12:31:03 +02:00
|
|
|
import { FC, useEffect } from "react";
|
2024-04-24 21:44:05 +02:00
|
|
|
import { Grid } from "@mui/material";
|
|
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
import { Button, Dialog } from "ui";
|
|
|
|
|
|
|
|
|
|
interface CreateProps {
|
|
|
|
|
title: string;
|
|
|
|
|
entity: string;
|
|
|
|
|
formAction: any;
|
2024-04-25 12:31:03 +02:00
|
|
|
formState: any;
|
2024-04-24 21:44:05 +02:00
|
|
|
children: any;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const Create: FC<CreateProps> = ({
|
|
|
|
|
title,
|
|
|
|
|
entity,
|
|
|
|
|
formAction,
|
2024-04-25 12:31:03 +02:00
|
|
|
formState,
|
2024-04-24 21:44:05 +02:00
|
|
|
children,
|
|
|
|
|
}) => {
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
2024-04-25 12:31:03 +02:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (formState.success) {
|
|
|
|
|
router.back();
|
|
|
|
|
}
|
|
|
|
|
}, [formState.success, router]);
|
|
|
|
|
|
2024-04-24 21:44:05 +02:00
|
|
|
return (
|
|
|
|
|
<Dialog
|
|
|
|
|
open
|
|
|
|
|
title={title}
|
|
|
|
|
formAction={formAction}
|
|
|
|
|
onClose={() => router.push(`/${entity}`)}
|
|
|
|
|
buttons={
|
|
|
|
|
<Grid container justifyContent="space-between">
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Button
|
|
|
|
|
text="Cancel"
|
|
|
|
|
kind="secondary"
|
|
|
|
|
onClick={() => router.push(`/${entity}`)}
|
|
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Button text="Save" kind="primary" type="submit" />
|
|
|
|
|
</Grid>
|
|
|
|
|
</Grid>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
};
|