diff --git a/app/(tabs)/addChantier.tsx b/app/(tabs)/addChantier.tsx index d31caba..ffc021d 100644 --- a/app/(tabs)/addChantier.tsx +++ b/app/(tabs)/addChantier.tsx @@ -20,6 +20,10 @@ import Constants from 'expo-constants'; //pour connaître la taille de la barre import SelectChafChantier from '@/components/selectChefChantier'; import SelectMachine from '@/components/selectMachine'; + + type RessourcesQte = [Ressources, number]; + + //Uniquement accessible par le RESPONSSABLE du chantier //Pour créer ou modifier un chantier export default function AddChantier() { @@ -37,8 +41,8 @@ export default function AddChantier() { const [adresse, setAdresse] = useState(''); const [duree, setDuree] = useState(''); const [contact, setContact] = useState(''); - const [engins, setEngins] = useState(); //de type enfin /!\ - const [materiels, setMateriels] = useState(); //de type material (outils) /!\ + const [machine, setMachines] = useState(); //de type enfin /!\ + const [materiels, setMateriels] = useState(); //de type material (outils) /!\ const [showDateSelect,setSowDateSelect] = useState(false); const [openConfirmation,setOpenConfirmation] = useState(false); @@ -46,6 +50,9 @@ export default function AddChantier() { const [userSelect, setUserSelect] = useState([]); const [ressourcesSelect, setRessourcesSelect] = useState([]); + + + async function handleAddChantier() { setLoading(true); setOpenConfirmation(true); @@ -59,23 +66,23 @@ export default function AddChantier() { } }; - async function onConfirm(): Promise { - //TODO - //await changeChantierStatus(chantier.id,tempStatus) - //Il faut changer le UX - //setChantier({...chantier,etat: tempStatus}) - if(isValidChantier()){ - setOpenConfirmation(false); - } - } + async function onConfirm(): Promise { + //TODO + //await changeChantierStatus(chantier.id,tempStatus) + //Il faut changer le UX + //setChantier({...chantier,etat: tempStatus}) + if(isValidChantier()){ + setOpenConfirmation(false); + } + } - function onCancel(): void { - setOpenConfirmation(false); - } + function onCancel(): void { + setOpenConfirmation(false); + } - function isValidChantier(): boolean { - return objet!=="" && duree!=='' && adresse!=='' && contact!=='' && chefChantier!==undefined; //TODO - } + function isValidChantier(): boolean { + return objet!=="" && duree!=='' && adresse!=='' && contact!=='' && chefChantier!==undefined; //TODO + } const renderValidationScreen = () => { return( @@ -165,17 +172,21 @@ export default function AddChantier() { {//renderInut("Date de départ","TOTO : JOUR + Demi journé",date,setDate) } {renderInutDate("Date de départ")} - {renderInut("Estimation de la durée (en demi-journées)","14",duree,setDuree,false)} + {renderInut("Estimation de la durée (en demi-journées)","14",duree,setDuree,true)} {renderInut("Adresse","1 Rue de la Coutellerie, Paris",adresse,setAdresse,false)} {renderInut("Contact client","07 01 02 03 04 05",contact,setContact,true)} - - Engins: - - Chef de chantier: + + Vehicules et machines: + + + + TODO pareil que vehicule mais pour ouvrier: + + diff --git a/app/_layout.tsx b/app/_layout.tsx index 7bd0abb..7945e22 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -16,6 +16,7 @@ import { Platform, UIManager } from 'react-native'; import { ChantierProvider } from "./ContextChantier"; import { UserProvider } from "./ContextUser"; import { RessourcesProvider } from "./ContextRessource"; +import LoginScreen from "./login/login"; export const unstable_settings = { @@ -60,6 +61,7 @@ export default function RootLayout() { + //faut que le login soit ici diff --git a/components/machineSummary.tsx b/components/machineSummary.tsx new file mode 100644 index 0000000..e037def --- /dev/null +++ b/components/machineSummary.tsx @@ -0,0 +1,68 @@ +import { Chantier, Ressources } from '@/class/class'; +import { ThemedView, } from '@/components/theme/themed-view'; +import React, { useState } from 'react'; +import { Image, StyleProp, StyleSheet, View, ViewStyle } from 'react-native'; +import { ThemedText } from './theme/themed-text'; +import { ThemedButton } from './theme/themed-button'; + +type RessourcesQte = [Ressources, number]; + +type Props = { + machine:Ressources; + qte:number; + sendMachine: (machine: RessourcesQte) => void; + style?: StyleProp; +}; + +export default function MachineSummary({machine,qte,style,sendMachine, ...otherProps }: Props) { + + + const [count,setCount] = useState(qte); + + function onPressAdd(machine: Ressources): void { + if(count0){ + setCount(count-1); + sendMachine([machine, count-1]); + } + } + + return( + + + + {machine.id} + {machine.name} + {machine.quantity} + {machine.type} + + + onPressAdd(machine)}> + + + + {count}/{machine.quantity} + onPressSub(machine)}> + - + + + + + ) + } + +const styles = StyleSheet.create({ + button:{ + padding:5, + marginHorizontal:10, + alignItems:"center", + borderRadius: 20, + width: 40, + height: 40, + }, +}); \ No newline at end of file diff --git a/components/selectMachine.tsx b/components/selectMachine.tsx index a328417..58b17d9 100644 --- a/components/selectMachine.tsx +++ b/components/selectMachine.tsx @@ -8,18 +8,21 @@ import { ThemedText } from './theme/themed-text'; import { ThemedView } from "./theme/themed-view"; import { Ressources, User } from '@/class/class'; import { getRessources } from "@/services/ressourcesService"; +import MachineSummary from './machineSummary'; const { width, height } = Dimensions.get("window"); +type RessourcesQte = [Ressources, number]; + type Props = { - sendMachines: (machine: Ressources[]) => void; + sendMachines: (machine: RessourcesQte[]) => void; style?: StyleProp; }; export default function SelectMachine({style,sendMachines: sendMachines , ...otherProps }: Props) { const { chantier, setChantier} = useChantier(); - const [machines, setMachines] = useState([]); + const [machines, setMachines] = useState([]); const [tempStatus, setTempStatus] = useState(""); const [isOpen,setIsOpen] = useState(false); const [openConfirmation,setOpenConfirmation] = useState(false); @@ -38,36 +41,51 @@ export default function SelectMachine({style,sendMachines: sendMachines , ...oth } loadData(); }, []); + + + useEffect(() => { + sendMachines(machines); + }, [machines]) function onPressOpen(): void { setIsOpen(!isOpen); } - function onPressRessource(machine: Ressources): void{ - const exists = machines.some(item => item.name === machine.name); - if(exists){ - setMachines(prev => prev.filter(item => item.name !== machine.name)); - } - else{ - setMachines(prevItem => [...prevItem, machine]); - } - sendMachines(machines); - //setIsOpen(false); + function getTotalMachine(): number{ + var total = 0; + machines.forEach(element => { + total += element[1] + }); + return total; } - const MachineSummary = ({ item }: { item: Ressources }) => { + function addMachine(machine: RessourcesQte): void{ + if(machine[1]>0){ + setMachines(prev => + prev.some(i => i[0].name === machine[0].name) + ? prev.map(i => + i[0].name === machine[0].name + ? [i[0], machine[1]] + : i + ) + : [...prev, machine] + ); + } + else{ + setMachines(prev => prev.filter(item => item[0].name !== machine[0].name)); + } + } + + + + + const MachineSummaryItem = ({ item }: { item: Ressources }) => { if (!item) return null; - const exists = machines.some(i => i.name === item.name); + const machineQte = machines.find(([r]) => r.name === item.name); + const qte = machineQte? machineQte[1]:0; return( - - {onPressRessource(item)}}> - {item.id} - {item.name} - {item.quantity} - {item.type} - - + ) } @@ -81,7 +99,7 @@ export default function SelectMachine({style,sendMachines: sendMachines , ...oth index.toString()} /> @@ -97,7 +115,7 @@ export default function SelectMachine({style,sendMachines: sendMachines , ...oth return( onPressOpen()}> - {machines?machines.length+" machine(s) sélectionné":"sélectionner des machine(s)"} + {machines? getTotalMachine()+" machine(s) sélectionné dont "+ machines.length+" différente":"sélectionner des machine(s)"} {isOpen && MachineSearch()}