import React, { useEffect, useState } from 'react'; import { View, Text, ScrollView, TouchableOpacity, Modal, Image, ActivityIndicator, SafeAreaView, } from 'react-native'; import Pdf from 'react-native-pdf'; import { useAppTheme } from '@theme'; import { ScreenHeader } from '@components'; import { ClipboardIcon, CloseIcon, ChevronRightIcon } from '@icons'; import { useNavigation } from '@react-navigation/native'; import { getFullUrl, isPdf } from '@utils/helper'; import { getStyles } from './documentsScreen.styles'; import { KycDocUploadResponseDocument } from '@interfaces'; import { formatDate } from '@utils/formatters'; import { useAppDispatch, useAppSelector } from '@store'; import { fetchMyKyc } from '../kycScreen'; export const DocumentsScreen: React.FC = () => { const { colors } = useAppTheme(); const styles = getStyles(colors); const navigation = useNavigation(); const dispatch = useAppDispatch(); const [selectedDoc, setSelectedDoc] = useState(null); const [isModalLoading, setIsModalLoading] = useState(true); const { myKycResponse } = useAppSelector(state => state.kyc); useEffect(() => { dispatch(fetchMyKyc()); }, []); const getStatusBadgeConfig = (status: string) => { switch (status?.toUpperCase()) { case 'APPROVED': case 'VERIFIED': return { bg: colors.successLight, text: colors.success, label: 'APPROVED', }; case 'PENDING': return { bg: colors.warningLight, text: colors.warning, label: 'PENDING', }; case 'REJECTED': return { bg: colors.errorLight, text: colors.error, label: 'REJECTED', }; default: return { bg: colors.primaryLight, text: colors.primary, label: status?.toUpperCase() || 'ACTIVE', }; } }; const handleOpenDocModal = (doc: KycDocUploadResponseDocument) => { setIsModalLoading(true); setSelectedDoc(doc); }; const approvedCount = myKycResponse?.documents?.filter( d => d.status === 'APPROVED', ).length; return ( {/* Screen Header */} navigation.goBack()} /> {/* Document Status Overview Banner */} Document Verification {approvedCount} of {myKycResponse?.documents?.length} Documents Verified {approvedCount === myKycResponse?.documents?.length ? 'VERIFIED' : 'PENDING'} Uploaded Documents {myKycResponse?.documents?.length === 0 ? ( No Documents Found Your uploaded documents will appear here. ) : ( myKycResponse?.documents?.map(doc => { const statusConfig = getStatusBadgeConfig(doc.status); const formattedDocName = doc.documentType === 'Pan' ? 'PAN Card' : doc.documentType; return ( handleOpenDocModal(doc)} > {/* Header Row */} {formattedDocName} Doc #: {doc.documentNumber} {statusConfig.label} {/* Details Section */} Uploaded On {formatDate(doc.createdAt)} {doc.verifiedAt && ( Verified On {formatDate(doc.verifiedAt)} )} {/* View Button Footer */} View Document ); }) )} {/* Full Screen View Modal */} setSelectedDoc(null)} > {/* Modal Header */} {selectedDoc?.documentType === 'Pan' ? 'PAN Card' : selectedDoc?.documentType}{' '} Preview {selectedDoc?.fileName} setSelectedDoc(null)} > {/* Modal Body / Viewer */} {isModalLoading && ( Loading file preview... )} {selectedDoc && isPdf(selectedDoc.fileName || selectedDoc.fileUrl) ? ( setIsModalLoading(false)} onError={error => { setIsModalLoading(false); console.log('PDF Load Error:', error); }} style={styles.pdfViewer} /> ) : ( selectedDoc && ( setIsModalLoading(true)} onLoadEnd={() => setIsModalLoading(false)} onError={() => setIsModalLoading(false)} /> ) )} ); }; export default DocumentsScreen;