summaryrefslogtreecommitdiff
path: root/lib/evaluation-submit/evaluation-page.tsx
blob: 810ed03e59123db8c35abeeefead2c6a757a0744 (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
"use client"

import * as React from "react"
import { useParams, useRouter } from "next/navigation"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { Button } from "@/components/ui/button"
import { Skeleton } from "@/components/ui/skeleton"
import { AlertCircle, ArrowLeft, RefreshCw } from "lucide-react"
import { Alert, AlertDescription } from "@/components/ui/alert"

import { getEvaluationFormData, EvaluationFormData } from "./service"
import { EvaluationForm } from "./evaluation-form"

/**
 * 로딩 스켈레톤 컴포넌트
 */
function EvaluationFormSkeleton() {
  return (
    <div className="container mx-auto py-6 space-y-6">
      {/* 헤더 스켈레톤 */}
      <div className="flex items-center justify-between">
        <div className="flex items-center gap-4">
          <Skeleton className="h-10 w-10" />
          <div className="space-y-2">
            <Skeleton className="h-8 w-32" />
            <Skeleton className="h-4 w-48" />
          </div>
        </div>
        <Skeleton className="h-6 w-16" />
      </div>

      {/* 평가 정보 카드 스켈레톤 */}
      <Card>
        <CardHeader>
          <Skeleton className="h-6 w-24" />
        </CardHeader>
        <CardContent>
          <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
            {[...Array(4)].map((_, i) => (
              <div key={i} className="space-y-2">
                <Skeleton className="h-4 w-16" />
                <Skeleton className="h-5 w-24" />
                <Skeleton className="h-3 w-20" />
              </div>
            ))}
          </div>
        </CardContent>
      </Card>

      {/* 진행률 카드 스켈레톤 */}
      <Card>
        <CardContent className="pt-6">
          <div className="flex items-center justify-between">
            <div className="space-y-1">
              <Skeleton className="h-4 w-16" />
              <Skeleton className="h-6 w-24" />
            </div>
            <Skeleton className="h-2 w-32" />
          </div>
        </CardContent>
      </Card>

      {/* 질문 카드들 스켈레톤 */}
      {[...Array(3)].map((_, i) => (
        <Card key={i} className="mb-6">
          <CardHeader className="pb-4">
            <div className="flex items-start justify-between">
              <div className="space-y-2">
                <div className="flex items-center gap-2">
                  <Skeleton className="h-5 w-16" />
                  <Skeleton className="h-5 w-12" />
                </div>
                <Skeleton className="h-6 w-64" />
                <Skeleton className="h-4 w-48" />
              </div>
            </div>
          </CardHeader>
          <CardContent className="space-y-4">
            <div className="space-y-3">
              <Skeleton className="h-4 w-32" />
              {[...Array(3)].map((_, j) => (
                <div key={j} className="flex items-center space-x-3 p-3 border rounded-lg">
                  <Skeleton className="h-4 w-4 rounded-full" />
                  <div className="flex-1 flex items-center justify-between">
                    <Skeleton className="h-4 w-32" />
                    <Skeleton className="h-5 w-12" />
                  </div>
                </div>
              ))}
            </div>
            <div className="space-y-2">
              <Skeleton className="h-4 w-24" />
              <Skeleton className="h-20 w-full" />
            </div>
          </CardContent>
        </Card>
      ))}
    </div>
  )
}

/**
 * 에러 상태 컴포넌트
 */
function EvaluationFormError({ 
  error, 
  onRetry 
}: { 
  error: string
  onRetry: () => void 
}) {
  const router = useRouter()

  return (
    <div className="container mx-auto py-6 space-y-6">
      <div className="flex items-center gap-4">
        <Button 
          variant="ghost" 
          size="icon"
          onClick={() => router.back()}
        >
          <ArrowLeft className="h-4 w-4" />
        </Button>
        <div>
          <h1 className="text-2xl font-bold">평가 작성</h1>
          <p className="text-muted-foreground">평가를 불러오는 중 오류가 발생했습니다</p>
        </div>
      </div>

      <Alert variant="destructive">
        <AlertCircle className="h-4 w-4" />
        <AlertDescription>
          {error}
        </AlertDescription>
      </Alert>

      <Card>
        <CardHeader>
          <CardTitle>문제 해결</CardTitle>
          <CardDescription>
            다음 방법들을 시도해보세요:
          </CardDescription>
        </CardHeader>
        <CardContent className="space-y-4">
          <ul className="list-disc pl-6 space-y-2 text-sm">
            <li>페이지를 새로고침해보세요</li>
            <li>인터넷 연결 상태를 확인해보세요</li>
            <li>잠시 후 다시 시도해보세요</li>
            <li>문제가 지속되면 관리자에게 문의하세요</li>
          </ul>
          
          <div className="flex items-center gap-2 pt-4">
            <Button onClick={onRetry} className="flex items-center gap-2">
              <RefreshCw className="h-4 w-4" />
              다시 시도
            </Button>
            <Button variant="outline" onClick={() => router.back()}>
              목록으로 돌아가기
            </Button>
          </div>
        </CardContent>
      </Card>
    </div>
  )
}

/**
 * 평가 작성 페이지 메인 컴포넌트
 */
export function EvaluationPage() {
  const params = useParams()
  const router = useRouter()
  const [formData, setFormData] = React.useState<EvaluationFormData | null>(null)
  const [isLoading, setIsLoading] = React.useState(true)
  const [error, setError] = React.useState<string | null>(null)

  const reviewerEvaluationId = params.id ? parseInt(params.id as string) : null

  // 평가 데이터 로드
  const loadEvaluationData = React.useCallback(async () => {
    if (!reviewerEvaluationId) {
      setError("잘못된 평가 ID입니다.")
      setIsLoading(false)
      return
    }

    try {
      setIsLoading(true)
      setError(null)
      
      const data = await getEvaluationFormData(reviewerEvaluationId)
      
      if (!data) {
        setError("평가 데이터를 찾을 수 없습니다.")
        return
      }
      
      setFormData(data)
    } catch (err) {
      console.error('Failed to load evaluation data:', err)
      setError(
        err instanceof Error 
          ? err.message 
          : "평가 데이터를 불러오는 중 오류가 발생했습니다."
      )
    } finally {
      setIsLoading(false)
    }
  }, [reviewerEvaluationId])

  // 초기 데이터 로드
  React.useEffect(() => {
    loadEvaluationData()
  }, [loadEvaluationData])

  // 평가 완료 후 처리
  const handleSubmitSuccess = React.useCallback(() => {
    router.push('/evaluations')
  }, [router])

  // 로딩 상태
  if (isLoading) {
    return <EvaluationFormSkeleton />
  }

  // 에러 상태
  if (error) {
    return (
      <EvaluationFormError 
        error={error} 
        onRetry={loadEvaluationData}
      />
    )
  }

  // 데이터가 없는 경우
  if (!formData) {
    return (
      <EvaluationFormError 
        error="평가 데이터를 불러올 수 없습니다." 
        onRetry={loadEvaluationData}
      />
    )
  }

  // 정상 상태 - 평가 폼 렌더링
  return (
    <EvaluationForm 
      formData={formData}
      onSubmit={handleSubmitSuccess}
    />
  )
}

// 페이지 컴포넌트용 기본 export
export default function EvaluationPageWrapper() {
  return <EvaluationPage />
}