91 lines
3.0 KiB
TypeScript
91 lines
3.0 KiB
TypeScript
import { useWrStore } from "@/app/store";
|
|
import { rainSttnHeadListType } from "@/app/store/ruseFcltMng/fcltSttn/rainSttn/headList";
|
|
import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "@common/business_components/ui";
|
|
import { Button, Checkbox } from "@common/components/ui";
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
import { useEffect, useState } from "react";
|
|
import { useForm } from "react-hook-form";
|
|
import { z } from "zod";
|
|
|
|
export default function HeadChModal({type }:{type: string }) {
|
|
const { rainSttn ,rainChSttnHead} = useWrStore((state) => state);
|
|
|
|
|
|
const { rainSttHeadList, rainSttNodeList } =rainSttn;
|
|
let items = rainSttHeadList.map(item => ({id:item.id, title:item.title, val:item.visible }));
|
|
|
|
|
|
|
|
// const FormSchema =
|
|
// z.object({
|
|
// id: z.string().refine((value) => value.some((item) => item), {
|
|
// message: "최소한 하나를 선택해주시길 바랍니다.",
|
|
// }),
|
|
// visible: z.boolean()
|
|
// })
|
|
|
|
|
|
const form = useForm<z.infer<typeof rainSttnHeadListType>>({
|
|
resolver: zodResolver(rainSttnHeadListType),
|
|
defaultValues: [],
|
|
})
|
|
|
|
|
|
useEffect(() =>{
|
|
form.reset(rainSttHeadList)
|
|
|
|
|
|
},[rainSttHeadList])
|
|
|
|
const onSubmit = (headList : z.infer<typeof rainSttnHeadListType> ) =>{
|
|
rainChSttnHead(headList)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div>
|
|
<Form {...form}>
|
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
|
|
|
|
<div className="mb-4">
|
|
<h3>조회항목 설정</h3>
|
|
</div>
|
|
{items.map((item,index) => (
|
|
<FormField
|
|
key={`${index}.id`}
|
|
control={form.control}
|
|
name={`${index}.visible`}
|
|
render={({ field }) =>
|
|
{
|
|
return (
|
|
<FormItem
|
|
key={`${index}.id`+'item'}
|
|
className="flex flex-row items-start space-x-3 space-y-0"
|
|
>
|
|
<FormControl>
|
|
<Checkbox
|
|
checked={field.value}
|
|
onCheckedChange={(checked) =>
|
|
{
|
|
field.onChange(checked);
|
|
return;
|
|
}
|
|
}
|
|
/>
|
|
</FormControl>
|
|
<FormLabel className="text-xl">
|
|
{item.title}
|
|
</FormLabel>
|
|
</FormItem>
|
|
);
|
|
}}
|
|
/>
|
|
))}
|
|
<Button type="submit">항목 표출 변경</Button>
|
|
</form>
|
|
</Form>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|