File size: 8,512 Bytes
f359e2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { useState, useEffect } from 'react';
import { Upload, CheckCircle, AlertCircle, Loader2, FileCheck } from 'lucide-react';
import api from '../api/api';

const VerificationPanel = ({ photographerId }) => {
  const [verification, setVerification] = useState(null);
  const [loading, setLoading] = useState(true);
  const [uploadingID, setUploadingID] = useState(false);
  const [uploadingPortfolio, setUploadingPortfolio] = useState(false);

  useEffect(() => {
    fetchVerificationStatus();
  }, []);

  const fetchVerificationStatus = async () => {
    try {
      const res = await api.get(`/verification/status/${photographerId}`);
      setVerification(res.data);
    } catch (err) {
      console.error('Failed to load verification status:', err);
    } finally {
      setLoading(false);
    }
  };

  const handleIDUpload = async (e) => {
    const file = e.target.files?.[0];
    if (!file) return;

    // In real app, upload to Cloudinary or similar
    setUploadingID(true);
    try {
      // Mock upload - in production use FormData with multipart
      const idUrl = URL.createObjectURL(file);

      const res = await api.post('/verification/submit', {
        idDocumentUrl: idUrl,
      });

      setVerification(res.data);
      alert('ID uploaded successfully!');
    } catch (err) {
      alert('Failed to upload ID');
    } finally {
      setUploadingID(false);
    }
  };

  const handlePortfolioUpload = async (e) => {
    const files = e.target.files;
    if (!files || files.length === 0) return;

    setUploadingPortfolio(true);
    try {
      const portfolioUrls = Array.from(files).map(file => URL.createObjectURL(file));

      const res = await api.post('/verification/submit', {
        portfolioUrls,
      });

      setVerification(res.data);
      alert(`${files.length} portfolio images uploaded!`);
    } catch (err) {
      alert('Failed to upload portfolio images');
    } finally {
      setUploadingPortfolio(false);
    }
  };

  if (loading) {
    return (
      <div className="flex items-center justify-center py-12">
        <Loader2 className="animate-spin text-blue-600" size={32} />
      </div>
    );
  }

  const statusColor = {
    verified: 'green',
    pending: 'amber',
    rejected: 'red',
    not_started: 'gray',
  };

  const statusIcon = {
    verified: <CheckCircle className="text-green-600" size={32} />,
    pending: <AlertCircle className="text-amber-600" size={32} />,
    rejected: <AlertCircle className="text-red-600" size={32} />,
    not_started: <AlertCircle className="text-gray-600" size={32} />,
  };

  const status = verification?.status || 'not_started';
  const color = statusColor[status];

  return (
    <div>
      <h2 className="text-2xl font-bold mb-6">๐Ÿ“‹ Photographer Verification</h2>

      {/* Status Card */}
      <div className={`bg-${color}-50 border border-${color}-200 rounded-lg p-6 mb-6`}>
        <div className="flex items-center gap-4">
          <div>{statusIcon[status]}</div>
          <div>
            <h3 className={`text-lg font-bold text-${color}-900 capitalize`}>
              Status: {status.replace('_', ' ')}
            </h3>
            {verification?.submittedAt && (
              <p className={`text-sm text-${color}-700`}>
                Submitted: {new Date(verification.submittedAt).toLocaleDateString()}
              </p>
            )}
            {verification?.verifiedAt && (
              <p className={`text-sm text-${color}-700`}>
                Verified: {new Date(verification.verifiedAt).toLocaleDateString()}
              </p>
            )}
          </div>
        </div>
      </div>

      {/* ID Verification Section */}
      <div className="bg-white border border-gray-200 rounded-lg p-6 mb-6">
        <h3 className="text-lg font-bold mb-4 flex items-center gap-2">
          <FileCheck size={20} />
          Step 1: ID Verification
        </h3>

        {verification?.idDocument ? (
          <div className="bg-green-50 border border-green-200 rounded-lg p-4 mb-4">
            <div className="flex items-center gap-2 text-green-700 font-semibold">
              <CheckCircle size={20} />
              ID Document Verified โœ“
            </div>
            {verification?.idVerifiedAt && (
              <p className="text-sm text-green-600 mt-1">
                Verified on {new Date(verification.idVerifiedAt).toLocaleDateString()}
              </p>
            )}
          </div>
        ) : (
          <div>
            <p className="text-gray-700 mb-4">
              Upload a clear copy of your government-issued ID (Aadhar, PAN, Passport, etc.)
            </p>
            <label className="flex items-center justify-center border-2 border-dashed border-gray-300 rounded-lg p-8 hover:border-blue-500 cursor-pointer transition">
              <div className="text-center">
                <Upload className="mx-auto mb-2 text-gray-400" size={32} />
                <p className="font-semibold text-gray-700">Click to upload ID</p>
                <p className="text-sm text-gray-500">or drag and drop</p>
              </div>
              <input
                type="file"
                onChange={handleIDUpload}
                disabled={uploadingID}
                className="hidden"
                accept="image/*,.pdf"
              />
            </label>
            {uploadingID && <p className="text-sm text-blue-600 mt-2">Uploading...</p>}
          </div>
        )}
      </div>

      {/* Portfolio Verification Section */}
      <div className="bg-white border border-gray-200 rounded-lg p-6 mb-6">
        <h3 className="text-lg font-bold mb-4 flex items-center gap-2">
          <FileCheck size={20} />
          Step 2: Portfolio Verification
        </h3>

        {verification?.portfolioSamples?.length > 0 ? (
          <div>
            <p className="text-green-700 font-semibold mb-4">
              โœ“ {verification.portfolioSamples.length} portfolio images uploaded
            </p>
            <div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-4">
              {verification.portfolioSamples.map((sample, idx) => (
                <div key={idx} className="aspect-square bg-gray-200 rounded-lg overflow-hidden">
                  <img
                    src={sample.url}
                    alt={`Portfolio ${idx + 1}`}
                    className="w-full h-full object-cover"
                  />
                </div>
              ))}
            </div>
          </div>
        ) : (
          <div>
            <p className="text-gray-700 mb-4">
              Upload 3-5 of your best portfolio samples to showcase your work quality.
            </p>
            <label className="flex items-center justify-center border-2 border-dashed border-gray-300 rounded-lg p-8 hover:border-blue-500 cursor-pointer transition">
              <div className="text-center">
                <Upload className="mx-auto mb-2 text-gray-400" size={32} />
                <p className="font-semibold text-gray-700">Click to upload portfolio</p>
                <p className="text-sm text-gray-500">Upload multiple images (PNG, JPG)</p>
              </div>
              <input
                type="file"
                onChange={handlePortfolioUpload}
                disabled={uploadingPortfolio}
                multiple
                className="hidden"
                accept="image/*"
              />
            </label>
            {uploadingPortfolio && <p className="text-sm text-blue-600 mt-2">Uploading...</p>}
          </div>
        )}
      </div>

      {/* Admin Notes */}
      {verification?.adminNotes && (
        <div className="bg-blue-50 border border-blue-200 rounded-lg p-6">
          <h3 className="font-bold text-blue-900 mb-2">Admin Notes</h3>
          <p className="text-blue-800">{verification.adminNotes}</p>
        </div>
      )}

      {/* Rejection Info */}
      {status === 'rejected' && verification?.rejectionReason && (
        <div className="bg-red-50 border border-red-200 rounded-lg p-6 mb-6">
          <h3 className="font-bold text-red-900 mb-2">Rejection Reason</h3>
          <p className="text-red-800 mb-4">{verification.rejectionReason}</p>
          {verification?.resubmissionAllowed && (
            <button className="bg-red-600 text-white px-4 py-2 rounded-lg hover:bg-red-700 font-medium">
              Resubmit Application
            </button>
          )}
        </div>
      )}
    </div>
  );
};

export default VerificationPanel;