import { router, useLocalSearchParams } from 'expo-router'; import { Alert, ScrollView, Text, View } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import { WORK_ORDER_PRIORITY_LABELS, WORK_ORDER_TYPE_LABELS, } from '@siop/shared'; import { useTransition, useWorkOrder } from '@/api/exploitation'; import { useHorsLigne } from '@/auth/session'; import { BoutonTel, Carte, ChipStatut, EnteteFiche, LigneInfo } from '@/composants/ui'; import { progression } from '@/lib/checklist'; import { useTokens } from '@/theme/tokens'; const fmt = new Intl.NumberFormat('fr-FR'); /** Écran 2 de la maquette R4 : la même machine à états que le web — UN * bouton principal selon l'état, la garde de clôture visible. En R4.2 les * écritures restent en ligne (la file arrive en R4.3 — assumé à l'écran). */ export default function PageFicheOT() { const t = useTokens(); const horsLigne = useHorsLigne(); const { id } = useLocalSearchParams<{ id: string }>(); const { data: ot } = useWorkOrder(id); const transition = useTransition(id); if (!ot) return null; const grille = progression(ot.checklist); const peutDemarrer = ot.allowedTransitions.includes('IN_PROGRESS'); const peutCloturer = ot.allowedTransitions.includes('DONE'); const peutSuspendre = ot.allowedTransitions.includes('ON_HOLD'); const demarrer = () => transition.mutate( { to: 'IN_PROGRESS' }, { onError: (e) => Alert.alert('Transition refusée', e.message) }, ); return ( } /> {ot.title} {horsLigne ? ( ⚠ Hors-ligne — lecture seule pour l’instant : les saisies hors réseau arrivent en R4.3 (file). ) : null} {WORK_ORDER_PRIORITY_LABELS[ot.priority]} } /> {ot.request ? ( ) : null} {ot.costs.parts.map((p) => ( ))} {ot.costs.labor.map((l) => ( ))} {!ot.costs.parts.length && !ot.costs.labor.length ? ( Aucune consommation ni temps saisi. (Saisies pièces/temps : depuis le web en R4.2.) ) : null} {ot.checklist.length ? ( router.push(`/ot/${ot.id}/grille`)} /> ) : null} {ot.closureBlockers.length && (peutCloturer || ot.status === 'IN_PROGRESS') ? ( ⚠ {ot.closureBlockers.join(' · ')} ) : null} {peutDemarrer ? ( ) : null} {peutCloturer ? ( router.push(`/ot/${ot.id}/cloture`)} /> ) : null} {peutSuspendre ? ( transition.mutate( { to: 'ON_HOLD' }, { onError: (e) => Alert.alert('Transition refusée', e.message) }, ) } /> ) : null} {ot.events.slice(0, 5).map((e) => ( {e.kind} {e.message ? ` — ${e.message}` : ''} {new Intl.DateTimeFormat('fr-FR', { dateStyle: 'medium', timeStyle: 'short' }).format( new Date(e.createdAt), )} {e.by ? ` · ${e.by.displayName}` : ''} ))} ); }