114 lines
3.7 KiB
TypeScript
114 lines
3.7 KiB
TypeScript
// * Packages
|
|
import { useForm, usePage } from "@inertiajs/react";
|
|
import { BookTextIcon, EyeIcon } from "lucide-react";
|
|
// * Other
|
|
import SimpleString from "@/back/Components/Inputs/SimpleString";
|
|
import FieldsetWrapper from "@/back/Components/FieldsetWrapper";
|
|
import SimpleSwitch from "@/back/Components/Inputs/SimpleSwitch";
|
|
import SimpleColorPicker from "@/back/Components/Inputs/SimpleColorPicker";
|
|
import SubmitButton from "@/back/Components/SubmitButton";
|
|
import useTrans from "@/hooks/use-translations";
|
|
import str from "@/hooks/use-string";
|
|
import InputError from "@/back/Components/InputError";
|
|
import { AppEnv } from "@/back/types/global";
|
|
import { CompanyActivityModel } from "@/back/types/others";
|
|
import useCrudSubmit from "@/hooks/use-crud-submit";
|
|
|
|
export default function Form({
|
|
model,
|
|
modelName,
|
|
modelRoute,
|
|
action,
|
|
method,
|
|
}: {
|
|
model?: CompanyActivityModel;
|
|
modelName: string;
|
|
modelRoute: string;
|
|
action: string;
|
|
method: number;
|
|
}) {
|
|
const { locale } = usePage().props.appEnv as AppEnv;
|
|
|
|
/** Form section */
|
|
const { post, setData, data } = useForm({
|
|
name: model?.name ? model?.name[locale] : "",
|
|
color: model?.color ?? null,
|
|
published: model?.published,
|
|
});
|
|
const submit = useCrudSubmit({
|
|
method,
|
|
modelRoute,
|
|
modelName,
|
|
action,
|
|
model,
|
|
post,
|
|
data,
|
|
});
|
|
|
|
return (
|
|
<form onSubmit={submit}>
|
|
<InputError all />
|
|
<FieldsetWrapper
|
|
title={useTrans("back.form_title_global")}
|
|
icon={<BookTextIcon className="mr-1" />}
|
|
description={useTrans("back.form_subtitle_global")}
|
|
className="sm:grid-cols-2 gap-4"
|
|
>
|
|
<SimpleString
|
|
name="name"
|
|
label={str(
|
|
useTrans("back.form_associate_to", {
|
|
params: {
|
|
attribute: useTrans(
|
|
"validation.attributes.name",
|
|
),
|
|
},
|
|
choice: 1,
|
|
}),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
placeholder="ex: John Doe"
|
|
value={data.name}
|
|
setData={setData}
|
|
/>
|
|
<SimpleColorPicker
|
|
name="color"
|
|
label={str(
|
|
useTrans("back.form_associate_to", {
|
|
params: {
|
|
attribute: useTrans("validation.custom.color"),
|
|
},
|
|
choice: 1,
|
|
}),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
setData={setData}
|
|
value={data.color}
|
|
required
|
|
/>
|
|
</FieldsetWrapper>
|
|
<FieldsetWrapper
|
|
className="gap-4"
|
|
title={useTrans("back.form_title_visibility")}
|
|
icon={<EyeIcon className="mr-1" />}
|
|
description={useTrans("back.form_subtitle_visibility")}
|
|
inline
|
|
>
|
|
<SimpleSwitch
|
|
name="published"
|
|
checked={data.published}
|
|
setData={setData}
|
|
/>
|
|
</FieldsetWrapper>
|
|
<div className="text-center">
|
|
<SubmitButton
|
|
modelTrans={useTrans(`models.classes.${modelName}`, {
|
|
choice: 1,
|
|
})}
|
|
/>
|
|
</div>
|
|
</form>
|
|
);
|
|
}
|