summaryrefslogtreecommitdiff
path: root/lib/rfq-last/table/create-general-rfq-dialog.tsx
blob: f751578725685595db7bbf78567eaa146fe89cc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
"use client"

import * as React from "react"
import { useForm, useFieldArray } from "react-hook-form"
import { zodResolver } from "@hookform/resolvers/zod"
import { z } from "zod"
import { format } from "date-fns"
import { CalendarIcon, Plus, Loader2, Trash2, PlusCircle, Check, ChevronsUpDown } from "lucide-react"
import { useRouter } from "next/navigation"
import { useSession } from "next-auth/react"

import { Button } from "@/components/ui/button"
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import {
  Form,
  FormControl,
  FormField,
  FormItem,
  FormLabel,
  FormMessage,
  FormDescription,
} from "@/components/ui/form"
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select"
import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from "@/components/ui/popover"
import {
  Command,
  CommandInput,
  CommandList,
  CommandGroup,
  CommandItem,
  CommandEmpty,
} from "@/components/ui/command"
import { Calendar } from "@/components/ui/calendar"
import { Badge } from "@/components/ui/badge"
import { cn } from "@/lib/utils"
import { toast } from "sonner"
import { ScrollArea } from "@/components/ui/scroll-area"
import { Separator } from "@/components/ui/separator"
import { createGeneralRfqAction, getPUsersForFilter, previewGeneralRfqCode } from "../service"

// 아이템 스키마
const itemSchema = z.object({
  itemCode: z.string().optional(),
  itemName: z.string().min(1, "자재명을 입력해주세요"),
  quantity: z.number().min(1, "수량은 1 이상이어야 합니다"),
  uom: z.string().min(1, "단위를 입력해주세요"),
  remark: z.string().optional(),
})

// 일반견적 생성 폼 스키마
const createGeneralRfqSchema = z.object({
  rfqType: z.string().min(1, "견적 종류를 선택해주세요"),
  rfqTitle: z.string().min(1, "견적명을 입력해주세요"),
  dueDate: z.date({
    required_error: "제출마감일을 선택해주세요",
  }),
  picUserId: z.number().min(1, "견적담당자를 선택해주세요"),
  remark: z.string().optional(),
  items: z.array(itemSchema).min(1, "최소 하나의 아이템을 추가해주세요"),
})

type CreateGeneralRfqFormValues = z.infer<typeof createGeneralRfqSchema>

interface CreateGeneralRfqDialogProps {
  onSuccess?: () => void;
}

