mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2024-11-17 06:19:25 +08:00
Added confirm password field
This commit is contained in:
parent
8867306bd0
commit
be21689639
1 changed files with 64 additions and 34 deletions
|
@ -23,6 +23,7 @@ export default function Register() {
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
// const dispatch = useDispatch();
|
// const dispatch = useDispatch();
|
||||||
// const creds = useSelector((state: RootState) => state.auth.creds);
|
// const creds = useSelector((state: RootState) => state.auth.creds);
|
||||||
|
const [registering, setRegistering] = useState(false);
|
||||||
const [user, setUser] = useState({
|
const [user, setUser] = useState({
|
||||||
first_name: "",
|
first_name: "",
|
||||||
last_name: "",
|
last_name: "",
|
||||||
|
@ -30,6 +31,7 @@ export default function Register() {
|
||||||
username: "",
|
username: "",
|
||||||
email: "",
|
email: "",
|
||||||
password: "",
|
password: "",
|
||||||
|
confirm_password: "",
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<View style={styles.background}>
|
<View style={styles.background}>
|
||||||
|
@ -121,49 +123,77 @@ export default function Register() {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={{ paddingVertical: 4 }} />
|
<View style={{ paddingVertical: 4 }} />
|
||||||
|
<TextInput
|
||||||
|
style={styles.text_input}
|
||||||
|
placeholder="Confirm Password"
|
||||||
|
placeholderTextColor={colors.text_default}
|
||||||
|
secureTextEntry={true}
|
||||||
|
value={user.confirm_password}
|
||||||
|
autoCapitalize={"none"}
|
||||||
|
onChange={(
|
||||||
|
e: NativeSyntheticEvent<TextInputChangeEventData>
|
||||||
|
): void => {
|
||||||
|
setUser({ ...user, confirm_password: e.nativeEvent.text });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<View style={{ paddingVertical: 4 }} />
|
||||||
<Button
|
<Button
|
||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
await UserRegister({
|
if (!registering) {
|
||||||
username: user.username,
|
if (user.password === user.confirm_password) {
|
||||||
email: user.email,
|
setRegistering(true);
|
||||||
password: user.password,
|
await UserRegister({
|
||||||
student_id_number: user.student_id_number,
|
username: user.username,
|
||||||
first_name: user.first_name,
|
email: user.email,
|
||||||
last_name: user.last_name,
|
password: user.password,
|
||||||
}).then((result) => {
|
student_id_number: user.student_id_number,
|
||||||
console.log(result);
|
first_name: user.first_name,
|
||||||
if (result[0]) {
|
last_name: user.last_name,
|
||||||
setUser({
|
}).then((result: any) => {
|
||||||
...user,
|
console.log(result);
|
||||||
first_name: "",
|
if (result[0]) {
|
||||||
last_name: "",
|
setUser({
|
||||||
student_id_number: "",
|
...user,
|
||||||
username: "",
|
first_name: "",
|
||||||
email: "",
|
last_name: "",
|
||||||
password: "",
|
student_id_number: "",
|
||||||
|
username: "",
|
||||||
|
email: "",
|
||||||
|
password: "",
|
||||||
|
});
|
||||||
|
toast.show(
|
||||||
|
"Success! An email has been sent to activate your account",
|
||||||
|
{
|
||||||
|
type: "success",
|
||||||
|
placement: "top",
|
||||||
|
duration: 6000,
|
||||||
|
animationType: "slide-in",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
setRegistering(false);
|
||||||
|
setTimeout(() => {
|
||||||
|
navigation.navigate("Login");
|
||||||
|
}, 10000);
|
||||||
|
} else {
|
||||||
|
toast.show(JSON.parse(JSON.stringify(result[1])), {
|
||||||
|
type: "warning",
|
||||||
|
placement: "top",
|
||||||
|
duration: 6000,
|
||||||
|
animationType: "slide-in",
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
toast.show(
|
toast.show(
|
||||||
"Success! An email has been sent to activate your account",
|
"Password does not match confirm password. Please try again"
|
||||||
|
),
|
||||||
{
|
{
|
||||||
type: "success",
|
type: "warning",
|
||||||
placement: "top",
|
placement: "top",
|
||||||
duration: 6000,
|
duration: 6000,
|
||||||
animationType: "slide-in",
|
animationType: "slide-in",
|
||||||
}
|
};
|
||||||
);
|
|
||||||
setTimeout(() => {
|
|
||||||
navigation.navigate("Login");
|
|
||||||
}, 10000);
|
|
||||||
} else {
|
|
||||||
toast.show(JSON.stringify(result[1]), {
|
|
||||||
type: "warning",
|
|
||||||
placement: "top",
|
|
||||||
duration: 6000,
|
|
||||||
animationType: "slide-in",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in a new issue