import React, { useState, useRef, useCallback } from 'react' import { View, Text, TouchableOpacity, StyleSheet, Alert, ScrollView, TextInput } from 'react-native' import { useFocusEffect } from 'expo-router' import { COLORS } from '../../constants/Config' import client from '../../services/api' export default function ESignatureScreen() { const [docs, setDocs] = useState([]) const [selected, setSelected] = useState(null) const [pin, setPin] = useState('') const [loading, setLoading] = useState(false) const load = useCallback(async () => { setLoading(true) try { const r = await client.get('/api/approvals/pending-docs'); setDocs(r.data?.docs ?? r.data?.items ?? []) } catch { setDocs([]) } finally { setLoading(false) } }, []) useFocusEffect(useCallback(() => { load() }, [load])) const sign = async () => { if (!selected) return if (!pin || pin.length < 4) { Alert.alert('오류', 'PIN 4자리 이상 입력하세요.'); return } try { await client.post(`/api/approvals/${selected.id}/sign`, { pin_hash: pin }) Alert.alert('완료', '전자서명이 완료됐습니다.') setSelected(null) setPin('') load() } catch { Alert.alert('오류', '서명에 실패했습니다.') } } if (selected) { return ( {selected.title} 요청자: {selected.requester_name ?? '-'} · {selected.created_at?.slice(0, 10) ?? ''} {selected.content ?? selected.description ?? ''} 전자서명 PIN 입력 전자서명 완료 { setSelected(null); setPin('') }}> 취소 ) } return ( 전자서명 대기 문서 {docs.length === 0 && 서명 대기 문서가 없습니다.} {docs.map((doc, i) => ( setSelected(doc)}> {doc.title} {doc.requester_name ?? '-'} · {doc.created_at?.slice(0, 10) ?? ''} 서명하기 → ))} ) } const s = StyleSheet.create({ container: { flex: 1, backgroundColor: COLORS.bg }, header: { fontSize: 16, fontWeight: '800', color: COLORS.text, marginBottom: 12 }, card: { backgroundColor: '#fff', borderRadius: 10, padding: 14, marginBottom: 8, elevation: 1 }, cardTitle: { fontSize: 14, fontWeight: '700', color: COLORS.text, marginBottom: 4 }, cardMeta: { fontSize: 11, color: COLORS.muted, marginBottom: 8 }, cardAction: { color: COLORS.accent, fontSize: 13, fontWeight: '700' }, docCard: { backgroundColor: '#fff', borderRadius: 12, padding: 16, margin: 12, elevation: 1 }, docTitle: { fontSize: 16, fontWeight: '800', color: COLORS.text, marginBottom: 4 }, docMeta: { fontSize: 12, color: COLORS.muted, marginBottom: 10 }, docDesc: { fontSize: 13, color: COLORS.text, lineHeight: 20 }, pinLabel: { fontSize: 13, fontWeight: '700', color: COLORS.text, marginHorizontal: 12, marginTop: 8 }, pinInput: { backgroundColor: '#fff', borderRadius: 10, padding: 14, margin: 12, fontSize: 18, letterSpacing: 4, elevation: 1, color: COLORS.text }, signBtn: { backgroundColor: COLORS.success, borderRadius: 10, padding: 14, margin: 12, alignItems: 'center' }, signText: { color: '#fff', fontSize: 15, fontWeight: '800' }, cancelBtn: { borderRadius: 10, padding: 12, marginHorizontal: 12, alignItems: 'center' }, cancelText: { color: COLORS.muted, fontSize: 14 }, empty: { textAlign: 'center', color: COLORS.muted, marginTop: 40 }, })