125 lines
3.4 KiB
TypeScript
125 lines
3.4 KiB
TypeScript
// * Packages
|
|
import { useForm, usePage } from "@inertiajs/react";
|
|
import { BookTextIcon, EyeIcon } from "lucide-react";
|
|
// * Components shadcn
|
|
//
|
|
// * Other
|
|
import FieldsetWrapper from "@/back/Components/FieldsetWrapper";
|
|
import useTrans from "@/hooks/use-translations";
|
|
import InputError from "@/back/Components/InputError";
|
|
import SubmitButton from "@/back/Components/SubmitButton";
|
|
import useCrudSubmit from "@/back/hooks/use-crud-submit";
|
|
import { AppEnv } from "@/types/global";
|
|
import { InvoicePackageModel } from "@/back/types/project";
|
|
import SimpleString from "@/back/Components/Inputs/SimpleString";
|
|
import SimpleSwitch from "@/back/Components/Inputs/SimpleSwitch";
|
|
import SimpleNumber from "@/back/Components/Inputs/SimpleNumber";
|
|
import str from "@/hooks/use-string";
|
|
|
|
export default function Form({
|
|
model,
|
|
modelName,
|
|
modelRoute,
|
|
action,
|
|
method,
|
|
}: {
|
|
model?: InvoicePackageModel;
|
|
modelName: string;
|
|
modelRoute: string;
|
|
action: string;
|
|
method: number;
|
|
}) {
|
|
const { appEnv } = usePage().props as unknown as {
|
|
appEnv: AppEnv;
|
|
};
|
|
|
|
/** Form section */
|
|
const { post, setData, data } = useForm({
|
|
name: model?.name ? model?.name[appEnv.locale] : "",
|
|
amount: model?.amount ?? 0,
|
|
published: model?.published ?? false,
|
|
});
|
|
|
|
const submit = useCrudSubmit({
|
|
method,
|
|
modelRoute,
|
|
modelName,
|
|
action,
|
|
model,
|
|
post,
|
|
data,
|
|
modelNameTrans: useTrans(`models.classes.${modelName}`, {
|
|
choice: 1,
|
|
}),
|
|
});
|
|
|
|
return (
|
|
<form id="config-form" onSubmit={submit}>
|
|
<InputError all />
|
|
<FieldsetWrapper
|
|
title={useTrans("uwil-backend::back.form_title_global")}
|
|
icon={<BookTextIcon className="mr-1" />}
|
|
description={useTrans("uwil-backend::back.form_subtitle_global")}
|
|
className="sm:grid-cols-2 gap-4"
|
|
>
|
|
<SimpleString
|
|
name="name"
|
|
label={str(
|
|
useTrans("uwil-backend::back.form_associate_to", {
|
|
params: {
|
|
attribute: useTrans("validation.custom.name"),
|
|
},
|
|
choice: 1,
|
|
}),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
placeholder="ex: Newsletter"
|
|
value={data.name}
|
|
setData={setData}
|
|
/>
|
|
<SimpleNumber
|
|
name="amount"
|
|
label={str(
|
|
useTrans("uwil-backend::back.form_associate_to", {
|
|
params: {
|
|
attribute: useTrans("validation.custom.amount"),
|
|
},
|
|
choice: 1,
|
|
}),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
step={0.01}
|
|
limits={{
|
|
min: 1,
|
|
max: 10000,
|
|
}}
|
|
placeholder="ex: 100"
|
|
value={data.amount}
|
|
setData={setData}
|
|
/>
|
|
</FieldsetWrapper>
|
|
<FieldsetWrapper
|
|
className="gap-4"
|
|
title={useTrans("uwil-backend::back.form_title_visibility")}
|
|
icon={<EyeIcon className="mr-1" />}
|
|
description={useTrans("uwil-backend::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>
|
|
);
|
|
}
|