mirror of
https://github.com/siop-spelev/siop2.git
synced 2026-08-08 20:51:53 +00:00
Serveur : updatedAt exposé au détail OT ; baseUpdatedAt optionnel sur transition/coche/bilan → 409 « Conflit de version » contextualisé (qui, quand) ; toute écriture secondaire (coche, bilan, commentaire, conso, MO) fait avancer la version — sans version fournie, le web est inchangé. ADR-003 : sécurité & protocole de routage mobile (qui vit où sur l'appareil, purge complète à la déconnexion — correctif réel : la file et le cache persisté survivaient au logout). Mobile : file persistée AsyncStorage rejouée dans l'ordre — succès → propagation de la version fraîche aux saisies restantes du même OT (nos écritures ne se conflictent pas entre elles, un écart étranger reste détecté) ; coupure → tout attend ; refus → CONFLIT, la file s'arrête, l'humain tranche (voir l'OT / rejouer sur version à jour / abandonner). Transitions, coches, bilan et photos (D5, compressées ~1600 px) passent par la file avec patch optimiste du cache ; écran Synchro (badge tabbar ambre/rouge) ; préchargement parc + référentiels (le bilan hors-ligne a ses vocabulaires). Recette « mode avion » 13/13 en Expo web piloté : gestes hors-ligne → 3 en file → modification concurrente de Salma → conflit tranché → serveur Terminé avec bilan. 17 tests jest-expo, 74 tests API. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
146 lines
5.3 KiB
TypeScript
146 lines
5.3 KiB
TypeScript
import { useQueryClient } from '@tanstack/react-query';
|
|
import { useLocalSearchParams } from 'expo-router';
|
|
import { Pressable, ScrollView, Text, View } from 'react-native';
|
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
import { useWorkOrder } from '@/api/exploitation';
|
|
import { useHorsLigne } from '@/auth/session';
|
|
import { EnteteFiche } from '@/composants/ui';
|
|
import { enfilerCoche } from '@/file/actions';
|
|
import { useFile } from '@/file/store';
|
|
import { prochainEtat, progression } from '@/lib/checklist';
|
|
import { useTokens } from '@/theme/tokens';
|
|
|
|
/** Écran 6 de la maquette R4 : la grille au pouce. Appui simple = coche,
|
|
* appui long = non-applicable. Chaque coche part en file INDIVIDUELLEMENT
|
|
* (D1) : 7 coches faites = 7 coches sauvées, réseau ou pas. */
|
|
export default function PageGrille() {
|
|
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 { faits, total, pct } = progression(ot.checklist);
|
|
const enFile = new Set(
|
|
file.flatMap((s) => (s.otId === ot.id && s.type === 'COCHE' ? [s.payload.itemId] : [])),
|
|
);
|
|
|
|
const basculer = (item: { id: string; label: string }, etat: Parameters<typeof prochainEtat>[0], versNA = false) => {
|
|
enfilerCoche(
|
|
queryClient,
|
|
ot,
|
|
item,
|
|
versNA ? (etat === 'NA' ? 'PENDING' : 'NA') : prochainEtat(etat),
|
|
);
|
|
};
|
|
|
|
return (
|
|
<SafeAreaView style={{ flex: 1, backgroundColor: t.fond }} edges={['top']}>
|
|
<ScrollView contentContainerStyle={{ padding: 14, gap: 10 }}>
|
|
<EnteteFiche
|
|
titre={`Grille — ${ot.assetReference}`}
|
|
apres={
|
|
<Text style={{ fontFamily: 'Manrope_800ExtraBold', fontSize: 13, color: t.encre2 }}>
|
|
{faits}/{total}
|
|
</Text>
|
|
}
|
|
/>
|
|
<View style={{ height: 8, borderRadius: 999, backgroundColor: t.surface2, overflow: 'hidden' }}>
|
|
<View
|
|
style={{ width: `${Math.round(pct * 100)}%`, height: '100%', backgroundColor: t.succes }}
|
|
/>
|
|
</View>
|
|
{horsLigne ? (
|
|
<View
|
|
style={{
|
|
backgroundColor: t.stAttenteFond,
|
|
borderColor: t.stAttente,
|
|
borderWidth: 1,
|
|
borderRadius: 10,
|
|
padding: 9,
|
|
}}
|
|
>
|
|
<Text style={{ color: t.stAttente, fontFamily: 'Manrope_700Bold', fontSize: 12 }}>
|
|
⚠ Hors-ligne — chaque coche part en file et se synchronisera au retour du réseau.
|
|
</Text>
|
|
</View>
|
|
) : null}
|
|
{ot.checklist.map((item) => (
|
|
<Pressable
|
|
key={item.id}
|
|
accessibilityRole="checkbox"
|
|
aria-checked={item.state === 'DONE'}
|
|
accessibilityLabel={item.label}
|
|
onPress={() => basculer(item, item.state)}
|
|
onLongPress={() => basculer(item, item.state, true)}
|
|
style={{
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
gap: 10,
|
|
backgroundColor: t.surface,
|
|
borderColor: t.bordure,
|
|
borderWidth: 1,
|
|
borderRadius: 10,
|
|
paddingHorizontal: 12,
|
|
paddingVertical: 11,
|
|
}}
|
|
>
|
|
<View
|
|
style={{
|
|
width: 22,
|
|
height: 22,
|
|
borderRadius: 6,
|
|
borderWidth: 2,
|
|
borderColor: item.state === 'DONE' ? t.succes : t.bordureForte,
|
|
backgroundColor: item.state === 'DONE' ? t.succes : 'transparent',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
}}
|
|
>
|
|
{item.state === 'DONE' ? (
|
|
<Text style={{ color: '#fff', fontSize: 13, fontFamily: 'Manrope_800ExtraBold' }}>✓</Text>
|
|
) : item.state === 'NA' ? (
|
|
<Text style={{ color: t.encre3, fontSize: 10, fontFamily: 'Manrope_800ExtraBold' }}>NA</Text>
|
|
) : null}
|
|
</View>
|
|
<Text
|
|
style={{
|
|
flex: 1,
|
|
fontFamily: 'Manrope_600SemiBold',
|
|
fontSize: 13,
|
|
color: item.state === 'PENDING' ? t.encre : t.encre2,
|
|
}}
|
|
>
|
|
{item.label}
|
|
</Text>
|
|
{enFile.has(item.id) ? (
|
|
<Text
|
|
style={{
|
|
fontFamily: 'Manrope_800ExtraBold',
|
|
fontSize: 9,
|
|
color: t.stAttente,
|
|
backgroundColor: t.stAttenteFond,
|
|
paddingHorizontal: 6,
|
|
borderRadius: 999,
|
|
overflow: 'hidden',
|
|
}}
|
|
>
|
|
en file
|
|
</Text>
|
|
) : item.doneBy ? (
|
|
<Text style={{ fontFamily: 'Manrope_400Regular', fontSize: 10.5, color: t.encre3 }}>
|
|
{item.doneBy.displayName.split(' ')[0]}
|
|
</Text>
|
|
) : null}
|
|
</Pressable>
|
|
))}
|
|
<Text style={{ color: t.encre3, fontFamily: 'Manrope_400Regular', fontSize: 11.5 }}>
|
|
Appui simple : cocher / décocher · appui long : non-applicable.
|
|
</Text>
|
|
</ScrollView>
|
|
</SafeAreaView>
|
|
);
|
|
}
|