import { useEffect, useState } from 'react' import { View, Text, ScrollView, StyleSheet, TouchableOpacity, RefreshControl, ActivityIndicator, TextInput, Modal, Alert, } from 'react-native' import { COLORS, PRIORITY_COLOR, STATUS_COLOR } from '../../constants/Config' import { getSRList, createSR } from '../../services/api' const PRIORITIES = ['CRITICAL','HIGH','MEDIUM','LOW'] const TYPES = ['DEPLOY','RESTART','LOG','INQUIRY','OTHER'] export default function SRScreen() { const [items, setItems] = useState([]) const [loading, setLoading] = useState(true) const [refresh, setRefresh] = useState(false) const [creating, setCreating] = useState(false) const [form, setForm] = useState({ title: '', description: '', priority: 'MEDIUM', sr_type: 'OTHER' }) const [modal, setModal] = useState(false) const [saving, setSaving] = useState(false) const load = async (r = false) => { r ? setRefresh(true) : setLoading(true) try { const res = await getSRList() setItems(res.data.content ?? res.data.items ?? res.data ?? []) } catch {} setLoading(false); setRefresh(false) } useEffect(() => { load() }, []) const submit = async () => { if (!form.title.trim()) { Alert.alert('제목을 입력하세요.'); return } setSaving(true) try { await createSR(form) setModal(false) setForm({ title:'', description:'', priority:'MEDIUM', sr_type:'OTHER' }) await load() Alert.alert('등록 완료', 'SR이 접수되었습니다.') } catch (e: any) { Alert.alert('오류', e.response?.data?.detail ?? 'SR 등록 실패') } finally { setSaving(false) } } return ( 서비스 요청 목록 setModal(true)}> + 새 SR {loading ? : ( load(true)} />} > {items.length === 0 && ( SR이 없습니다. )} {items.map(sr => ( {sr.sr_id} {sr.status} {sr.title} {sr.priority} {sr.requested_by} {sr.created_at?.slice(0,10)} ))} ) } {/* SR 등록 모달 */} 새 SR 등록 setModal(false)}> {[ { label: '제목 *', key: 'title', ph: 'SR 제목을 입력하세요', multi: false }, { label: '설명', key: 'description', ph: '상세 내용을 입력하세요', multi: true }, ].map(f => ( {f.label} setForm(p => ({ ...p, [f.key]: v }))} placeholder={f.ph} placeholderTextColor={COLORS.muted} multiline={f.multi} /> ))} 우선순위 {PRIORITIES.map(p => ( setForm(f => ({ ...f, priority: p }))} > {p} ))} 유형 {TYPES.map(t => ( setForm(f => ({ ...f, sr_type: t }))} > {t} ))} {saving ? : SR 등록 } ) } const s = StyleSheet.create({ toolbar: { flexDirection:'row', justifyContent:'space-between', alignItems:'center', backgroundColor:'#fff', paddingHorizontal:16, paddingVertical:12, borderBottomWidth:1, borderBottomColor:COLORS.border }, toolbarTitle:{ fontSize:15, fontWeight:'700', color:COLORS.text }, addBtn: { backgroundColor:COLORS.accent, paddingHorizontal:14, paddingVertical:7, borderRadius:8 }, addBtnText: { color:'#fff', fontSize:13, fontWeight:'600' }, card: { backgroundColor:'#fff', marginHorizontal:16, marginTop:10, borderRadius:10, padding:14, elevation:1 }, cardHead: { flexDirection:'row', justifyContent:'space-between', marginBottom:6 }, srId: { fontSize:11, color:COLORS.accent, fontWeight:'600' }, statusBadge: { paddingHorizontal:8, paddingVertical:2, borderRadius:10 }, statusText: { fontSize:10, fontWeight:'600' }, srTitle: { fontSize:14, fontWeight:'600', color:COLORS.text, marginBottom:8 }, cardFoot: { flexDirection:'row', alignItems:'center', gap:8 }, priBadge: { paddingHorizontal:8, paddingVertical:2, borderRadius:10 }, priText: { fontSize:10, fontWeight:'700' }, metaText: { fontSize:11, color:COLORS.muted }, modal: { flex:1, backgroundColor:'#fff' }, modalHead: { flexDirection:'row', justifyContent:'space-between', alignItems:'center', padding:20, borderBottomWidth:1, borderBottomColor:COLORS.border }, modalTitle: { fontSize:17, fontWeight:'700', color:COLORS.text }, field: { marginBottom:16 }, label: { fontSize:11, fontWeight:'600', color:COLORS.muted, marginBottom:6, textTransform:'uppercase', letterSpacing:.5 }, input: { borderWidth:1.5, borderColor:COLORS.border, borderRadius:9, padding:12, fontSize:14, color:COLORS.text }, chips: { flexDirection:'row', flexWrap:'wrap', gap:8 }, chip: { paddingHorizontal:12, paddingVertical:6, borderRadius:20, borderWidth:1, borderColor:COLORS.border }, chipActive: { backgroundColor:COLORS.accent, borderColor:COLORS.accent }, chipText: { fontSize:12, color:COLORS.text }, submitBtn: { backgroundColor:COLORS.primary, borderRadius:10, padding:15, alignItems:'center', marginTop:8, marginBottom:32 }, submitText: { color:'#fff', fontSize:15, fontWeight:'700' }, })