continue generating flow, add backend connection on main tabs
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { View, Text, Pressable } from "react-native";
|
||||
import React from "react";
|
||||
import React, { useState } from "react";
|
||||
import { useGlobal } from "reactn";
|
||||
import Page from "../layouts/Page";
|
||||
import { background } from "../assets";
|
||||
import ItemContainer from "../components/ItemContainer/ItemContainer";
|
||||
@@ -8,9 +9,43 @@ 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 route = useRoute();
|
||||
const email = route?.params?.email || "";
|
||||
const [password, setPassword] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [, setTooltip] = useGlobal("_tooltip");
|
||||
|
||||
const onCreateAccount = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const cred = await firebase
|
||||
.auth()
|
||||
.createUserWithEmailAndPassword(email.trim(), password);
|
||||
const uid = cred?.user?.uid || firebase.auth().currentUser?.uid;
|
||||
if (!uid) throw new Error("Création de compte échouée");
|
||||
await usersRef.doc(uid).set(
|
||||
{
|
||||
email: email.trim(),
|
||||
createdAt: firebase.firestore.FieldValue.serverTimestamp(),
|
||||
updatedAt: firebase.firestore.FieldValue.serverTimestamp(),
|
||||
},
|
||||
{ merge: true },
|
||||
);
|
||||
setTooltip({ text: "Compte créé, continuons", type: "success" });
|
||||
navigate(Routes.CreatePseudo);
|
||||
} catch (e) {
|
||||
console.log("Register error", e?.message);
|
||||
setTooltip({ text: e?.message || "Création impossible", type: "error" });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Page
|
||||
backgroundImg={background.homeBG}
|
||||
@@ -46,15 +81,18 @@ const CreatePassword = () => {
|
||||
label="Mot de passe"
|
||||
isBlur
|
||||
type="password"
|
||||
value={password}
|
||||
setValue={setPassword}
|
||||
/>
|
||||
</View>
|
||||
<GradientButton
|
||||
title="Suivant"
|
||||
title={loading ? "Création..." : "Suivant"}
|
||||
containerStyle={{
|
||||
width: "80%",
|
||||
alignSelf: "center",
|
||||
}}
|
||||
onPress={() => navigate(Routes.CreateName)}
|
||||
onPress={onCreateAccount}
|
||||
disabled={loading || !email || !password}
|
||||
/>
|
||||
</View>
|
||||
</ItemContainer>
|
||||
|
||||
Reference in New Issue
Block a user