67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
// * Packages
|
|
import { usePage } from "@inertiajs/react";
|
|
import { route } from "ziggy-js";
|
|
import { ArrowLeft } from "lucide-react";
|
|
// * Other
|
|
import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout";
|
|
|
|
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
|
|
import useTrans from "@/hooks/use-translations";
|
|
import { Actions, Methods } from "@/lib/enums";
|
|
import { AuthProp, SingleResource } from "@/back/types/global";
|
|
import { DocumentModel } from "@/back/types/others";
|
|
import Form from "@/back/Pages/Document/Form";
|
|
import str from "@/hooks/use-string";
|
|
|
|
export default function Create({
|
|
data,
|
|
modelName,
|
|
}: {
|
|
data: SingleResource;
|
|
modelName: string;
|
|
}) {
|
|
const { viewAny } = (usePage().props.auth as AuthProp).policies.documents;
|
|
const documentModel = data.data as DocumentModel;
|
|
const singularModelName = str(modelName).singular().value();
|
|
|
|
// Translations.
|
|
const transBackToList = useTrans("back.crud_back_to_list");
|
|
const transTitle = useTrans(
|
|
route().current(`back.${modelName}.duplicate`)
|
|
? "crud.helpers.duplication_model"
|
|
: "crud.helpers.creation_model",
|
|
{
|
|
params: {
|
|
model: useTrans(`models.classes.${singularModelName}`, {
|
|
choice: 1,
|
|
}),
|
|
},
|
|
},
|
|
);
|
|
|
|
const beforeNode = () => {
|
|
return (
|
|
viewAny && (
|
|
<div className="flex justify-end items-center gap-x-1.5">
|
|
<BtnOptionnalLinkWithTooltip
|
|
link={route(`back.${modelName}.index`)}
|
|
content={<ArrowLeft />}
|
|
tooltipContent={<p>{transBackToList}</p>}
|
|
/>
|
|
</div>
|
|
)
|
|
);
|
|
};
|
|
|
|
return (
|
|
<AuthenticatedLayout title={transTitle} beforeNode={beforeNode()}>
|
|
<Form
|
|
model={documentModel}
|
|
modelName={singularModelName}
|
|
modelRoute={modelName}
|
|
action={Actions.STORE}
|
|
method={Methods.POST}
|
|
/>
|
|
</AuthenticatedLayout>
|
|
);
|
|
}
|