61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
// * Packages
|
|
import { usePage } from "@inertiajs/react";
|
|
import { ArrowLeftIcon } from "lucide-react";
|
|
import { route } from "ziggy-js";
|
|
// * Other
|
|
import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout";
|
|
import ModelActions from "@/back/Components/ModelActions";
|
|
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
|
|
import Form from "@/back/Pages/DynamicPages/Form";
|
|
import useTrans from "@/hooks/use-translations";
|
|
import { Actions, Methods } from "@/lib/enums";
|
|
import { Views } from "@/lib/utils";
|
|
import { AuthProp, SingleResource, DynamicPageModel } from "@/back/types/global";
|
|
import str from "@/hooks/use-string";
|
|
|
|
export default function Edit({ data, modelName }: { data: SingleResource, modelName: string }) {
|
|
const { viewAny } = (usePage().props.auth as AuthProp).policies.dynamicPages;
|
|
const dynamicPageModel = data.data as DynamicPageModel;
|
|
const actionModels = [
|
|
Views.VISUALIZATION,
|
|
Views.DUPLICATION,
|
|
Views.ARCHIVATION,
|
|
];
|
|
const singularModelName = str(modelName).singular().value();
|
|
const transTitle = useTrans("crud.helpers.edition_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={<ArrowLeftIcon />}
|
|
tooltipContent={<p>{useTrans("back.crud_back_to_list")}</p>}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
return (
|
|
<AuthenticatedLayout
|
|
title={transTitle}
|
|
beforeNode={beforeNode()}
|
|
>
|
|
<ModelActions
|
|
actions={actionModels}
|
|
modelRoute={modelName}
|
|
model={dynamicPageModel}
|
|
modelUpdatedAt={dynamicPageModel.updated_at.toString()}
|
|
/>
|
|
<Form
|
|
model={dynamicPageModel}
|
|
modelName={singularModelName}
|
|
modelRoute={modelName}
|
|
action={Actions.UPDATE}
|
|
method={Methods.PATCH}
|
|
/>
|
|
</AuthenticatedLayout>
|
|
);
|
|
}
|