ldc-ovoteam/resources/ts/back/Pages/Users/Create.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

68 lines
1.9 KiB
TypeScript

import { usePage } from "@inertiajs/react";
import { ArrowLeftIcon } from "lucide-react";
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout";
import { Actions, Methods } from "@/back/lib/enums";
import Form from "@/back/Pages/Users/Form";
import type {
AuthProp,
ConfigBackend,
SingleResource,
UserModel,
} from "@/back/types/global";
import trans from "@/hooks/use-translations";
export default function Create({
data,
modelName,
}: Readonly<{
data: SingleResource;
modelName: string;
}>) {
const routeName = (usePage().props.configBackend as ConfigBackend).routes
.name;
const { viewAny } = (usePage().props.auth as AuthProp).policies.users;
const model = data.data as UserModel;
// Translations.
const transBackToList = trans("uwil-backend::back.crud_back_to_list");
const transTitle = trans(
route().current(`${routeName}${modelName}.duplicate`)
? "uwil-backend::crud.helpers.duplication_model"
: "uwil-backend::crud.helpers.creation_model",
{
params: {
model: trans(`uwil-backend::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()}>
<Form
model={model}
modelName={modelName}
modelRoute={modelName}
action={Actions.STORE}
method={Methods.POST}
/>
</AuthenticatedLayout>
);
}