Fakultas Ilmu Komputer UI

Commit 835b0841 authored by Ahmad Izzudin Alifyandra's avatar Ahmad Izzudin Alifyandra
Browse files

Merge branch 'fix-register' into 'master'

Fix register

See merge request !91
parents feec42ae 0e9df53c
Pipeline #86256 passed with stage
in 12 minutes and 55 seconds
......@@ -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<any>) => {
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 };
}
};
};
......@@ -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<IDD[]>([]);
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">) => {
<MainButton text="Daftar" colors="primary" onPress={handleSubmit} />
</View>
<Spacer variant="xl" />
<Spacer variant="xl" />
</ScrollView>
);
};
......@@ -163,6 +167,7 @@ const styles = StyleSheet.create({
container: {
padding: 24,
backgroundColor: Colors.background,
flex: 1,
},
titleText: {
fontSize: 32,
......
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);
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment