selection d'un chef de chatier dans addChantier
This commit is contained in:
@@ -10,7 +10,7 @@ import { useChantier } from '../ContextChantier';
|
|||||||
import { useRessources } from '../ContextRessource';
|
import { useRessources } from '../ContextRessource';
|
||||||
import { useUser } from '../ContextUser';
|
import { useUser } from '../ContextUser';
|
||||||
import { getRessources, getUsers, addChantier } from '@/services/ressourcesService';
|
import { getRessources, getUsers, addChantier } from '@/services/ressourcesService';
|
||||||
import { Chantier, Ressources } from '@/class/class';
|
import { Chantier, Ressources, User } from '@/class/class';
|
||||||
import { ThemedText } from '@/components/theme/themed-text';
|
import { ThemedText } from '@/components/theme/themed-text';
|
||||||
import { ThemedButton } from '@/components/theme/themed-button';
|
import { ThemedButton } from '@/components/theme/themed-button';
|
||||||
import { ThemedTextInput } from '@/components/theme/themed-textinput';
|
import { ThemedTextInput } from '@/components/theme/themed-textinput';
|
||||||
@@ -32,7 +32,7 @@ export default function AddChantier() {
|
|||||||
const [objet, setObjet] = useState('');
|
const [objet, setObjet] = useState('');
|
||||||
const [date, setDate] = useState(new Date());
|
const [date, setDate] = useState(new Date());
|
||||||
const [morning, setMorning] = useState(true);
|
const [morning, setMorning] = useState(true);
|
||||||
const [chefChantier, setChefChantier] = useState('');
|
const [chefChantier, setChefChantier] = useState<User>();
|
||||||
const [adresse, setAdresse] = useState('');
|
const [adresse, setAdresse] = useState('');
|
||||||
const [duree, setDuree] = useState('');
|
const [duree, setDuree] = useState('');
|
||||||
const [contact, setContact] = useState('');
|
const [contact, setContact] = useState('');
|
||||||
@@ -72,7 +72,7 @@ export default function AddChantier() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isValidChantier(): boolean {
|
function isValidChantier(): boolean {
|
||||||
return objet!=="" && duree!=='' && adresse!=='' && contact!=='' && chefChantier!==''; //TODO
|
return objet!=="" && duree!=='' && adresse!=='' && contact!=='' && chefChantier!==undefined; //TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
const renderValidationScreen = () => {
|
const renderValidationScreen = () => {
|
||||||
@@ -87,7 +87,7 @@ export default function AddChantier() {
|
|||||||
<ThemedText style={{fontSize: 20}}>Durée: {duree===''?"0":duree} demi-journées</ThemedText>
|
<ThemedText style={{fontSize: 20}}>Durée: {duree===''?"0":duree} demi-journées</ThemedText>
|
||||||
<ThemedText style={{fontSize: 20}}>Adresse: {adresse===''?"NONE":adresse}</ThemedText>
|
<ThemedText style={{fontSize: 20}}>Adresse: {adresse===''?"NONE":adresse}</ThemedText>
|
||||||
<ThemedText style={{fontSize: 20}}>Contact client: {contact===''?"NONE":contact}</ThemedText>
|
<ThemedText style={{fontSize: 20}}>Contact client: {contact===''?"NONE":contact}</ThemedText>
|
||||||
<ThemedText style={{fontSize: 20}}>Chef de chantier: {chefChantier===''?"NONE":chefChantier}</ThemedText>
|
<ThemedText style={{fontSize: 20}}>Chef de chantier: {chefChantier===undefined?"NONE":chefChantier.name}</ThemedText>
|
||||||
|
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
<View style={styles.overlayView}>
|
<View style={styles.overlayView}>
|
||||||
@@ -169,7 +169,7 @@ export default function AddChantier() {
|
|||||||
{renderInut("Vehicule","TODO Ouvrir un menu",vehicule,setVehicule,false)}
|
{renderInut("Vehicule","TODO Ouvrir un menu",vehicule,setVehicule,false)}
|
||||||
<View style = {styles.inputLine}>
|
<View style = {styles.inputLine}>
|
||||||
<ThemedText style = {styles.inputName}>Chef de chantier:</ThemedText>
|
<ThemedText style = {styles.inputName}>Chef de chantier:</ThemedText>
|
||||||
<SelectChafChantier style = {styles.input}/>
|
<SelectChafChantier style = {styles.input} sendChefChantier={setChefChantier}/>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +1,67 @@
|
|||||||
import { useChantier } from '@/app/ContextChantier';
|
import { useChantier } from '@/app/ContextChantier';
|
||||||
import { changeChantierStatus } from "@/services/ressourcesService";
|
import { changeChantierStatus } from "@/services/ressourcesService";
|
||||||
import { useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Dimensions, LayoutAnimation, Modal, Pressable, StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
|
import { Dimensions, FlatList, LayoutAnimation, Modal, Pressable, ScrollView, StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
|
||||||
import Animated, { LinearTransition } from 'react-native-reanimated';
|
import Animated, { LinearTransition } from 'react-native-reanimated';
|
||||||
import { ThemedButton } from './theme/themed-button';
|
import { ThemedButton } from './theme/themed-button';
|
||||||
import { ThemedText } from './theme/themed-text';
|
import { ThemedText } from './theme/themed-text';
|
||||||
import { ThemedView } from "./theme/themed-view";
|
import { ThemedView } from "./theme/themed-view";
|
||||||
import { User } from '@/class/class';
|
import { User } from '@/class/class';
|
||||||
|
import { getUsers } from "@/services/ressourcesService";
|
||||||
|
|
||||||
const { width, height } = Dimensions.get("window");
|
const { width, height } = Dimensions.get("window");
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
sendChefChantier: (user: User) => void;
|
||||||
style?: StyleProp<ViewStyle>;
|
style?: StyleProp<ViewStyle>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function SelectChafChantier({style , ...otherProps }: Props) {
|
export default function SelectChafChantier({style,sendChefChantier , ...otherProps }: Props) {
|
||||||
|
|
||||||
const { chantier, setChantier} = useChantier();
|
const { chantier, setChantier} = useChantier();
|
||||||
const [chefDeChantier, setChefDeChantier] = useState<User>();
|
const [chefDeChantier, setChefDeChantier] = useState<User>();
|
||||||
const [tempStatus, setTempStatus] = useState("");
|
const [tempStatus, setTempStatus] = useState("");
|
||||||
const [isOpen,setIsOpen] = useState(false);
|
const [isOpen,setIsOpen] = useState(false);
|
||||||
const [openConfirmation,setOpenConfirmation] = useState(false);
|
const [openConfirmation,setOpenConfirmation] = useState(false);
|
||||||
|
const [users,setUsers] = useState<User[]>([]);
|
||||||
|
|
||||||
const AnimatedThemedView = Animated.createAnimatedComponent(ThemedView);
|
const AnimatedThemedView = Animated.createAnimatedComponent(ThemedView);
|
||||||
|
|
||||||
const choices = ["En cours","Interrompu","Terminé","Non réalisé"]
|
useEffect(() => {
|
||||||
|
async function loadData() {
|
||||||
|
try {
|
||||||
|
const data = await getUsers();//TODO chef de chantier uniquement
|
||||||
|
setUsers(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erreur lors du chargement :", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
function onPressOpen(): void {
|
function onPressOpen(): void {
|
||||||
setIsOpen(!isOpen);
|
setIsOpen(!isOpen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onPressUser(user: User): void{
|
||||||
|
sendChefChantier(user);
|
||||||
|
setChefDeChantier(user);
|
||||||
|
setIsOpen(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const chefChantierSummary = ({ item }: { item: User }) => {
|
||||||
|
if (!item) return null;
|
||||||
|
return(
|
||||||
|
<View style={{padding:10,width:"100%"}}>
|
||||||
|
<ThemedButton lvl={2} style={{padding:10,width:"100%",borderRadius:10}} onPress={() => {onPressUser(item)}}>
|
||||||
|
<ThemedText>{item.name}</ThemedText>
|
||||||
|
<ThemedText>{item.last_name}</ThemedText>
|
||||||
|
<ThemedText>{item.role}</ThemedText>
|
||||||
|
</ThemedButton>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const chefChantierSearch = () => {
|
const chefChantierSearch = () => {
|
||||||
@@ -40,12 +70,17 @@ export default function SelectChafChantier({style , ...otherProps }: Props) {
|
|||||||
<View style={styles.overlay}>
|
<View style={styles.overlay}>
|
||||||
<ThemedView style={styles.overlayView}>
|
<ThemedView style={styles.overlayView}>
|
||||||
<ThemedText style={{fontSize: 25}}>Rechercher un chef de chantier :</ThemedText>
|
<ThemedText style={{fontSize: 25}}>Rechercher un chef de chantier :</ThemedText>
|
||||||
|
<FlatList
|
||||||
|
style={{width:"100%"}}
|
||||||
|
data={users}
|
||||||
|
renderItem={chefChantierSummary}
|
||||||
|
keyExtractor={(_, index) => index.toString()}
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
<View style={styles.overlayView}>
|
|
||||||
<ThemedButton lvl={2} border={5} style={styles.buttonValid} onPress={() => setIsOpen(false)}>
|
<ThemedButton lvl={2} border={5} style={styles.buttonValid} onPress={() => setIsOpen(false)}>
|
||||||
<ThemedText style={{fontSize: 25}}>Annuler</ThemedText>
|
<ThemedText style={{fontSize: 25}}>Annuler</ThemedText>
|
||||||
</ThemedButton>
|
</ThemedButton>
|
||||||
</View>
|
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
</View>
|
</View>
|
||||||
</Modal>
|
</Modal>
|
||||||
@@ -110,6 +145,7 @@ const styles = StyleSheet.create({
|
|||||||
padding: 20,
|
padding: 20,
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
//backgroundColor:'#ff0000',
|
//backgroundColor:'#ff0000',
|
||||||
},
|
},
|
||||||
buttonValid:{
|
buttonValid:{
|
||||||
|
|||||||
Reference in New Issue
Block a user