import { useEffect, useState } from 'react' import { View, Text, TouchableOpacity, StyleSheet, ActivityIndicator } from 'react-native' import { router } from 'expo-router' import { COLORS, PRIORITY_COLOR, STATUS_COLOR } from '../constants/Config' import { getRelatedSR } from '../services/api' interface Props { srId: number } interface RelatedItem { id: number sr_id?: string title: string status?: string priority?: string } /** * 기능 #7 — 관련 SR 자동 연결 표시 * GET /api/tasks?related_to={id} → 최대 3개 카드, 탭 시 상세 이동 */ export default function RelatedSR({ srId }: Props) { const [items, setItems] = useState([]) const [loading, setLoading] = useState(true) useEffect(() => { let alive = true ;(async () => { try { const res = await getRelatedSR(srId) const list: RelatedItem[] = res.data?.content ?? res.data?.items ?? res.data ?? [] if (alive) setItems(list.slice(0, 3)) } catch { if (alive) setItems([]) } finally { if (alive) setLoading(false) } })() return () => { alive = false } }, [srId]) if (loading) return if (items.length === 0) { return 관련 SR이 없습니다. } return ( {items.map(it => ( router.push({ pathname: '/(tabs)/sr_detail', params: { id: String(it.id) } })} > {it.sr_id ?? `#${it.id}`} {!!it.status && ( {it.status} )} {it.title} {!!it.priority && ( ● {it.priority} )} ))} ) } const s = StyleSheet.create({ empty: { color: COLORS.muted, fontSize: 12, paddingVertical: 8 }, card: { backgroundColor: COLORS.light, borderRadius: 8, padding: 10, marginBottom: 8 }, head: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }, srId: { fontSize: 11, color: COLORS.accent, fontWeight: '700' }, badge: { paddingHorizontal: 7, paddingVertical: 2, borderRadius: 9 }, badgeText: { fontSize: 9, fontWeight: '700' }, title: { fontSize: 13, color: COLORS.text, marginTop: 4 }, pri: { fontSize: 10, fontWeight: '700', marginTop: 4 }, })