addChantier / selectMachine / machineSummary : presque fini
This commit is contained in:
@@ -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<Ressources[]>(); //de type enfin /!\
|
||||
const [materiels, setMateriels] = useState<Ressources>(); //de type material (outils) /!\
|
||||
const [machine, setMachines] = useState<RessourcesQte[]>(); //de type enfin /!\
|
||||
const [materiels, setMateriels] = useState<RessourcesQte[][]>(); //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<string[]>([]);
|
||||
const [ressourcesSelect, setRessourcesSelect] = useState<string[]>([]);
|
||||
|
||||
|
||||
|
||||
|
||||
async function handleAddChantier() {
|
||||
setLoading(true);
|
||||
setOpenConfirmation(true);
|
||||
@@ -59,23 +66,23 @@ export default function AddChantier() {
|
||||
}
|
||||
};
|
||||
|
||||
async function onConfirm(): Promise<void> {
|
||||
//TODO
|
||||
//await changeChantierStatus(chantier.id,tempStatus)
|
||||
//Il faut changer le UX
|
||||
//setChantier({...chantier,etat: tempStatus})
|
||||
if(isValidChantier()){
|
||||
setOpenConfirmation(false);
|
||||
}
|
||||
}
|
||||
async function onConfirm(): Promise<void> {
|
||||
//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)}
|
||||
<View style = {styles.inputLine}>
|
||||
<ThemedText style = {styles.inputName}>Engins:</ThemedText>
|
||||
<SelectMachine style = {styles.input} sendMachines={setEngins}/>
|
||||
</View>
|
||||
<View style = {styles.inputLine}>
|
||||
<ThemedText style = {styles.inputName}>Chef de chantier:</ThemedText>
|
||||
<SelectChafChantier style = {styles.input} sendChefChantier={setChefChantier}/>
|
||||
</View>
|
||||
<View style = {styles.inputLine}>
|
||||
<ThemedText style = {styles.inputName}>Vehicules et machines:</ThemedText>
|
||||
<SelectMachine style = {styles.input} sendMachines={setMachines}/>
|
||||
</View>
|
||||
<View style = {styles.inputLine}>
|
||||
<ThemedText style = {styles.inputName}>TODO pareil que vehicule mais pour ouvrier:</ThemedText>
|
||||
<SelectMachine style = {styles.input} sendMachines={setMachines}/>
|
||||
</View>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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() {
|
||||
<ChantierProvider>
|
||||
<RessourcesProvider>
|
||||
<ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
|
||||
//faut que le login soit ici
|
||||
<Stack>
|
||||
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
||||
<Stack.Screen name="selectChantier" options={{ headerShown: false }}/>
|
||||
|
||||
68
components/machineSummary.tsx
Normal file
68
components/machineSummary.tsx
Normal file
@@ -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<ViewStyle>;
|
||||
};
|
||||
|
||||
export default function MachineSummary({machine,qte,style,sendMachine, ...otherProps }: Props) {
|
||||
|
||||
|
||||
const [count,setCount] = useState(qte);
|
||||
|
||||
function onPressAdd(machine: Ressources): void {
|
||||
if(count<machine.quantity){
|
||||
setCount(count+1);
|
||||
sendMachine([machine, count+1]);
|
||||
}
|
||||
}
|
||||
|
||||
function onPressSub(machine: Ressources): void {
|
||||
if(count>0){
|
||||
setCount(count-1);
|
||||
sendMachine([machine, count-1]);
|
||||
}
|
||||
}
|
||||
|
||||
return(
|
||||
<View style={style}>
|
||||
<ThemedView lvl={2} border={3} style={{padding:10,width:"100%",borderRadius:10,flexDirection: 'row',justifyContent: 'space-between',}}>
|
||||
<View>
|
||||
<ThemedText>{machine.id}</ThemedText>
|
||||
<ThemedText>{machine.name}</ThemedText>
|
||||
<ThemedText>{machine.quantity}</ThemedText>
|
||||
<ThemedText>{machine.type}</ThemedText>
|
||||
</View>
|
||||
<View style={{alignItems:"center"}}>
|
||||
<ThemedButton style={styles.button} lvl={3} onPress={() => onPressAdd(machine)}>
|
||||
<ThemedText>+</ThemedText>
|
||||
</ThemedButton>
|
||||
<ThemedText>{count}/{machine.quantity}</ThemedText>
|
||||
<ThemedButton style={styles.button} lvl={3} onPress={() => onPressSub(machine)}>
|
||||
<ThemedText>-</ThemedText>
|
||||
</ThemedButton>
|
||||
</View>
|
||||
</ThemedView>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
button:{
|
||||
padding:5,
|
||||
marginHorizontal:10,
|
||||
alignItems:"center",
|
||||
borderRadius: 20,
|
||||
width: 40,
|
||||
height: 40,
|
||||
},
|
||||
});
|
||||
@@ -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<ViewStyle>;
|
||||
};
|
||||
|
||||
export default function SelectMachine({style,sendMachines: sendMachines , ...otherProps }: Props) {
|
||||
|
||||
const { chantier, setChantier} = useChantier();
|
||||
const [machines, setMachines] = useState<Ressources[]>([]);
|
||||
const [machines, setMachines] = useState<RessourcesQte[]>([]);
|
||||
const [tempStatus, setTempStatus] = useState("");
|
||||
const [isOpen,setIsOpen] = useState(false);
|
||||
const [openConfirmation,setOpenConfirmation] = useState(false);
|
||||
@@ -40,34 +43,49 @@ export default function SelectMachine({style,sendMachines: sendMachines , ...oth
|
||||
}, []);
|
||||
|
||||
|
||||
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(
|
||||
<View style={{padding:10,width:"100%"}}>
|
||||
<ThemedButton lvl={exists?2:0} border={exists?3:0} style={{padding:10,width:"100%",borderRadius:10}} onPress={() => {onPressRessource(item)}}>
|
||||
<ThemedText>{item.id}</ThemedText>
|
||||
<ThemedText>{item.name}</ThemedText>
|
||||
<ThemedText>{item.quantity}</ThemedText>
|
||||
<ThemedText>{item.type}</ThemedText>
|
||||
</ThemedButton>
|
||||
</View>
|
||||
<MachineSummary style={{padding:10,width:"100%"}} machine={item} qte={qte} sendMachine={addMachine}></MachineSummary>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -81,7 +99,7 @@ export default function SelectMachine({style,sendMachines: sendMachines , ...oth
|
||||
<FlatList
|
||||
style={{width:"100%"}}
|
||||
data={listMachines}
|
||||
renderItem={MachineSummary}
|
||||
renderItem={MachineSummaryItem}
|
||||
keyExtractor={(_, index) => index.toString()}
|
||||
/>
|
||||
|
||||
@@ -97,7 +115,7 @@ export default function SelectMachine({style,sendMachines: sendMachines , ...oth
|
||||
|
||||
return(
|
||||
<ThemedButton style={style} lvl={1} onPress={() => onPressOpen()}>
|
||||
<ThemedText style={styles.centeredText}>{machines?machines.length+" machine(s) sélectionné":"sélectionner des machine(s)"}</ThemedText>
|
||||
<ThemedText style={styles.centeredText}>{machines? getTotalMachine()+" machine(s) sélectionné dont "+ machines.length+" différente":"sélectionner des machine(s)"}</ThemedText>
|
||||
{isOpen && MachineSearch()}
|
||||
</ThemedButton>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user