ldc-ovoteam/resources/ts/back/Pages/Recipes/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

84 lines
2.4 KiB
TypeScript

import { route } from "ziggy-js";
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/Recipes/Form";
import { SingleResource } from "@/back/types/global";
import { RecipeModel, validateAsRecipeModel } from "@/back/types/recipes";
import usePermissions from "@/hooks/use-permissions";
import trans, { UseTransOptions } from "@/hooks/use-translations";
import { ArrowLeftIcon } from "lucide-react";
export default function Edit({
data,
}: Readonly<{
data: SingleResource;
}>) {
const { can } = usePermissions();
const viewAny = can("viewAny", String.raw`App\Models\Recipe`);
let recipe: RecipeModel | undefined;
try {
const hasData =
data?.data &&
(Array.isArray(data.data)
? data.data.length > 0
: Object.keys(data.data).length > 0);
if (hasData) {
recipe = validateAsRecipeModel(data.data);
}
} catch (error) {
console.warn("Zod validation failed, falling back to empty model.", error);
}
const actionModels = [
Views.VISUALIZATION,
Views.DUPLICATION,
Views.ARCHIVATION,
];
const transBackToList = trans("uwil-backend::back.crud_back_to_list");
const title = trans("uwil-backend::crud.helpers.edition_model", {
params: {
model: trans(`models.classes.recipe`, {
choice: 1,
}),
},
} as UseTransOptions);
const beforeNode = () => {
return (
viewAny && (
<div className="flex justify-end items-center gap-x-1.5">
<BtnOptionnalLinkWithTooltip
link={route(`back.recipes.index`)}
content={<ArrowLeftIcon />}
tooltipContent={<p>{transBackToList}</p>}
/>
</div>
)
);
};
return (
<AuthenticatedLayout title={title} beforeNode={beforeNode()}>
{recipe && (
<ModelActions
actions={actionModels}
modelRoute="recipes"
model={recipe}
modelUpdatedAt={recipe.updated_at?.toString()}
/>
)}
<Form
model={recipe}
modelName="recipe"
modelRoute="recipes"
action={Actions.UPDATE}
method={Methods.PATCH}
/>
</AuthenticatedLayout>
);
}