131 lines
3.5 KiB
TypeScript
131 lines
3.5 KiB
TypeScript
// * Packages
|
|
import { useForm, usePage } from "@inertiajs/react";
|
|
import { BookTextIcon } 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 { NoticeModel } from "@/back/types/project";
|
|
import SimpleString from "@/back/Components/Inputs/SimpleString";
|
|
import str from "@/hooks/use-string";
|
|
import { AppEnv, LaravelEnum } from "@/types/global";
|
|
import SimpleWysiwyg from "@/back/Components/Inputs/Wysiwyg/SimpleWysiwyg";
|
|
import EnumSelect from "@/back/Components/Inputs/EnumSelect";
|
|
|
|
export default function Form({
|
|
model,
|
|
modelName,
|
|
modelRoute,
|
|
action,
|
|
method,
|
|
}: {
|
|
model?: NoticeModel;
|
|
modelName: string;
|
|
modelRoute: string;
|
|
action: string;
|
|
method: number;
|
|
}) {
|
|
const { appEnv, noticeTypeEnum } = usePage().props as unknown as {
|
|
appEnv: AppEnv;
|
|
noticeTypeEnum: LaravelEnum;
|
|
};
|
|
|
|
/** Form section */
|
|
const { post, setData, data } = useForm({
|
|
title: model?.title ? model?.title[appEnv.locale] : "",
|
|
message: model?.message ? model?.message[appEnv.locale] : "",
|
|
type: model?.type ?? noticeTypeEnum.primary,
|
|
});
|
|
|
|
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="title"
|
|
label={str(
|
|
useTrans("uwil-backend::back.form_associate_to", {
|
|
params: {
|
|
attribute: useTrans(
|
|
"validation.custom.title",
|
|
),
|
|
},
|
|
choice: 1,
|
|
}),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
placeholder="ex: John Doe"
|
|
value={data.title}
|
|
setData={setData}
|
|
/>
|
|
<EnumSelect
|
|
name="type"
|
|
options={noticeTypeEnum}
|
|
label={str(
|
|
useTrans("uwil-backend::back.form_associate_to", {
|
|
params: {
|
|
attribute: useTrans(
|
|
"validation.custom.type",
|
|
),
|
|
},
|
|
choice: 1,
|
|
}),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
placeholder={`ex: ${noticeTypeEnum.primary.label}`}
|
|
selected={data.type}
|
|
setData={setData}
|
|
/>
|
|
<SimpleWysiwyg
|
|
name="message"
|
|
tableName="notices"
|
|
label={str(
|
|
useTrans("uwil-backend::back.form_associate_to", {
|
|
params: {
|
|
attribute: useTrans(
|
|
"validation.custom.message",
|
|
),
|
|
},
|
|
choice: 1,
|
|
}),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
value={data.message}
|
|
setData={setData}
|
|
/>
|
|
</FieldsetWrapper>
|
|
<div className="text-center">
|
|
<SubmitButton
|
|
modelTrans={useTrans(`models.classes.${modelName}`, {
|
|
choice: 1,
|
|
})}
|
|
/>
|
|
</div>
|
|
</form>
|
|
);
|
|
}
|