import { useQueryClient } from '@tanstack/react-query'; import { router, useLocalSearchParams } from 'expo-router'; import { 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 { useWorkOrder } from '@/api/exploitation'; import { useHorsLigne } from '@/auth/session'; import { BoutonTel, Carte, ChipStatut, EnteteFiche, LigneInfo } from '@/composants/ui'; import { CartePhotos } from '@/composants/carte-photos'; import { enfilerTransition } from '@/file/actions'; import { useFile } from '@/file/store'; 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. Depuis R4.3, chaque geste part en file * (D1) : l'écran montre l'état local tout de suite, la synchro suit. */ export default function PageFicheOT() { const t = useTokens(); const horsLigne = useHorsLigne(); const { id } = useLocalSearchParams<{ id: string }>(); const { data: ot } = useWorkOrder(id); const queryClient = useQueryClient(); const file = useFile(); if (!ot) return null; const grille = progression(ot.checklist); const enFile = file.filter((s) => s.otId === ot.id); const peutDemarrer = ot.allowedTransitions.includes('IN_PROGRESS'); const peutCloturer = ot.allowedTransitions.includes('DONE'); const peutSuspendre = ot.allowedTransitions.includes('ON_HOLD'); const demarrer = () => enfilerTransition(queryClient, ot, 'IN_PROGRESS'); return ( {enFile.length ? ( {enFile.length} en file ) : null} } /> {ot.title} {horsLigne ? ( ⚠ Hors-ligne — vos gestes partent en file et se synchroniseront au retour du réseau. ) : 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 ? ( enfilerTransition(queryClient, ot, 'ON_HOLD')} /> ) : 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}` : ''} ))} ); }