mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 07:07:16 +00:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
@ -70,9 +70,9 @@ if (Platform.OS === 'ios') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
// functions().useEmulator("localhost", 5001);
|
functions().useEmulator("localhost", 5001);
|
||||||
// firestore().useEmulator("localhost", 5471);
|
firestore().useEmulator("localhost", 5471);
|
||||||
// auth().useEmulator("http://localhost:9099");
|
auth().useEmulator("http://localhost:9099");
|
||||||
}
|
}
|
||||||
|
|
||||||
type TextStyleBase =
|
type TextStyleBase =
|
||||||
|
@ -1,30 +1,49 @@
|
|||||||
import {useMutation} from "@tanstack/react-query";
|
import {useMutation} from "@tanstack/react-query";
|
||||||
import auth from "@react-native-firebase/auth";
|
import auth from "@react-native-firebase/auth";
|
||||||
|
import firestore from "@react-native-firebase/firestore";
|
||||||
import {ProfileType, useAuthContext} from "@/contexts/AuthContext";
|
import {ProfileType, useAuthContext} from "@/contexts/AuthContext";
|
||||||
import {useSetUserData} from "./useSetUserData";
|
import {useSetUserData} from "./useSetUserData";
|
||||||
import {uuidv4} from "@firebase/util";
|
import {uuidv4} from "@firebase/util";
|
||||||
import * as Localization from "expo-localization";
|
import * as Localization from "expo-localization";
|
||||||
|
|
||||||
export const useSignUp = () => {
|
export const useSignUp = () => {
|
||||||
const {setRedirectOverride} = useAuthContext()
|
const {setRedirectOverride} = useAuthContext();
|
||||||
const {mutateAsync: setUserData} = useSetUserData();
|
const {mutateAsync: setUserData} = useSetUserData();
|
||||||
|
|
||||||
|
const createHouseholdIfNeeded = async (familyId: string, lastName: string) => {
|
||||||
|
try {
|
||||||
|
const householdRef = firestore().collection("Households");
|
||||||
|
const snapshot = await householdRef.where("familyId", "==", familyId).get();
|
||||||
|
|
||||||
|
if (snapshot.empty) {
|
||||||
|
await householdRef.add({
|
||||||
|
familyId,
|
||||||
|
name: lastName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error creating household:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationKey: ["signUp"],
|
mutationKey: ["signUp"],
|
||||||
mutationFn: async ({
|
mutationFn: async ({
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
firstName,
|
firstName,
|
||||||
lastName,
|
lastName,
|
||||||
birthday
|
birthday
|
||||||
}: {
|
}: {
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
lastName: string;
|
lastName: string;
|
||||||
birthday: Date;
|
birthday: Date;
|
||||||
}) => {
|
}) => {
|
||||||
setRedirectOverride(true)
|
setRedirectOverride(true);
|
||||||
|
const familyId = uuidv4();
|
||||||
|
|
||||||
await auth()
|
await auth()
|
||||||
.createUserWithEmailAndPassword(email, password)
|
.createUserWithEmailAndPassword(email, password)
|
||||||
@ -35,12 +54,14 @@ export const useSignUp = () => {
|
|||||||
userType: ProfileType.PARENT,
|
userType: ProfileType.PARENT,
|
||||||
firstName: firstName,
|
firstName: firstName,
|
||||||
lastName: lastName,
|
lastName: lastName,
|
||||||
familyId: uuidv4(),
|
familyId: familyId,
|
||||||
timeZone: Localization.getCalendars()[0].timeZone,
|
timeZone: Localization.getCalendars()[0].timeZone,
|
||||||
birthday: birthday
|
birthday: birthday
|
||||||
},
|
},
|
||||||
customUser: res.user,
|
customUser: res.user,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await createHouseholdIfNeeded(familyId, lastName);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user