diff --git a/src/components/DocumentViewer.jsx b/src/components/DocumentViewer.jsx index 930d9b2..0857f3d 100644 --- a/src/components/DocumentViewer.jsx +++ b/src/components/DocumentViewer.jsx @@ -1,6 +1,38 @@ -import React from 'react'; +import React, { useState } from 'react'; +import StatusBadge from './StatusBadge'; +import { API_BASE_URL } from '../config'; +import { useAuth } from '../context/AuthContext'; + +const DocumentViewer = ({ documents, sellerId, refreshDocs }) => { + const { token } = useAuth(); + const [previewDoc, setPreviewDoc] = useState(null); + + const handleApprove = async (docId) => { + try { + const res = await fetch(`${API_BASE_URL}/sellers/${sellerId}/documents/${docId}/approve/`, { + method: 'POST', + headers: { + 'Authorization': `Bearer ${token}`, + 'Content-Type': 'application/json' + } + }); + if (!res.ok) throw new Error('Failed to approve document'); + alert('Document approved successfully'); + if (refreshDocs) refreshDocs(); + } catch (err) { + alert(err.message); + } + }; + + const handleDownload = (doc) => { + const link = document.createElement('a'); + link.href = doc.url; + link.download = doc.filename; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + }; -const DocumentViewer = ({ documents, sellerId }) => { return (

KYC Document Verification

@@ -11,29 +43,60 @@ const DocumentViewer = ({ documents, sellerId }) => { background: 'rgba(255, 255, 255, 0.02)', border: '1px solid var(--glass-border)', borderRadius: 'var(--border-radius)', - padding: '16px' + padding: '16px', + display: 'flex', + flexDirection: 'column', + justifyContent: 'space-between' }}> -
- {doc.type} - Status: Verified +
+
+ {doc.type} + +
+
+ {doc.filename.match(/\.(jpg|jpeg|png)$/i) ? ( + {doc.type} + ) : ( + [Document Preview: {doc.filename}] + )} +
-
- [Presigned Document Preview: {doc.filename}] -
-
- - Open Original - +
+ + +
))} @@ -41,6 +104,41 @@ const DocumentViewer = ({ documents, sellerId }) => { ) : (

No KYC documents submitted yet.

)} + + {/* Lightbox / Preview Modal Overlay */} + {previewDoc && ( +
setPreviewDoc(null)}> +
e.stopPropagation()}> +
+

Document Preview: {previewDoc.type}

+ +
+
+ {previewDoc.filename.match(/\.(jpg|jpeg|png)$/i) ? ( + {previewDoc.type} + ) : previewDoc.filename.match(/\.pdf$/i) ? ( +