diff --git a/src/redux/user/actions.tsx b/src/redux/user/actions.tsx index 77418c43e2e2eac369abca5c36397bf559920db7..606ac3f14d9e06589b5d4ff79e2ebd255cd22f45 100644 --- a/src/redux/user/actions.tsx +++ b/src/redux/user/actions.tsx @@ -72,19 +72,29 @@ export const signupUser = ( firstName: string, lastName: string, email: string, - password: string + password: string, + phone: string, + businessType: string ) => { return async (dispatch: Dispatch) => { try { const userAuth = await authService.signUpAuth(email, password); const uid = userAuth.user.uid; - await userService.createUser(email, firstName, lastName, uid); - dispatch({ + await userService.createUser(uid, { + firstName, + lastName, + email, + phone, + businessType, + pic: "", + }); + return dispatch({ type: "SIGNUP", - payload: { email, firstName, lastName, id: uid }, + payload: { email, firstName, lastName, id: uid, phone, businessType }, }); } catch (e) { console.log(e); + return { error: e }; } }; }; diff --git a/src/screens/auth/RegisterScreen.tsx b/src/screens/auth/RegisterScreen.tsx index 5d9d2dc8e76039b2cc36b56b1498d25fa7e91c95..48ead26fdf1b43df8310cefb20a6f8bf42058a39 100644 --- a/src/screens/auth/RegisterScreen.tsx +++ b/src/screens/auth/RegisterScreen.tsx @@ -25,13 +25,12 @@ const RegisterScreen = ({ navigation }: RootTabScreenProps<"TabOne">) => { const [password, setPassword] = useState(""); const [phoneNo, setPhoneNo] = useState(""); const [picked, setPicked] = useState(""); + const dispatch = useAppDispatch(); const [categories, setCategories] = useState([]); useEffect(() => { getCategoriesAsDdFormat().then((res) => setCategories(res)); - }); - - const dispatch = useAppDispatch(); + }, []); const handleSubmit = () => { if ( @@ -42,7 +41,11 @@ const RegisterScreen = ({ navigation }: RootTabScreenProps<"TabOne">) => { validateEmpty(password) && validateEmpty(picked) ) { - dispatch(signupUser(firstName, lastName, email, password)); + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + dispatch( + signupUser(firstName, lastName, email, password, phoneNo, picked) + ).then(() => Alert.alert("Error", "Something went wrong")); + // .then((e: ActionErrorRes) => e.error && Alert.alert("Error", e.error)); } else { Alert.alert("Form Tidak Lengkap", "Silahkan isi form dengan benar"); } @@ -155,6 +158,7 @@ const RegisterScreen = ({ navigation }: RootTabScreenProps<"TabOne">) => { + ); }; @@ -163,6 +167,7 @@ const styles = StyleSheet.create({ container: { padding: 24, backgroundColor: Colors.background, + flex: 1, }, titleText: { fontSize: 32, diff --git a/src/service/firestore/user.ts b/src/service/firestore/user.ts index 9b4d35b23e3cfa8fd3ae15cd989c9b3c6138b39f..cac4e653acefe38bd603fee48e251a3bf690009b 100644 --- a/src/service/firestore/user.ts +++ b/src/service/firestore/user.ts @@ -1,4 +1,5 @@ import firebase from "firebase/app"; +import { IUser } from "../../types/firestore/User"; export const addProfilePic = async (url: string, userId: string) => { const db = firebase.firestore(); @@ -12,16 +13,7 @@ export const getUser = async (id) => { return await db.collection("users").doc(id).get(); }; -export const createUser = async ( - email: string, - firstName: string, - lastName: string, - uid: string -) => { +export const createUser = async (uid, user: IUser) => { const db = firebase.firestore(); - return await db.collection("users").doc(uid).set({ - firstName, - lastName, - email, - }); + return await db.collection("users").doc(uid).set(user); };