export function CreateGeneralRfqDialog({ onSuccess }: CreateGeneralRfqDialogProps) {
  const [open, setOpen] = React.useState(false)
  const [isLoading, setIsLoading] = React.useState(false)
  const [users, setUsers] = React.useState<Array<{ id: number; name: string }>>([])
  const [isLoadingUsers, setIsLoadingUsers] = React.useState(false)
  const [userPopoverOpen, setUserPopoverOpen] = React.useState(false)
  const [userSearchTerm, setUserSearchTerm] = React.useState("")
  const [previewCode, setPreviewCode] = React.useState("")
  const [isLoadingPreview, setIsLoadingPreview] = React.useState(false)
  const userOptionIdsRef = React.useRef<Record<number, string>>({})
  const router = useRouter()
  const { data: session } = useSession()

  // 고유 ID 생성
  const buttonId = React.useMemo(() => `user-button-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, [])
  const popoverContentId = React.useMemo(() => `user-popover-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, [])
  const commandId = React.useMemo(() => `user-command-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, [])

  const userId = React.useMemo(() => {
    return session?.user?.id ? Number(session.user.id) : null;
  }, [session]);

  const form = useForm<CreateGeneralRfqFormValues>({
    resolver: zodResolver(createGeneralRfqSchema),
    defaultValues: {
      rfqType: "",
      rfqTitle: "",
      dueDate: undefined,
      picUserId: userId || undefined,
      remark: "",
      items: [
        {
          itemCode: "",
          itemName: "",
          quantity: 1,
          uom: "",
          remark: "",
        },
      ],
    },
  })

  const { fields, append, remove } = useFieldArray({
    control: form.control,
    name: "items",
  })

  // 견적 종류 변경
  const handleRfqTypeChange = (value: string) => {
    form.setValue("rfqType", value)
  }

  // RFQ 코드 미리보기 생성
  const generatePreviewCode = React.useCallback(async () => {
    const picUserId = form.watch("picUserId")
    
    if (!picUserId) {
      setPreviewCode("")
      return
    }

    setIsLoadingPreview(true)
    try {
      const code = await previewGeneralRfqCode(picUserId)
      setPreviewCode(code)
    } catch (error) {
      console.error("코드 미리보기 오류:", error)
      setPreviewCode("")
    } finally {
      setIsLoadingPreview(false)
    }
  }, [form])

  // 필드 변경 감지해서 미리보기 업데이트
  React.useEffect(() => {
    const subscription = form.watch((value, { name }) => {
      if (name === "picUserId") {
        generatePreviewCode()
      }
    })
    return () => subscription.unsubscribe()
  }, [form, generatePreviewCode])

  // 사용자 목록 로드
  React.useEffect(() => {
    const loadUsers = async () => {
      setIsLoadingUsers(true)
      try {
        const userList = await getPUsersForFilter()
        setUsers(userList)
      } catch (error) {
        console.log("사용자 목록 로드 오류:", error)
        toast.error("사용자 목록을 불러오는데 실패했습니다")
      } finally {
        setIsLoadingUsers(false)
      }
    }
    loadUsers()
  }, [])

  // 세션 사용자 ID로 기본값 설정
  React.useEffect(() => {
    if (userId && !form.getValues("picUserId")) {
      form.setValue("picUserId", userId)
    }
  }, [userId, form])

  // 사용자 검색 필터링
  const userOptions = React.useMemo(() => {
    return users.filter((user) =>
      user.name.toLowerCase().includes(userSearchTerm.toLowerCase())
    )
  }, [users, userSearchTerm])

  // 선택된 사용자 찾기
  const selectedUser = React.useMemo(() => {
    const picUserId = form.watch("picUserId")
    return users.find(user => user.id === picUserId)
  }, [users, form.watch("picUserId")])

  // 사용자 선택 핸들러
  const handleSelectUser = (user: { id: number; name: string }) => {
    form.setValue("picUserId", user.id)
    setUserPopoverOpen(false)
    setUserSearchTerm("")
  }

  // 다이얼로그 열림/닫힘 처리 및 폼 리셋
  const handleOpenChange = (newOpen: boolean) => {
    setOpen(newOpen)
    
    // 다이얼로그가 닫힐 때 폼과 상태 초기화
    if (!newOpen) {
      form.reset({
        rfqType: "",
        rfqTitle: "",
        dueDate: undefined,
        picUserId: userId || undefined,
        remark: "",
        items: [
          {
            itemCode: "",
            itemName: "",
            quantity: 1,
            uom: "",
            remark: "",
          },
        ],
      })
      setUserSearchTerm("")
      setUserPopoverOpen(false)
      setPreviewCode("")
      setIsLoadingPreview(false)
    }
  }

  const handleCancel = () => {
    form.reset()
    setOpen(false)
  }

  const onSubmit = async (data: CreateGeneralRfqFormValues) => {
    if (!userId) {
      toast.error("로그인이 필요합니다")
      return
    }

    setIsLoading(true)
    
    try {
      // 서버 액션 호출
      const result = await createGeneralRfqAction({
        rfqType: data.rfqType,
        rfqTitle: data.rfqTitle,
        dueDate: data.dueDate,
        picUserId: data.picUserId,
        remark: data.remark || "",
        items: data.items,
        createdBy: userId,
        updatedBy: userId,
      })

      if (result.success) {
        toast.success(result.message, {
          description: `RFQ 코드: ${result.data?.rfqCode}`,
        })

        // 다이얼로그 닫기
        setOpen(false)
        
        // 성공 콜백 실행
        if (onSuccess) {
          onSuccess()
        }
        
        // RFQ 상세 페이지로 이동 (선택사항)
        // router.push(`/rfq/${result.data?.rfqCode}`)
        
      } else {
        toast.error(result.error || "일반견적 생성에 실패했습니다")
      }
      
    } catch (error) {
      console.error('일반견적 생성 오류:', error)
      toast.error("일반견적 생성에 실패했습니다", {
        description: "알 수 없는 오류가 발생했습니다",
      })
    } finally {
      setIsLoading(false)
    }
  }

  // 아이템 추가
  const handleAddItem = () => {
    append({
      itemCode: "",
      itemName: "",
      quantity: 1,
      uom: "",
      remark: "",
    })
  }


  return (
    <Dialog open={open} onOpenChange={handleOpenChange}>
      <DialogTrigger asChild>
        <Button variant="samsung" size="sm" className="h-8 px-2 lg:px-3">
          <Plus className="mr-2 h-4 w-4" />
          일반견적 생성
        </Button>
      </DialogTrigger>
      <DialogContent className="max-w-4xl h-[90vh] flex flex-col">
        {/* 고정된 헤더 */}
        <DialogHeader className="flex-shrink-0">
          <DialogTitle>일반견적 생성</DialogTitle>
          <DialogDescription>
            새로운 일반견적을 생성합니다. 필수 정보를 입력해주세요.
          </DialogDescription>
        </DialogHeader>

        {/* 스크롤 가능한 컨텐츠 영역 */}
        <ScrollArea className="flex-1 px-1">
          <Form {...form}>
            <form id="createGeneralRfqForm" onSubmit={form.handleSubmit(onSubmit)} className="space-y-6 py-2">
              
              {/* 기본 정보 섹션 */}
              <div className="space-y-4">
                <h3 className="text-lg font-semibold">기본 정보</h3>
                
                <div className="grid grid-cols-2 gap-4">
                  {/* 견적 종류 */}
                  <div className="space-y-2">
                    <FormField
                      control={form.control}
                      name="rfqType"
                      render={({ field }) => (
                        <FormItem className="flex flex-col">
                          <FormLabel>
                            견적 종류 <span className="text-red-500">*</span>
                          </FormLabel>
                          <Select onValueChange={handleRfqTypeChange} value={field.value}>
                            <FormControl>
                              <SelectTrigger>
                                <SelectValue placeholder="견적 종류 선택" />
                              </SelectTrigger>
                            </FormControl>
                            <SelectContent>
                              <SelectItem value="단가계약">단가계약</SelectItem>
                              <SelectItem value="매각계약">매각계약</SelectItem>
                              <SelectItem value="일반계약">일반계약</SelectItem>
                            </SelectContent>
                          </Select>
                          <FormMessage />
                        </FormItem>
                      )}
                    />
                  </div>

                  {/* 제출마감일 */}
                  <FormField
                    control={form.control}
                    name="dueDate"
                    render={({ field }) => (
                      <FormItem className="flex flex-col">
                        <FormLabel>
                          제출마감일 <span className="text-red-500">*</span>
                        </FormLabel>
                        <Popover>
                          <PopoverTrigger asChild>
                            <FormControl>
                              <Button
                                variant="outline"
                                className={cn(
                                  "w-full pl-3 text-left font-normal",
                                  !field.value && "text-muted-foreground"
                                )}
                              >
                                {field.value ? (
                                  format(field.value, "yyyy-MM-dd")
                                ) : (
                                  <span>제출마감일을 선택하세요 (미선택 시 생성일 +7일)</span>
                                )}
                                <CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
                              </Button>
                            </FormControl>
                          </PopoverTrigger>
                          <PopoverContent className="w-auto p-0" align="start">
                            <Calendar
                              mode="single"
                              selected={field.value}
                              onSelect={field.onChange}
                              disabled={(date) =>
                                date < new Date() || date < new Date("1900-01-01")
                              }
                              initialFocus
                            />
                          </PopoverContent>
                        </Popover>
                        <FormMessage />
                      </FormItem>
                    )}
                  />
                </div>

                {/* 견적명 */}
                <FormField
                  control={form.control}
                  name="rfqTitle"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>
                        견적명 <span className="text-red-500">*</span>
                      </FormLabel>
                      <FormControl>
                        <Input
                          placeholder="예: 2025년 1분기 사무용품 구매 견적"
                          {...field}
                        />
                      </FormControl>
                      <FormDescription>
                        견적의 목적이나 내용을 간단명료하게 입력해주세요
                      </FormDescription>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* 구매 담당자 - 검색 가능한 셀렉터로 변경 */}
                <FormField
                  control={form.control}
                  name="picUserId"
                  render={({ field }) => (
                    <FormItem className="flex flex-col">
                      <FormLabel>
                        견적담당자 <span className="text-red-500">*</span>
                      </FormLabel>
                      <FormControl>
                        <Popover open={userPopoverOpen} onOpenChange={setUserPopoverOpen}>
                          <PopoverTrigger asChild>
                            <Button
                              key={buttonId}
                              type="button"
                              variant="outline"
                              className="w-full justify-between relative h-9"
                              disabled={isLoadingUsers}
                            >
                              {isLoadingUsers ? (
                                <>
                                  <span>담당자 로딩 중...</span>
                                  <Loader2 className="ml-2 h-4 w-4 animate-spin" />
                                </>
                              ) : (
                                <>
                                  <span className="truncate mr-1 flex-grow text-left">
                                    {selectedUser ? selectedUser.name : "견적담당자를 선택하세요"}
                                  </span>
                                  <ChevronsUpDown className="h-4 w-4 opacity-50 flex-shrink-0" />
                                </>
                              )}
                            </Button>
                          </PopoverTrigger>
                          <PopoverContent key={popoverContentId} className="w-[300px] p-0">
                            <Command key={commandId}>
                              <CommandInput
                                key={`${commandId}-input`}
                                placeholder="담당자 검색..."
                                value={userSearchTerm}
                                onValueChange={setUserSearchTerm}
                              />
                              <CommandList 
                                key={`${commandId}-list`} 
                                className="max-h-[300px]" 
                                onWheel={(e) => {
                                  e.stopPropagation(); // 이벤트 전파 차단
                                  const target = e.currentTarget;
                                  target.scrollTop += e.deltaY; // 직접 스크롤 처리
                                }}
                              >
                                <CommandEmpty key={`${commandId}-empty`}>담당자를 찾을 수 없습니다.</CommandEmpty>
                                <CommandGroup key={`${commandId}-group`}>
                                  {userOptions.map((user, userIndex) => {
                                    if (!userOptionIdsRef.current[user.id]) {
                                      userOptionIdsRef.current[user.id] =
                                        `user-${user.id}-${Date.now()}-${Math.random()
                                          .toString(36)
                                          .slice(2, 9)}`
                                    }
                                    const optionId = userOptionIdsRef.current[user.id]

                                    return (
                                      <CommandItem
                                        key={`${optionId}-${userIndex}`}
                                        onSelect={() => handleSelectUser(user)}
                                        value={user.name}
                                        className="truncate"
                                        title={user.name}
                                      >
                                        <span className="truncate">{user.name}</span>
                                        <Check
                                          key={`${optionId}-check`}
                                          className={cn(
                                            "ml-auto h-4 w-4 flex-shrink-0",
                                            selectedUser?.id === user.id ? "opacity-100" : "opacity-0"
                                          )}
                                        />
                                      </CommandItem>
                                    )
                                  })}
                                </CommandGroup>
                              </CommandList>
                            </Command>
                          </PopoverContent>
                        </Popover>
                      </FormControl>
                      {/* RFQ 코드 미리보기 */}
                      {previewCode && (
                        <div className="flex items-center gap-2 mt-2">
                          <Badge variant="secondary" className="font-mono text-sm">
                            예상 RFQ 코드: {previewCode}
                          </Badge>
                          {isLoadingPreview && (
                            <Loader2 className="h-3 w-3 animate-spin" />
                          )}
                        </div>
                      )}
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* 비고 */}
                <FormField
                  control={form.control}
                  name="remark"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>비고</FormLabel>
                      <FormControl>
                        <Textarea
                          placeholder="추가 비고사항을 입력하세요"
                          className="resize-none"
                          rows={3}
                          {...field}
                        />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />
              </div>

              <Separator />

              {/* 아이템 정보 섹션 - 컴팩트한 UI */}
              <div className="space-y-4">
                <div className="flex items-center justify-between">
                  <h3 className="text-lg font-semibold">아이템 정보</h3>
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={handleAddItem}
                  >
                    <PlusCircle className="mr-2 h-4 w-4" />
                    아이템 추가
                  </Button>
                </div>

                <div className="space-y-3">
                  {fields.map((field, index) => (
                    <div key={field.id} className="border rounded-lg p-3 bg-gray-50/50">
                      <div className="flex items-center justify-between mb-3">
                        <span className="text-sm font-medium text-gray-700">
                          아이템 #{index + 1}
                        </span>
                        {fields.length > 1 && (
                          <Button
                            type="button"
                            variant="ghost"
                            size="sm"
                            onClick={() => remove(index)}
                            className="h-6 w-6 p-0 text-destructive hover:text-destructive"
                          >
                            <Trash2 className="h-3 w-3" />
                          </Button>
                        )}
                      </div>
                      
                      <div className="grid grid-cols-4 gap-3">
                        {/* 자재코드 */}
                        <FormField
                          control={form.control}
                          name={`items.${index}.itemCode`}
                          render={({ field }) => (
                            <FormItem>
                              <FormLabel className="text-xs">
                                자재코드 
                              </FormLabel>
                              <FormControl>
                                <Input
                                  placeholder="MAT-001"
                                  className="h-8 text-sm"
                                  {...field}
                                />
                              </FormControl>
                              <FormMessage />
                            </FormItem>
                          )}
                        />

                        {/* 자재명 */}
                        <FormField
                          control={form.control}
                          name={`items.${index}.itemName`}
                          render={({ field }) => (
                            <FormItem>
                              <FormLabel className="text-xs">
                                자재명 <span className="text-red-500">*</span>
                              </FormLabel>
                              <FormControl>
                                <Input
                                  placeholder="A4 용지"
                                  className="h-8 text-sm"
                                  {...field}
                                />
                              </FormControl>
                              <FormMessage />
                            </FormItem>
                          )}
                        />

                        {/* 수량 */}
                        <FormField
                          control={form.control}
                          name={`items.${index}.quantity`}
                          render={({ field }) => (
                            <FormItem>
                              <FormLabel className="text-xs">
                                수량 <span className="text-red-500">*</span>
                              </FormLabel>
                              <FormControl>
                                <Input
                                  type="number"
                                  min="1"
                                  placeholder="1"
                                  className="h-8 text-sm"
                                  {...field}
                                  onChange={(e) => field.onChange(Number(e.target.value))}
                                />
                              </FormControl>
                              <FormMessage />
                            </FormItem>
                          )}
                        />

                        {/* 단위 */}
                        <FormField
                          control={form.control}
                          name={`items.${index}.uom`}
                          render={({ field }) => (
                            <FormItem>
                              <FormLabel className="text-xs">
                                단위 <span className="text-red-500">*</span>
                              </FormLabel>
                              <FormControl>
                                <Input
                                  placeholder="EA"
                                  className="h-8 text-sm"
                                  {...field}
                                />
                              </FormControl>
                              <FormMessage />
                            </FormItem>
                          )}
                        />
                      </div>

                      {/* 비고 - 별도 행에 배치 */}
                      <div className="mt-3">
                        <FormField
                          control={form.control}
                          name={`items.${index}.remark`}
                          render={({ field }) => (
                            <FormItem>
                              <FormLabel className="text-xs">비고</FormLabel>
                              <FormControl>
                                <Input
                                  placeholder="아이템별 비고사항"
                                  className="h-8 text-sm"
                                  {...field}
                                />
                              </FormControl>
                              <FormMessage />
                            </FormItem>
                          )}
                        />
                      </div>
                    </div>
                  ))}
                </div>
              </div>
            </form>
          </Form>
        </ScrollArea>

        {/* 고정된 푸터 */}
        <DialogFooter className="flex-shrink-0">
          <Button
            type="button"
            variant="outline"
            onClick={handleCancel}
            disabled={isLoading}
          >
            취소
          </Button>
          <Button
            type="submit"
            form="createGeneralRfqForm"
            onClick={form.handleSubmit(onSubmit)}
            disabled={isLoading}
            // variant="default"
          >
            {isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
            {isLoading ? "생성 중..." : "일반견적 생성"}
          </Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}