Skip to content

Commit

Permalink
fix: add last front parts
Browse files Browse the repository at this point in the history
  • Loading branch information
YoanRos committed Sep 5, 2024
1 parent 90ea53f commit a5ee246
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 50 deletions.
2 changes: 1 addition & 1 deletion api/src/controllers/consommation.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ router.post(
catchErrors(async (req, res) => {
const matomoId = req.body?.matomoId;
if (!matomoId) return res.status(400).json({ ok: false, error: "no matomo id" });

console.log("syncing consos", matomoId);
const { drinks, drinksCatalog } = req.body;

if (!drinks.length) {
Expand Down
11 changes: 7 additions & 4 deletions expo/src/scenes/Infos/AccountInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ const AccountInfo = ({ navigation }) => {
/>
<View className="flex items-center">
<TouchableOpacity
// onPress={signup}
onPress={() => navigation.navigate("ROUTER", { screen: "ChangeAccountModal" })}
onPress={() => {
navigation.navigate("CHANGE_PASSWORD");
}}
className={`mt-2 rounded-full px-6 py-2 ${isButtonDisabled ? "bg-[#EA6C96]" : "bg-[#de285e]"}`}
// disabled={isButtonDisabled}
>
<Text className="text-center text-white text-lg font-bold">Modifier mon email</Text>
</TouchableOpacity>
</View>
<Text className=" text-black text-lg font-bold">Mot de passe</Text>
<Text className="text-sm text-black">
Pour modifier votre mot de passe, <Text className="text-[#4030a5] underline font-bold">cliquez ici</Text>
Pour modifier votre mot de passe,
<TouchableOpacity onPress={() => navigation.navigate("CHANGE_PASSWORD")}>
<Text className="text-[#4030a5] underline font-bold"> cliquez ici</Text>
</TouchableOpacity>
</Text>
</View>
</View>
Expand Down
2 changes: 2 additions & 0 deletions expo/src/scenes/Infos/AccountMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import AccountGearIcon from "../../components/illustrations/icons/AccountGearIco
import AccountInfo from "./AccountInfo";
import Support from "./Support";
import DeleteAccount from "./DeleteAccount";
import ChangePassword from "./ChangePassword";

const AccountStack = createStackNavigator();

Expand All @@ -27,6 +28,7 @@ const Account = () => {
<AccountStack.Screen name="SUPPORT" component={Support} />
<AccountStack.Screen name="TRANSFER" component={Transfer} />
<AccountStack.Screen name="DELETE" component={DeleteAccount} />
<AccountStack.Screen name="CHANGE_PASSWORD" component={ChangePassword} />
</AccountStack.Navigator>
</Background>
);
Expand Down
97 changes: 53 additions & 44 deletions expo/src/scenes/Infos/ChangeAccountModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { SafeAreaView } from "react-native-safe-area-context";
import MaterialCommunityIcons from "@expo/vector-icons/MaterialCommunityIcons";

const ChangeAccountModal = ({ navigation, route }) => {
const isChangeEmail = route?.params?.from === "changeEmail";

const [password, setPassword] = useState("");
const [hidePassword, setHidePassword] = useState(true);
const [isButtonDisabled, setIsButtonDisabled] = useState(true);
Expand All @@ -16,58 +18,65 @@ const ChangeAccountModal = ({ navigation, route }) => {

return (
<SafeAreaView className="flex flex-grow justify-center items-center">
<View className="bg-white rounded-xl max-w-[90%]">
<View className="flex flex-row justify-center mt-4 mb-2 mx-4">
<View className="h-5 flex flex-row justify-end">
<TouchableOpacity
hitSlop={hitSlop(15)}
onPress={() => {
navigation.navigate("CRAVING", { screen: "CRAVING_STRATEGIES" });
}}
>
<Svg fill="none" viewBox="0 0 24 24" className="h-5 w-5">
<Path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={3}
stroke="black"
d="M6 18L18 6M6 6l12 12"
/>
</Svg>
</TouchableOpacity>
</View>
<View className="flex w-full px-2 my-8 items-center">
<Text className="text-start text-xl px-2 font-extrabold text-[#4030A5] ">Modifier l'e-mail</Text>
<Text className=" text-center px-2 font-semibold">
Afin de confirmer la modification de l’adresse e-mail du compte, veuillez saisir votre mot de passe
ci-dessous.
</Text>
<Text className=" text-white text-lg font-semibold mb-2">Mot de passe</Text>
<View className="bg-white rounded-md p-3 mb-4 flex flex-row items-center">
<TextInput
placeholder="Mot de passe"
value={password}
onChangeText={setPassword}
secureTextEntry={hidePassword}
className="flex-1"
<View className="bg-white rounded-xl max-w-[90%] p-5">
<View className="h-5 flex flex-row justify-end">
<TouchableOpacity
hitSlop={hitSlop(15)}
onPress={() => {
navigation.navigate("CRAVING", { screen: "CRAVING_STRATEGIES" });
}}
>
<Svg fill="none" viewBox="0 0 24 24" className="h-5 w-5">
<Path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={3}
stroke="black"
d="M6 18L18 6M6 6l12 12"
/>
<TouchableOpacity className="absolute right-2" onPress={() => setHidePassword(!hidePassword)}>
{hidePassword ? (
<MaterialCommunityIcons name="eye-outline" size={24} color="#3E309F" />
) : (
<MaterialCommunityIcons name="eye-off-outline" size={24} color="#3E309F" />
)}
</TouchableOpacity>
</Svg>
</TouchableOpacity>
</View>
<View className="flex flex-col justify-center">
<View className="flex w-full items-start space-y-4 flex-col">
<Text className="text-start text-xl font-extrabold text-[#4030A5] ">
{isChangeEmail ? "Modifier l'e-mail" : "Supprimer mon compte"}
</Text>
<Text className=" text-start ">
{isChangeEmail
? "Afin de confirmer la modification de l’adresse e-mail du compte, veuillez saisir votre mot de passe ci-dessous."
: "Afin de confirmer la suppression de votre compte, veuillez saisir votre mot de passe ci-dessous."}
</Text>
<View className="flex flex-col items-start">
<Text className=" text-black text-lg font-semibold mb-2">Mot de passe</Text>
<View className="bg-white rounded-md p-3 mb-4 flex flex-row items-center border border-gray-300">
<TextInput
placeholder="Mot de passe"
value={password}
onChangeText={setPassword}
secureTextEntry={hidePassword}
className="flex-1"
/>
<TouchableOpacity className="absolute right-2" onPress={() => setHidePassword(!hidePassword)}>
{hidePassword ? (
<MaterialCommunityIcons name="eye-outline" size={24} color="#3E309F" />
) : (
<MaterialCommunityIcons name="eye-off-outline" size={24} color="#3E309F" />
)}
</TouchableOpacity>
</View>
</View>
</View>
<View className="flex mt-10 items-center">
<View className="flex mt-6 items-center">
<TouchableOpacity
className={`rounded-full px-6 py-3 ${isButtonDisabled ? "bg-[#EA6C96]" : "bg-[#de285e]"}`}
className={`rounded-full px-5 py-2 ${isButtonDisabled ? "bg-[#EA6C96]" : "bg-[#de285e]"}`}
onPress={() => {
navigation.goBack();
}}
>
<Text className="text-center text-white text-xl font-bold">Valider</Text>
<Text className="text-center text-white text-xl font-bold">
{isChangeEmail ? "Valider" : "Confirmer la suppression"}
</Text>
</TouchableOpacity>
</View>
</View>
Expand Down
159 changes: 159 additions & 0 deletions expo/src/scenes/Infos/ChangePassword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import React, { useEffect, useState } from "react";
import { View, TextInput, TouchableOpacity, Text, SafeAreaView, KeyboardAvoidingView, Platform } from "react-native";
import AntDesign from "@expo/vector-icons/AntDesign";
import Entypo from "@expo/vector-icons/Entypo";
import MaterialCommunityIcons from "@expo/vector-icons/MaterialCommunityIcons";
import BackButton from "../../components/BackButton";

const ChangePassword = ({ navigation }) => {
const [formerPassword, setFormerPassword] = useState("");
const [password, setPassword] = useState("");
const [confirmPassword, setConfirmPassword] = useState("");
const [isDifferent, setIsDifferent] = useState(false);
const [isStrongPassword, setIsStrongPassword] = useState(false);
const [isMatching, setIsMatching] = useState(false);
const [isButtonDisabled, setIsButtonDisabled] = useState(true);
const [hidePassword, setHidePassword] = useState(true);
const [passwordChecks, setPasswordChecks] = useState({
minLength: false,
hasUpperCase: false,
hasLowerCase: false,
hasNumber: false,
hasSpecialChar: false,
});

const checkPassword = (password) => {
const checks = {
minLength: password.length >= 12,
hasUpperCase: /[A-Z]/.test(password),
hasLowerCase: /[a-z]/.test(password),
hasNumber: /[0-9]/.test(password),
hasSpecialChar: /[!@#\$%\^&\*]/.test(password),
};
setPasswordChecks(checks);
setIsStrongPassword(Object.values(checks).every((check) => check));
setIsMatching(password === confirmPassword);
setIsDifferent(password !== formerPassword);
};

const handleConfirmPasswordChange = (text) => {
setConfirmPassword(text);
setIsMatching(password === text);
};

useEffect(() => {
if (isStrongPassword && isMatching && isDifferent) {
setIsButtonDisabled(false);
} else {
setIsButtonDisabled(true);
}
}, [isStrongPassword, isMatching, isDifferent]);

const numberOfChecksPassed = Object.values(passwordChecks).filter(Boolean).length;

return (
<SafeAreaView className=" w-full h-full px-5">
<KeyboardAvoidingView enabled behavior={Platform.select({ ios: "padding", android: null })}>
<BackButton onPress={navigation.goBack} marginTop marginLeft marginBottom />

<View className="flex px-8 space-y-8 ">
<Text className="text-start text-[#4030A5] text-2xl font-bold">Modifier le mot de passe</Text>
<Text className="text-black text-sm">
Veuillez saisir votre mot de passe actuel, ainsi que votre nouveau mot de passe.
</Text>
<View className="flex space-y-3">
<Text className=" text-black text-lg font-bold">Mot de passe actuel</Text>
<View className="bg-white rounded-md p-3 flex flex-row items-center">
<TextInput
placeholder="Renseignez votre mot de passe actuel"
value={formerPassword}
onChangeText={setFormerPassword}
secureTextEntry={hidePassword}
className="text-black flex-1"
/>
</View>
</View>

<View className="flex space-y-3">
<Text className=" text-black text-lg font-bold">Mot de passe</Text>
<Text className="text-black text-sm">
doit contenir au minimum 12 caractères, 1 Majuscule, 1 chiffre, 1 caractère spécial
</Text>
<View className="bg-white rounded-md p-3 flex flex-row items-center">
<TextInput
placeholder="Renseignez le même mot de passe"
value={password}
onChangeText={(text) => {
setPassword(text);
checkPassword(text);
}}
secureTextEntry={hidePassword}
className="text-black flex-1"
/>
<TouchableOpacity className="" onPress={() => setHidePassword(!hidePassword)}>
{hidePassword ? (
<MaterialCommunityIcons name="eye-outline" size={24} color="#3E309F" />
) : (
<MaterialCommunityIcons name="eye-off-outline" size={24} color="#3E309F" />
)}
</TouchableOpacity>
</View>
<View className="flex flex-row justify-between mt-2">
{[...Array(5)].map((_, index) => (
<View
key={index}
className={`h-1 flex-1 mx-0.5 rounded-xl ${
index < numberOfChecksPassed ? "bg-green-500" : "bg-gray-300"
}`}
/>
))}
</View>
</View>
<View className="flex space-y-3">
<Text className=" text-black text-xl font-bold mb-1">Confirmation du mot de passe</Text>
<View className="bg-white rounded-md p-3 flex flex-row items-center">
<TextInput
placeholder="Renseignez le même mot de passe"
value={confirmPassword}
onChangeText={handleConfirmPasswordChange}
secureTextEntry={hidePassword}
className="text-black flex-1"
/>
<TouchableOpacity className="" onPress={() => setHidePassword(!hidePassword)}>
{hidePassword ? (
<MaterialCommunityIcons name="eye-outline" size={24} color="#3E309F" />
) : (
<MaterialCommunityIcons name="eye-off-outline" size={24} color="#3E309F" />
)}
</TouchableOpacity>
</View>
{confirmPassword && (
<View className="flex items-center flex-row justify-end space-x-1">
{isMatching ? (
<AntDesign name="checkcircleo" size={15} color="#39CEC1" />
) : (
<Entypo name="circle-with-cross" size={15} color="#FF0000" />
)}
<Text className="text-black text-sm">
{isMatching ? "Mots de passe similaires" : "Mots de passe différents"}
</Text>
</View>
)}
</View>
</View>
<View className="flex mt-10 items-center">
<TouchableOpacity
// onPress={signup}
onPress={() => navigation.push("TABS")}
className={`rounded-full px-6 py-3 ${isButtonDisabled ? "bg-[#EA6C96]" : "bg-[#de285e]"}`}
// disabled={isButtonDisabled}
>
<Text className="text-center text-white text-xl font-bold">Valider</Text>
</TouchableOpacity>
</View>
</KeyboardAvoidingView>
</SafeAreaView>
);
};

export default ChangePassword;
4 changes: 3 additions & 1 deletion expo/src/scenes/Infos/DeleteAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const DeleteAccount = ({ navigation }) => {
</Text>
<View className="flex items-center">
<TouchableOpacity
// onPress={() => }
onPress={() => {
navigation.navigate("CHANGE_ACCOUNT");
}}
className=" rounded-full px-6 py-2 bg-[#de285e] mt-8"
>
<Text className="text-center text-white text-lg font-bold">Supprimer mon Compte</Text>
Expand Down

0 comments on commit a5ee246

Please sign in to comment.