65 lines
2.2 KiB
TypeScript
65 lines
2.2 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 Form from "@/back/Pages/Users/Form";
|
|
import useTrans from "@/hooks/use-translations";
|
|
import { Actions, Methods } from "@/lib/enums";
|
|
import { Views } from "@/lib/utils";
|
|
import { AuthProp, SingleResource, UserModel } from "@/back/types/global";
|
|
|
|
export default function Edit({ data }: { data: SingleResource }) {
|
|
const { viewAny } = (usePage().props.auth as AuthProp).policies.users;
|
|
const userModel = data.data as UserModel;
|
|
const actionModels = [
|
|
Views.VISUALIZATION,
|
|
Views.DUPLICATION,
|
|
Views.DELETION,
|
|
];
|
|
|
|
// Translations.
|
|
const transBackToList = useTrans("back.crud_back_to_list");
|
|
|
|
const beforeNode = () => {
|
|
return (
|
|
viewAny && (
|
|
<div className="flex justify-end items-center gap-x-1.5">
|
|
<BtnOptionnalLinkWithTooltip
|
|
link={route("back.users.index")}
|
|
content={<ArrowLeftIcon />}
|
|
tooltipContent={<p>{transBackToList}</p>}
|
|
/>
|
|
</div>
|
|
)
|
|
);
|
|
};
|
|
|
|
return (
|
|
<AuthenticatedLayout
|
|
title={useTrans("crud.helpers.edition_model", {
|
|
params: {
|
|
model: useTrans("models.classes.user", { choice: 1 }),
|
|
},
|
|
})}
|
|
beforeNode={beforeNode()}
|
|
>
|
|
<ModelActions
|
|
actions={actionModels}
|
|
modelRoute="users"
|
|
model={userModel}
|
|
modelUpdatedAt={userModel.updated_at.toString()}
|
|
/>
|
|
<Form
|
|
model={userModel}
|
|
modelName="user"
|
|
modelRoute="users"
|
|
action={Actions.UPDATE}
|
|
method={Methods.PATCH}
|
|
/>
|
|
</AuthenticatedLayout>
|
|
);
|
|
}
|