link-stack/apps/bridge-frontend/app/_components/Edit.tsx

56 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-03-16 19:39:20 +01:00
"use client";
2024-04-25 12:31:03 +02:00
import { FC, useEffect } from "react";
import { 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 { Button, Dialog } from "ui";
2024-03-16 19:39:20 +01:00
interface EditProps {
title: string;
entity: string;
2024-04-25 12:31:03 +02:00
formAction: any;
formState: any;
2024-03-16 19:39:20 +01:00
children: any;
}
2024-04-25 12:31:03 +02:00
export const Edit: FC<EditProps> = ({
title,
entity,
formState,
formAction,
children,
}) => {
2024-03-16 19:39:20 +01:00
const router = useRouter();
2024-04-25 12:31:03 +02:00
useEffect(() => {
if (formState.success) {
router.push(`/${entity}`);
}
}, [formState.success, router]);
2024-03-16 19:39:20 +01:00
return (
2024-04-25 12:31:03 +02:00
<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>
2024-03-16 19:39:20 +01:00
</Grid>
2024-04-25 12:31:03 +02:00
}
>
{children}
</Dialog>
2024-03-16 19:39:20 +01:00
);
};