add: domain in access and page
This commit is contained in:
@@ -3,14 +3,19 @@ import Button from "../../components/Button/Button";
|
||||
import { Grid } from "../../components/Grid/Grid";
|
||||
import Textfield from "../../components/Textfeild/Textfeild";
|
||||
import { useForm, Controller } from "react-hook-form";
|
||||
import { zValidateEnglishString } from "../../data/getFormTypeErrors";
|
||||
import {
|
||||
zValidateEnglishString,
|
||||
zValidateNumber,
|
||||
} from "../../data/getFormTypeErrors";
|
||||
import { z } from "zod";
|
||||
import { useApiMutation } from "../../utils/useApiRequest";
|
||||
import { useToast } from "../../hooks/useToast";
|
||||
import { useModalStore } from "../../context/zustand-store/appStore";
|
||||
import { FormApiBasedAutoComplete } from "../../components/FormItems/FormApiBasedAutoComplete";
|
||||
|
||||
const schema = z.object({
|
||||
page: zValidateEnglishString("نام صفحه"),
|
||||
domain: zValidateNumber("حوزه"),
|
||||
});
|
||||
|
||||
type AddPageProps = {
|
||||
@@ -27,11 +32,13 @@ export const AddPage = ({ getData, item }: AddPageProps) => {
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = useForm<FormValues>({
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: {
|
||||
page: item?.name || "",
|
||||
domain: item?.domain?.id,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -45,6 +52,7 @@ export const AddPage = ({ getData, item }: AddPageProps) => {
|
||||
const payload = {
|
||||
name: data.page,
|
||||
code: data.page + ".view",
|
||||
domain: data.domain,
|
||||
};
|
||||
|
||||
if (item) {
|
||||
@@ -83,6 +91,25 @@ export const AddPage = ({ getData, item }: AddPageProps) => {
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
name="domain"
|
||||
control={control}
|
||||
render={() => (
|
||||
<FormApiBasedAutoComplete
|
||||
selectField
|
||||
defaultKey={item?.domain?.id}
|
||||
title="انتخاب حوزه"
|
||||
api="/core/domain/"
|
||||
keyField="id"
|
||||
valueField="fa_name"
|
||||
error={!!errors.domain}
|
||||
errorMessage={errors.domain?.message}
|
||||
onChange={(value) => {
|
||||
setValue("domain", value);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<Button type="submit">ثبت</Button>
|
||||
</Grid>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user