file upload 컴퍼넌트 사용하는 예제 소스 작성.

This commit is contained in:
truthwing
2025-03-06 17:38:05 +09:00
parent c96b2600dd
commit ff3b2f18b5
+250 -250
View File
@@ -1,87 +1,80 @@
'use client' 'use client'
import { zodResolver } from "@hookform/resolvers/zod" import { FileUpload, SelectBox } from "@common/business_components";
import { useForm } from "react-hook-form"
import { z } from "zod"
import { Button, FileSearch, Input } from "@common/components";
import {Form, FormField, FormItem, FormLabel, FormControl, FormDescription, FormMessage } from "@common/business_components/ui/form";
import { UiTable } from "@common/business_components/ui"; import { UiTable } from "@common/business_components/ui";
import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "@common/business_components/ui/form";
import { Button, FileSearch, Input } from "@common/components";
import { zodResolver } from "@hookform/resolvers/zod";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { useWrStore } from "../store"; import { useWrStore } from "../store";
import Style from "../style/PublicReuseFaciltyInsert.module.css";
import { SelectBox } from "@common/business_components";
const formSchema= z.object({ const formSchema = z.object({
username: z.string().min(2).max(50), username: z.string().min(2).max(50),
facilityName:z.string().min(2).max(50) facilityName: z.string().min(2).max(50)
}) })
export function PublicReuseFaciltyFormInsert(){ export function PublicReuseFaciltyFormInsert() {
const { upHeadList, publicReuseFacilityUper} = useWrStore((state) => state); const { upHeadList, publicReuseFacilityUper } = useWrStore((state) => state);
const total = 100; const total = 100;
const form = useForm<z.infer<typeof formSchema>>({ const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema), resolver: zodResolver(formSchema),
defaultValues: { defaultValues: {
username: "", username: "",
}, },
}) })
// 2. Define a submit handler.
function onSubmit(values: z.infer<typeof formSchema>) {
// Do something with the form values.
// ✅ This will be type-safe and validated.
console.log(values)
}
const selectboxValue=[ // 2. Define a submit handler.
{text:'1치', function onSubmit(values: z.infer<typeof formSchema>) {
val:'1'}, // Do something with the form values.
{text:'2차', // ✅ This will be type-safe and validated.
val:'2' console.log(values)
} }
]
return (
<>
<div >
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} >
{/* <div className="flex justify-between items-center mx-3"> */}
<div className="grid grid-cols-12 gap-4">
<div className="colspan-6">
<FormField
control={form.control} name='facilityName'
render={({ field }) => (
<FormItem>
<FormLabel>재이용시설 명</FormLabel>
<FormControl>
<Input
placeholder="하수처리장-1"
type=""
{...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<Button size="xs" type="submit">Submit</Button>
</div>
<div className="grid grid-cols-12 gap-4">
const selectboxValue = [
<div className="col-span-4"> {
text: '1치',
<FormField val: '1'
control={form.control} },
name="name_3799085626" {
render={({ field }) => ( text: '2차',
<FormItem> val: '2'
<FormLabel>계통도</FormLabel> }
<FormControl> ]
<FileSearch id="test1"></FileSearch> const [files, setFiles] = useState < File[] | null > (null);
{/* <FileUploader
return (
<>
<div >
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} >
{/* <div className="flex justify-between items-center mx-3"> */}
<div className="grid grid-cols-12 gap-4">
<div className="colspan-6">
</div>
<div className="colspan-6"></div>
<div className="colspan-6"></div>
<div className="colspan-6"></div>
<div className="colspan-6">
<Button size="sm">신규등록</Button>
</div>
</div>
<div className="grid grid-cols-12 gap-4">
<div className="col-span-4">
<FormField
control={form.control}
name="name_3799085626"
render={({ field }) => (
<FormItem>
<FormLabel>계통도</FormLabel>
<FormControl>
<FileSearch id="test1"></FileSearch>
{/* <FileUploader
value={files} value={files}
onValueChange={setFiles} onValueChange={setFiles}
dropzoneOptions={dropZoneConfig} dropzoneOptions={dropZoneConfig}
@@ -113,200 +106,207 @@ export function PublicReuseFaciltyFormInsert(){
))} ))}
</FileUploaderContent> </FileUploaderContent>
</FileUploader> */} </FileUploader> */}
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
)} )}
/> />
</div> </div>
<div className="col-span-1"/>
<div className="col-span-4">
<FormField
control={form.control}
name="name_0211213336"
render={({ field }) => (
<FormItem>
<FormLabel>평면도</FormLabel>
<FormControl>
<FileSearch id="test"></FileSearch>
{/* <FileUploader
value={files}
onValueChange={setFiles}
dropzoneOptions={dropZoneConfig}
className="relative bg-background rounded-lg p-2"
>
<FileInput
id="fileInput"
className="outline-dashed outline-1 outline-slate-500"
>
<div className="flex items-center justify-center flex-col p-8 w-full ">
<CloudUpload className='text-gray-500 w-10 h-10' />
<p className="mb-1 text-sm text-gray-500 dark:text-gray-400">
<span className="font-semibold">Click to upload</span>
&nbsp; or drag and drop
</p>
<p className="text-xs text-gray-500 dark:text-gray-400">
SVG, PNG, JPG or GIF
</p>
</div>
</FileInput>
<FileUploaderContent>
{files &&
files.length > 0 &&
files.map((file, i) => (
<FileUploaderItem key={i} index={i}>
<Paperclip className="h-4 w-4 stroke-current" />
<span>{file.name}</span>
</FileUploaderItem>
))}
</FileUploaderContent>
</FileUploader> */}
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
</div>
<div className="col-span-1" />
<div className="col-span-4">
<FormField
<div className="flex justify-between items-center mx-3"> control={form.control}
<h1 className="pl-3 text-xl">○ 재이용시설 운영정보</h1> name="name_0211213336"
<Button size='xs'>추가등록</Button> render={({ field }) => (
</div> <FormItem>
<div> <FormLabel>평면도</FormLabel>
<UiTable publicReuseFacility={publicReuseFacilityUper} headlist={upHeadList} pageSize={100} total={total} headName={''} children={undefined} ></UiTable> <FormControl>
</div>
<div>
<h1 className="pl-3 text-xl">○ 재이용수 공급 가능량</h1>
<div className="grid grid-cols-12 gap-4">
<div className="col-span-3">
<FormField
control={form.control}
name="name_0943143371"
render={({ field }) => (
<FormItem>
<FormLabel>시설용량(m³/일)</FormLabel>
<FormControl>
<Input
placeholder="shadcn"
type=""
{...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="col-span-3">
<FormField
control={form.control}
name="name_2007089217"
render={({ field }) => (
<FormItem>
<FormLabel>하수처리량(m³/일)</FormLabel>
<FormControl>
<Input
placeholder="shadcn"
type=""
{...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="col-span-3">
<FormField
control={form.control}
name="name_1624679275"
render={({ field }) => (
<FormItem>
<FormLabel>재이용량(m³/일)</FormLabel>
<FormControl>
<Input
placeholder="shadcn"
type=""
{...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="col-span-3">
<FormField <FormField
control={form.control} control={form.control}
name="name_1624679277" name="name_0973831747"
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel>공급여유량(m³/일)</FormLabel> <FormLabel>Select File</FormLabel>
<FormControl> <FormControl>
<Input <FileUpload files={files} setFiles={setFiles} fileTypes="PDF"></FileUpload>
placeholder="shadcn"
type=""
{...field} />
</FormControl> </FormControl>
<FormDescription>Select a file to upload.</FormDescription>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
)} )}
/> />
</div>
</div>
</div>
{/* <FileUploader
value={files}
onValueChange={setFiles}
dropzoneOptions={dropZoneConfig}
className="relative bg-background rounded-lg p-2"
>
<FileInput
id="fileInput"
className="outline-dashed outline-1 outline-slate-500"
>
<div className="flex items-center justify-center flex-col p-8 w-full ">
<CloudUpload className='text-gray-500 w-10 h-10' />
<p className="mb-1 text-sm text-gray-500 dark:text-gray-400">
<span className="font-semibold">Click to upload</span>
&nbsp; or drag and drop
</p>
<p className="text-xs text-gray-500 dark:text-gray-400">
SVG, PNG, JPG or GIF
</p>
</div>
</FileInput>
<FileUploaderContent>
{files &&
files.length > 0 &&
files.map((file, i) => (
<FileUploaderItem key={i} index={i}>
<Paperclip className="h-4 w-4 stroke-current" />
<span>{file.name}</span>
</FileUploaderItem>
))}
</FileUploaderContent>
</FileUploader> */}
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
</div>
<div className="flex justify-between items-center mx-3">
<h1 className="pl-3 text-xl">○ 재이용시설 운영정보</h1>
<Button size='xs'>추가등록</Button>
</div>
<div>
<UiTable publicReuseFacility={publicReuseFacilityUper} headlist={upHeadList} pageSize={100} total={total} headName={''} children={undefined} ></UiTable>
</div>
<div>
<h1 className="pl-3 text-xl">○ 재이용수 공급 가능량</h1>
<div className="grid grid-cols-12 gap-4">
<div className="col-span-3">
<FormField
control={form.control}
name="name_0943143371"
render={({ field }) => (
<FormItem>
<FormLabel>시설용량(m³/일)</FormLabel>
<FormControl>
<Input
placeholder="shadcn"
type=""
{...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="col-span-3">
<FormField
control={form.control}
name="name_2007089217"
render={({ field }) => (
<FormItem>
<FormLabel>하수처리량(m³/일)</FormLabel>
<FormControl>
<Input
placeholder="shadcn"
type=""
{...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="col-span-3">
<FormField
control={form.control}
name="name_1624679275"
render={({ field }) => (
<FormItem>
<FormLabel>재이용량(m³/일)</FormLabel>
<FormControl>
<Input
placeholder="shadcn"
type=""
{...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="col-span-3">
<FormField
control={form.control}
name="name_1624679277"
render={({ field }) => (
<FormItem>
<FormLabel>공급여유량(m³/일)</FormLabel>
<FormControl>
<Input
placeholder="shadcn"
type=""
{...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
</div>
</div>
</form> </form>
</Form> </Form>
</div> </div>
{/* 차수별 등록 현호아 폼 */} {/* 차수별 등록 현호아 폼 */}
<div className="justify-between"> <div className="justify-between">
<Form {...form}> <Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8 mx-auto py-10 w-100" > <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8 mx-auto py-10 w-100" >
<div className="flex justify-between"> <div className="flex justify-between">
<div className=""> <div className="">
<h1 className="pl-3 text-xl">○ 하수처리수 재이용 시설 현황</h1> <h1 className="pl-3 text-xl">○ 하수처리수 재이용 시설 현황</h1>
</div> </div>
<div className=" flex items-center"> <div className=" flex items-center">
<FormField <FormField
control={form.control} control={form.control}
name="name_1486273033" name="name_1486273033"
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel>등록 차수</FormLabel> <FormLabel>등록 차수</FormLabel>
<SelectBox selectArray={selectboxValue} ></SelectBox> <SelectBox selectArray={selectboxValue} ></SelectBox>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
)} )}
/> />
<Button className="mx-5 mt-6" size='xs' type="submit">신규등록</Button> <Button className="mx-5 mt-6" size='xs' type="submit">신규등록</Button>
</div> </div>
</div>
</form>
</Form>
</div> </div>
</form>
</> </Form>
); </div>
</>
);
} }