regex & hit parade
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 302 KiB |
@@ -37,5 +37,5 @@ exports.onProjectUpdate = onDocumentWritten(
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,27 +1,59 @@
|
|||||||
import { View, Text, Pressable } from "react-native";
|
import { useRoute } from "@react-navigation/native";
|
||||||
import React, { useState } from "react";
|
import React, { useMemo, useState } from "react";
|
||||||
|
import { Text, View } from "react-native";
|
||||||
import { useGlobal } from "reactn";
|
import { useGlobal } from "reactn";
|
||||||
import Page from "../layouts/Page";
|
|
||||||
import { background } from "../assets";
|
import { background } from "../assets";
|
||||||
|
import GradientButton from "../components/GradientButton";
|
||||||
|
import { Input } from "../components/Input";
|
||||||
import ItemContainer from "../components/ItemContainer/ItemContainer";
|
import ItemContainer from "../components/ItemContainer/ItemContainer";
|
||||||
|
import firebase, { usersRef } from "../config/firebase";
|
||||||
|
import Page from "../layouts/Page";
|
||||||
|
import { Routes } from "../navigation";
|
||||||
|
import { navigate } from "../navigation/NavigationService";
|
||||||
import { Palette } from "../styles";
|
import { Palette } from "../styles";
|
||||||
import { FONT_FAMILY } from "../styles/Fonts";
|
import { FONT_FAMILY } from "../styles/Fonts";
|
||||||
import { Input } from "../components/Input";
|
|
||||||
import GradientButton from "../components/GradientButton";
|
|
||||||
import { navigate } from "../navigation/NavigationService";
|
|
||||||
import { useRoute } from "@react-navigation/native";
|
|
||||||
import firebase, { usersRef } from "../config/firebase";
|
|
||||||
import { Routes } from "../navigation";
|
|
||||||
|
|
||||||
const CreatePassword = () => {
|
const CreatePassword = () => {
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const email = route?.params?.email || "";
|
const email = route?.params?.email || "";
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
|
const [passwordError, setPasswordError] = useState("");
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [, setTooltip] = useGlobal("_tooltip");
|
const [, setTooltip] = useGlobal("_tooltip");
|
||||||
|
|
||||||
|
const passwordRegex = useMemo(
|
||||||
|
() => /^(?=.*[a-z])(?=.*[A-Z])(?=.*[^A-Za-z0-9]).{8,}$/,
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handlePasswordChange = (text) => {
|
||||||
|
setPassword(text);
|
||||||
|
if (!text) {
|
||||||
|
setPasswordError("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!passwordRegex.test(text)) {
|
||||||
|
setPasswordError(
|
||||||
|
"Ton mot de passe doit contenir 8 caractères, une majuscule, une minuscule et un caractère spécial."
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setPasswordError("");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const isPasswordValid = passwordRegex.test(password);
|
||||||
|
|
||||||
const onCreateAccount = async () => {
|
const onCreateAccount = async () => {
|
||||||
try {
|
try {
|
||||||
|
if (!isPasswordValid) {
|
||||||
|
setTooltip({
|
||||||
|
text: "Ton mot de passe doit contenir 8 caractères, une majuscule, une minuscule et un caractère spécial.",
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const cred = await firebase
|
const cred = await firebase
|
||||||
.auth()
|
.auth()
|
||||||
@@ -34,7 +66,7 @@ const CreatePassword = () => {
|
|||||||
createdAt: firebase.firestore.FieldValue.serverTimestamp(),
|
createdAt: firebase.firestore.FieldValue.serverTimestamp(),
|
||||||
updatedAt: firebase.firestore.FieldValue.serverTimestamp(),
|
updatedAt: firebase.firestore.FieldValue.serverTimestamp(),
|
||||||
},
|
},
|
||||||
{ merge: true },
|
{ merge: true }
|
||||||
);
|
);
|
||||||
setTooltip({ text: "Compte créé, continuons", type: "success" });
|
setTooltip({ text: "Compte créé, continuons", type: "success" });
|
||||||
navigate(Routes.CreatePseudo);
|
navigate(Routes.CreatePseudo);
|
||||||
@@ -82,8 +114,19 @@ const CreatePassword = () => {
|
|||||||
isBlur
|
isBlur
|
||||||
type="password"
|
type="password"
|
||||||
value={password}
|
value={password}
|
||||||
setValue={setPassword}
|
setValue={handlePasswordChange}
|
||||||
/>
|
/>
|
||||||
|
{passwordError ? (
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 12,
|
||||||
|
color: Palette.red,
|
||||||
|
fontFamily: FONT_FAMILY.InterRegular,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{passwordError}
|
||||||
|
</Text>
|
||||||
|
) : null}
|
||||||
</View>
|
</View>
|
||||||
<GradientButton
|
<GradientButton
|
||||||
title={loading ? "Création..." : "Suivant"}
|
title={loading ? "Création..." : "Suivant"}
|
||||||
@@ -92,7 +135,7 @@ const CreatePassword = () => {
|
|||||||
alignSelf: "center",
|
alignSelf: "center",
|
||||||
}}
|
}}
|
||||||
onPress={onCreateAccount}
|
onPress={onCreateAccount}
|
||||||
disabled={loading || !email || !password}
|
disabled={loading || !email || !isPasswordValid}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</ItemContainer>
|
</ItemContainer>
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ const HitParade = () => {
|
|||||||
<SongCard
|
<SongCard
|
||||||
rank={index + 1}
|
rank={index + 1}
|
||||||
title={item?.title || "Sans titre"}
|
title={item?.title || "Sans titre"}
|
||||||
artist={"MusicLand"}
|
artist={item?.userName}
|
||||||
coverUrl={item?.coverUrl || null}
|
coverUrl={item?.coverUrl || null}
|
||||||
onPress={() => navigate(Routes.MusicDetails, { projectId: item.id })}
|
onPress={() => navigate(Routes.MusicDetails, { projectId: item.id })}
|
||||||
/>
|
/>
|
||||||
@@ -92,7 +92,7 @@ const HitParade = () => {
|
|||||||
<PlaybacksCard
|
<PlaybacksCard
|
||||||
rank={index + 1}
|
rank={index + 1}
|
||||||
title={item?.title || "Sans titre"}
|
title={item?.title || "Sans titre"}
|
||||||
artist={"MusicLand"}
|
artist={item?.userName}
|
||||||
coverUrl={item?.coverUrl || null}
|
coverUrl={item?.coverUrl || null}
|
||||||
onPress={() => navigate(Routes.Playbacks, { projectId: item.id })}
|
onPress={() => navigate(Routes.Playbacks, { projectId: item.id })}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user