-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added update profile and clinic functionalities
- added updateClinicInfos and updateProfileInfos services to profileSlice - added cities.ts file to store cities data - updated navigationStacks paramList - updated ProfileIcon component to display user's profile picture - also make the profileScreen data dynamic
- Loading branch information
Showing
9 changed files
with
179 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const cities = [ | ||
{ name: "ouarzazate", avatar: null }, | ||
{ name: "casablanca", avatar: null }, | ||
{ name: "rabat", avatar: null }, | ||
{ name: "marrakech", avatar: null }, | ||
{ name: "tanger", avatar: null }, | ||
{ name: "fes", avatar: null }, | ||
{ name: "meknes", avatar: null }, | ||
{ name: "agadir", avatar: null }, | ||
{ name: "oujda", avatar: null }, | ||
] | ||
|
||
export default cities |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,42 +4,57 @@ import { SettingsStackNavProps } from "../../../navigation/stacks/settingsStack/ | |
import editClinicStyles from "./editClinicStyles" | ||
import styles from "../../../assets/styles" | ||
import { heightPercentageToDP as hp } from "react-native-responsive-screen" | ||
import { useState } from "react" | ||
import { useAppDispatch, useAppSelector } from "../../../state/hooks" | ||
import { updateClinicInfos } from "../../../services/profileServices" | ||
import cities from "../../../helpers/data/cities" | ||
|
||
const EditClinic = ({ navigation, route }: { navigation: SettingsStackNavProps<"EditClinic">["navigation"]; route: SettingsStackNavProps<"EditClinic">["route"] }): JSX.Element => { | ||
const { clinic } = route.params | ||
|
||
const [clinicData, setClinicData] = useState({ | ||
name: clinic?.name, | ||
email: clinic?.email, | ||
address: clinic?.address, | ||
city: clinic?.city, | ||
phone: clinic?.phone, | ||
fax: clinic?.fax, | ||
}) | ||
|
||
const dispatch = useAppDispatch() | ||
|
||
const { loading, error } = useAppSelector(state => state.profile) | ||
|
||
const handleSave = () => { | ||
dispatch(updateClinicInfos(clinicData)) | ||
|
||
if (error) { | ||
console.log(error) | ||
return | ||
} | ||
|
||
if (loading) { | ||
console.log("loading...") | ||
return | ||
} | ||
|
||
navigation.goBack() | ||
} | ||
|
||
const EditClinic = ({ navigation }: { navigation: SettingsStackNavProps<"EditClinic">["navigation"] }): JSX.Element => { | ||
const cities = [ | ||
{ name: "ouarzazate" }, | ||
{ name: "casablanca" }, | ||
{ name: "rabat" }, | ||
{ name: "marrakech" }, | ||
{ name: "tanger" }, | ||
{ name: "fes" }, | ||
{ name: "meknes" }, | ||
{ name: "agadir" }, | ||
{ name: "oujda" }, | ||
] | ||
return ( | ||
<SafeAreaView> | ||
<NavBar navigation={navigation} /> | ||
<ScrollView nestedScrollEnabled={true} style={styles.appContainer}> | ||
<View style={editClinicStyles.container}> | ||
<Heading text="Cabinet" /> | ||
<View style={editClinicStyles.formContainer}> | ||
<CustomContainer | ||
label="Nom du cabinet" | ||
element={<CustomTextInput placeholder="Cabinet Redouani" />} | ||
/> | ||
<CustomContainer | ||
label="Email du cabinet" | ||
element={<CustomTextInput placeholder="[email protected]" />} | ||
/> | ||
<CustomContainer | ||
label="Adresse du cabinet" | ||
element={<SelectOption data={cities} initialValue="ouarzazate" noImg={true} />} | ||
/> | ||
<CustomContainer label="Ville" element={<CustomTextInput placeholder="Paris" />} /> | ||
<CustomContainer label="Téléphone" element={<CustomTextInput placeholder="06 12 34 56 78" />} /> | ||
<CustomContainer label="Fax" element={<CustomTextInput placeholder="01 23 45 67 89" />} /> | ||
<WideButton text="Enregistrer" /> | ||
<CustomContainer label="Nom du cabinet" element={<CustomTextInput placeholder="Cabinet Redouani" value={clinicData.name} onChangeText={text => setClinicData({ ...clinicData, name: text })} />} /> | ||
<CustomContainer label="Email du cabinet" element={<CustomTextInput placeholder="[email protected]" value={clinicData.email} onChangeText={text => setClinicData({ ...clinicData, email: text })} />} /> | ||
<CustomContainer label="Adresse du cabinet" element={<CustomTextInput placeholder="2 parc des princes" value={clinicData.address} onChangeText={text => setClinicData({ ...clinicData, address: text })} />} /> | ||
<CustomContainer label="Ville" element={<SelectOption data={cities} initialValue={{ name: "ouarzazate", avatar: null }} onSelect={item => setClinicData({ ...clinicData, city: item.name })} />} /> | ||
<CustomContainer label="Téléphone" element={<CustomTextInput placeholder="06 12 34 56 78" value={clinicData.phone} onChangeText={text => setClinicData({ ...clinicData, phone: text })} />} /> | ||
<CustomContainer label="Fax" element={<CustomTextInput placeholder="01 23 45 67 89" value={clinicData.fax} onChangeText={text => setClinicData({ ...clinicData, fax: text })} />} /> | ||
<WideButton text="Enregistrer" onPress={handleSave} /> | ||
</View> | ||
</View> | ||
<View style={{ marginTop: hp("10%") }} /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,63 @@ | ||
import { View, SafeAreaView, ScrollView } from "react-native" | ||
import { View, SafeAreaView, ScrollView, Text } from "react-native" | ||
import { NavBar, Heading, CustomContainer, CustomTextInput, WideButton } from "../../../components" | ||
import { SettingsStackNavProps } from "../../../navigation/stacks/settingsStack/@types" | ||
import editProfileStyles from "./editProfileStyles" | ||
import styles from "../../../assets/styles" | ||
import { widthPercentageToDP as wp, heightPercentageToDP as hp } from "react-native-responsive-screen" | ||
import { useState } from "react" | ||
import { useAppDispatch, useAppSelector } from "../../../state/hooks" | ||
import { updateUserInfos } from "../../../services/profileServices" | ||
|
||
const EditProfile = ({ navigation, route }: { navigation: SettingsStackNavProps<"EditProfile">["navigation"]; route: SettingsStackNavProps<"EditProfile">["route"] }): JSX.Element => { | ||
const { user } = route.params | ||
|
||
const [userData, setUserData] = useState({ | ||
fullName: user?.fullName, | ||
speciality: user?.speciality, | ||
phone: user?.phone, | ||
email: user?.email, | ||
dateOfBirth: user?.dateOfBirth, | ||
inpe: user?.inpe, | ||
}) | ||
|
||
const dispatch = useAppDispatch() | ||
|
||
const { loading, error } = useAppSelector(state => state.profile) | ||
|
||
const handleSave = () => { | ||
dispatch(updateUserInfos(userData)) | ||
|
||
if (error) { | ||
console.log(error) | ||
return | ||
} | ||
|
||
navigation.goBack() | ||
} | ||
|
||
if (loading) | ||
return ( | ||
<View> | ||
<Text>Loading...</Text> | ||
</View> | ||
) | ||
|
||
const EditProfile = ({ | ||
navigation, | ||
}: { | ||
navigation: SettingsStackNavProps<"EditProfile">["navigation"] | ||
}): JSX.Element => { | ||
return ( | ||
<SafeAreaView> | ||
<NavBar navigation={navigation} /> | ||
<ScrollView nestedScrollEnabled={true} style={styles.appContainer}> | ||
<View style={editProfileStyles.container}> | ||
<Heading text="Informations générales" /> | ||
<View style={editProfileStyles.formContainer}> | ||
<CustomContainer | ||
label="Nom du compte" | ||
element={<CustomTextInput placeholder="Khalid Redouani" />} | ||
/> | ||
<CustomContainer | ||
label="Spécialité" | ||
element={<CustomTextInput placeholder="Médecin généraliste" />} | ||
/> | ||
<CustomContainer label="Téléphone" element={<CustomTextInput placeholder="06 12 34 56 78" />} /> | ||
<CustomContainer label="Email" element={<CustomTextInput placeholder="[email protected]" />} /> | ||
<CustomContainer | ||
label="Date de naissance" | ||
element={<CustomTextInput placeholder="01/01/1990" />} | ||
/> | ||
<CustomContainer label="INPE" element={<CustomTextInput placeholder="123456789" />} /> | ||
<WideButton text="Enregistrer" /> | ||
<CustomContainer label="Nom du compte" element={<CustomTextInput placeholder="Khalid Redouani" value={userData.fullName} onChangeText={text => setUserData({ ...userData, fullName: text })} />} /> | ||
<CustomContainer label="Spécialité" element={<CustomTextInput placeholder="Médecin généraliste" value={userData.speciality} onChangeText={text => setUserData({ ...userData, speciality: text })} />} /> | ||
|
||
<CustomContainer label="Téléphone" element={<CustomTextInput placeholder="06 12 34 56 78" value={userData.phone} onChangeText={text => setUserData({ ...userData, phone: text })} />} /> | ||
<CustomContainer label="Email" element={<CustomTextInput placeholder="[email protected]" value={userData.email} onChangeText={text => setUserData({ ...userData, email: text })} />} /> | ||
<CustomContainer label="Date de naissance" element={<CustomTextInput placeholder="01/01/1990" value={userData.dateOfBirth} onChangeText={text => setUserData({ ...userData, dateOfBirth: text })} />} /> | ||
<CustomContainer label="INPE" element={<CustomTextInput placeholder="123456789" value={userData.inpe} onChangeText={text => setUserData({ ...userData, inpe: text })} />} /> | ||
</View> | ||
<WideButton text="Enregistrer" onPress={handleSave} /> | ||
</View> | ||
<View style={{ marginTop: hp("10%") }} /> | ||
</ScrollView> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,45 @@ | ||
import { View, Image, ScrollView, SafeAreaView } from "react-native" | ||
import { NavBar, TextButton, DetailsCard } from "../../../components" | ||
import { View, Image, ScrollView, SafeAreaView, Text } from "react-native" | ||
import { NavBar, TextButton, DetailsCard, ProfileIcon } from "../../../components" | ||
import { SettingsStackNavProps } from "../../../navigation/stacks/settingsStack/@types" | ||
import profileStyles from "./profileStyles" | ||
import styles from "../../../assets/styles" | ||
import { heightPercentageToDP as hp } from "react-native-responsive-screen" | ||
import { useEffect } from "react" | ||
import { useAppDispatch, useAppSelector } from "../../../state/hooks" | ||
import { getUserInfos, getClinicInfos } from "../../../services/profileServices" | ||
import { RootState } from "../../../state/store" | ||
import API_URL from "../../../configs/API_URL" | ||
|
||
const Profile = ({ navigation }: { navigation: SettingsStackNavProps<"Profile">["navigation"] }): JSX.Element => { | ||
const dispatch = useAppDispatch() | ||
|
||
const { user, clinic, loading } = useAppSelector((state: RootState) => state.profile) | ||
|
||
useEffect(() => { | ||
dispatch(getUserInfos()) | ||
dispatch(getClinicInfos()) | ||
}, [dispatch]) | ||
|
||
if (loading) | ||
return ( | ||
<View> | ||
<Text | ||
style={{ | ||
textAlign: "center", | ||
marginTop: hp("10%"), | ||
fontSize: 20, | ||
}}> | ||
Loading... | ||
</Text> | ||
</View> | ||
) | ||
|
||
return ( | ||
<SafeAreaView> | ||
<NavBar navigation={navigation} /> | ||
<ScrollView nestedScrollEnabled={true} style={styles.appContainer}> | ||
<View style={profileStyles.container}> | ||
<Image | ||
source={{ uri: "https://www.w3schools.com/w3images/avatar2.png" }} | ||
style={profileStyles.image} | ||
/> | ||
{user.avatar ? <Image source={{ uri: API_URL + user?.avatar }} style={profileStyles.image} /> : <ProfileIcon firstName={user?.fullName.split(" ")[0] || "No"} lastName={user?.fullName.split(" ")[1] || "Name"} />} | ||
<TextButton text="Changer photo de profile" /> | ||
</View> | ||
{/* General Infos */} | ||
|
@@ -24,30 +49,30 @@ const Profile = ({ navigation }: { navigation: SettingsStackNavProps<"Profile">[ | |
details={[ | ||
{ | ||
title: "Nom du Compte", | ||
value: "Khalid Redouani", | ||
value: user?.fullName, | ||
}, | ||
{ | ||
title: "Spécialité", | ||
value: "Médecin généraliste", | ||
value: user.speciality, | ||
}, | ||
{ | ||
title: "Email", | ||
value: "[email protected]", | ||
value: user.email, | ||
}, | ||
{ | ||
title: "Téléphone", | ||
value: "06 12 34 56 78", | ||
value: user.phone, | ||
}, | ||
{ | ||
title: "Date de naissance", | ||
value: "01 novembre 1990", | ||
value: user.dateOfBirth, | ||
}, | ||
{ | ||
title: "INPE", | ||
value: "EE 123456", | ||
value: user.inpe, | ||
}, | ||
]} | ||
onPress={() => navigation.navigate("EditProfile")} | ||
onPress={() => navigation.navigate("EditProfile", { user })} | ||
/> | ||
{/* Cabinet */} | ||
<DetailsCard | ||
|
@@ -56,30 +81,30 @@ const Profile = ({ navigation }: { navigation: SettingsStackNavProps<"Profile">[ | |
details={[ | ||
{ | ||
title: "Nom", | ||
value: "Cabinet Redouani", | ||
value: clinic?.name, | ||
}, | ||
{ | ||
title: "Email du cabinet", | ||
value: "[email protected]", | ||
value: clinic?.email, | ||
}, | ||
{ | ||
title: "Adresse", | ||
value: "Rue 123, Ville, Pays", | ||
value: clinic?.address, | ||
}, | ||
{ | ||
title: "Ville", | ||
value: "Ville", | ||
value: clinic?.city, | ||
}, | ||
{ | ||
title: "Téléphone", | ||
value: "06 12 34 56 78", | ||
value: clinic?.phone, | ||
}, | ||
{ | ||
title: "Fax", | ||
value: "06 12 34 56 78", | ||
value: clinic?.fax, | ||
}, | ||
]} | ||
onPress={() => navigation.navigate("EditClinic")} | ||
onPress={() => navigation.navigate("EditClinic", { clinic })} | ||
/> | ||
<View style={{ marginTop: hp("10%") }} /> | ||
</ScrollView> | ||
|
Oops, something went wrong.