// * Packages import { useForm, usePage } from "@inertiajs/react"; import { BookTextIcon, EyeIcon } from "lucide-react"; // * Other import SimpleString from "@/back/Components/Inputs/SimpleString"; import SimpleSwitch from "@/back/Components/Inputs/SimpleSwitch"; import EnumSelect from "@/back/Components/Inputs/EnumSelect"; import FieldsetWrapper from "@/back/Components/FieldsetWrapper"; import useTrans from "@/hooks/use-translations"; import str from "@/hooks/use-string"; import InputError from "@/back/Components/InputError"; import { AuthProp, UserModel } from "@/back/types/global"; import SubmitButton from "@/back/Components/SubmitButton"; import useCrudSubmit from "@/back/hooks/use-crud-submit"; export default function Form({ model, modelName, modelRoute, action, method, }: { model?: UserModel; modelName: string; modelRoute: string; action: string; method: number; }) { const userModel = (usePage().props.auth as AuthProp).user; const enumUserRole = usePage().props.enumUserRole as UserModel["role"][]; const isConceptor = enumUserRole.find((role) => role.name === "conceptor"); const filterRoles = (value: number) => { return ( Object.entries(enumUserRole) // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars .filter(([_, role]) => role.value >= value) .reduce((acc, [key, val]) => ({ ...acc, [key]: val }), {}) ); }; /** Form section */ const { post, setData, data } = useForm({ first_name: model?.first_name, last_name: model?.last_name, email: model?.email, published: model?.published ?? false, published_at: model?.published_at, role: model && model.role ? model.role.value : undefined, }); const submit = useCrudSubmit({ method, modelRoute, modelName, action, model, post, data, modelNameTrans: useTrans(`uwil-backend::models.classes.${modelName}`, { choice: 1, }), }); // * Translations. const transAssociateToRole = str( useTrans("uwil-backend::back.form_associate_to", { params: { attribute: useTrans("uwil-backend::validation.attributes.role"), }, choice: 1, }), ) .ucFirst() .value(); const transFormTitleVisibility = useTrans( "uwil-backend::back.form_title_visibility", ); const transFormSubtitleVisibility = useTrans( "uwil-backend::back.form_subtitle_visibility", ); return (
); }