85 lines
2.3 KiB
TypeScript
85 lines
2.3 KiB
TypeScript
// * Packages
|
|
import { usePage } from "@inertiajs/react";
|
|
import { route } from "ziggy-js";
|
|
import { ArrowLeftIcon } from "lucide-react";
|
|
// * Other
|
|
import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout";
|
|
import ModelActions from "@/back/Components/ModelActions";
|
|
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
|
|
import BtnResetPassword from "@/back/Components/BtnResetPassword";
|
|
import Form from "@/back/Pages/Users/Form";
|
|
import useTrans from "@/hooks/use-translations";
|
|
import { Actions, Methods } from "@/back/lib/enums";
|
|
import Views from "@/back/lib/actions";
|
|
import {
|
|
AuthProp,
|
|
SingleResource,
|
|
UserModel,
|
|
ConfigBackend,
|
|
} from "@/back/types/global";
|
|
|
|
export default function Edit({
|
|
data,
|
|
modelName,
|
|
}: {
|
|
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;
|
|
const actionModels = [
|
|
Views.VISUALIZATION,
|
|
Views.DUPLICATION,
|
|
Views.ARCHIVATION,
|
|
];
|
|
|
|
// Translations.
|
|
const transBackToList = useTrans("uwil-backend::back.crud_back_to_list");
|
|
const transTitle = useTrans("uwil-backend::crud.helpers.edition_model", {
|
|
params: {
|
|
model: useTrans(`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>
|
|
)
|
|
);
|
|
};
|
|
|
|
const afterNode = () => <BtnResetPassword model={model} />;
|
|
|
|
return (
|
|
<AuthenticatedLayout
|
|
title={transTitle}
|
|
beforeNode={beforeNode()}
|
|
afterNode={afterNode()}
|
|
>
|
|
<ModelActions
|
|
actions={actionModels}
|
|
modelRoute={modelName}
|
|
model={model}
|
|
modelUpdatedAt={model.updated_at?.toString()}
|
|
/>
|
|
<Form
|
|
model={model}
|
|
modelName={modelName}
|
|
modelRoute={modelName}
|
|
action={Actions.UPDATE}
|
|
method={Methods.PATCH}
|
|
/>
|
|
</AuthenticatedLayout>
|
|
);
|
|
}
|