summaryrefslogtreecommitdiff
path: root/lib/pq/pq-review-table-new/cancel-investigation-dialog.tsx
blob: e22b9ca13741b8866ea95d167c4a39308a06400f (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
"use client"

import * as React from "react"

import { Button } from "@/components/ui/button"
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
} from "@/components/ui/dialog"
import { Textarea } from "@/components/ui/textarea"
import { Label } from "@/components/ui/label"

interface CancelInvestigationDialogProps {
  isOpen: boolean
  onClose: () => void
  onConfirm: () => Promise<void>
  selectedCount: number
}

export function CancelInvestigationDialog({
  isOpen,
  onClose,
  onConfirm,
  selectedCount,
}: CancelInvestigationDialogProps) {
  const [isPending, setIsPending] = React.useState(false)

  async function handleConfirm() {
    setIsPending(true)
    try {
      await onConfirm()
    } finally {
      setIsPending(false)
    }
  }

  return (
    <Dialog open={isOpen} onOpenChange={(open) => !open && onClose()}>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>실사 의뢰 취소</DialogTitle>
          <DialogDescription>
            선택한 {selectedCount}개 협력업체의 실사 의뢰를 취소하시겠습니까?
            계획 상태인 실사만 취소할 수 있습니다.
          </DialogDescription>
        </DialogHeader>
        <DialogFooter>
          <Button
            type="button"
            variant="outline"
            onClick={onClose}
            disabled={isPending}
          >
            취소
          </Button>
          <Button
            variant="destructive"
            onClick={handleConfirm}
            disabled={isPending}
          >
            {isPending ? "처리 중..." : "실사 의뢰 취소"}
          </Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}

interface ReRequestInvestigationDialogProps {
  isOpen: boolean
  onClose: () => void
  onConfirm: (reason?: string) => Promise<void>
  selectedCount: number
}

export function ReRequestInvestigationDialog({
  isOpen,
  onClose,
  onConfirm,
  selectedCount,
}: ReRequestInvestigationDialogProps) {
  const [isPending, setIsPending] = React.useState(false)
  const [reason, setReason] = React.useState("")

  async function handleConfirm() {
    setIsPending(true)
    try {
      await onConfirm(reason || undefined)
    } finally {
      setIsPending(false)
    }
  }

  // Dialog가 닫힐 때 상태 초기화
  React.useEffect(() => {
    if (!isOpen) {
      setReason("")
    }
  }, [isOpen])

  return (
    <Dialog open={isOpen} onOpenChange={(open) => !open && onClose()}>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>실사 재의뢰</DialogTitle>
          <DialogDescription>
            선택한 {selectedCount}개 협력업체의 실사를 재의뢰하시겠습니까?
            취소 상태인 실사만 재의뢰할 수 있습니다.
          </DialogDescription>
        </DialogHeader>
        
        <div className="space-y-4 py-4">
          <div className="space-y-2">
            <Label htmlFor="reason">재의뢰 사유 (선택)</Label>
            <Textarea
              id="reason"
              placeholder="재의뢰 사유를 입력해주세요..."
              value={reason}
              onChange={(e) => setReason(e.target.value)}
              rows={4}
              disabled={isPending}
            />
          </div>
        </div>

        <DialogFooter>
          <Button
            type="button"
            variant="outline"
            onClick={onClose}
            disabled={isPending}
          >
            취소
          </Button>
          <Button
            variant="default"
            onClick={handleConfirm}
            disabled={isPending}
          >
            {isPending ? "처리 중..." : "실사 재의뢰"}
          </Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}