ldc-ovoteam/resources/ts/back/Pages/DynamicPages/Edit.tsx
Jérémy Munsch cd2d8ed397
refactor(i18n): replace GetTranslation with trans function
- Updated translation utility to improve consistency and reduce redundancy.
- Removed deprecated useTrans hook and related code.
- Introduced a new Zustand store for managing translations and locale settings.
- Cleaned up unused hooks and files related to localization.
2026-10-19 17:43:33 +02:00

76 lines
2.2 KiB
TypeScript

import { usePage } from "@inertiajs/react";
import { ArrowLeftIcon } from "lucide-react";
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
import ModelActions from "@/back/Components/ModelActions";
import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout";
import { Views } from "@/back/lib/actions";
import { Actions, Methods } from "@/back/lib/enums";
import Form from "@/back/Pages/DynamicPages/Form";
import type { DynamicPageModel } from "@/back/types/dynamic-pages";
import type {
AuthProp,
ConfigBackend,
SingleResource,
} from "@/back/types/global";
import trans from "@/hooks/use-translations";
export default function Edit({
data,
modelName,
}: Readonly<{
data: SingleResource;
modelName: string;
}>) {
const routeName = (usePage().props.configBackend as ConfigBackend).routes
.name;
const { viewAny } = (usePage().props.auth as AuthProp).policies.dynamicPages;
const dynamicPageModel = data.data as DynamicPageModel;
const actionModels = [
Views.VISUALIZATION,
Views.DUPLICATION,
Views.ARCHIVATION,
];
// Translations.
const transBackToList = trans("uwil-backend::back.crud_back_to_list");
const transTitle = trans("uwil-backend::crud.helpers.edition_model", {
params: {
model: trans(`uwil-dynamic-pages::models.classes.${modelName}`, {
choice: 1,
}),
},
});
const beforeNode = () => {
return (
viewAny && (
<div className="flex justify-end items-center gap-x-1.5">
<BtnOptionnalLinkWithTooltip
link={route(`${routeName}${modelName}.index`)}
content={<ArrowLeftIcon />}
tooltipContent={<p>{transBackToList}</p>}
/>
</div>
)
);
};
return (
<AuthenticatedLayout title={transTitle} beforeNode={beforeNode()}>
<ModelActions
actions={actionModels}
modelRoute={modelName}
model={dynamicPageModel}
modelUpdatedAt={dynamicPageModel.updated_at?.toString()}
/>
<Form
model={dynamicPageModel}
modelName={modelName}
modelRoute={modelName}
action={Actions.UPDATE}
method={Methods.PATCH}
/>
</AuthenticatedLayout>
);
}