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 dispatch = useDispatch();
|
||||
// const creds = useSelector((state: RootState) => state.auth.creds);
|
||||
const [registering, setRegistering] = useState(false);
|
||||
const [user, setUser] = useState({
|
||||
first_name: "",
|
||||
last_name: "",
|
||||
|
@ -30,6 +31,7 @@ export default function Register() {
|
|||
username: "",
|
||||
email: "",
|
||||
password: "",
|
||||
confirm_password: "",
|
||||
});
|
||||
return (
|
||||
<View style={styles.background}>
|
||||
|
@ -121,8 +123,25 @@ export default function Register() {
|
|||
}}
|
||||
/>
|
||||
<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
|
||||
onPress={async () => {
|
||||
if (!registering) {
|
||||
if (user.password === user.confirm_password) {
|
||||
setRegistering(true);
|
||||
await UserRegister({
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
|
@ -130,7 +149,7 @@ export default function Register() {
|
|||
student_id_number: user.student_id_number,
|
||||
first_name: user.first_name,
|
||||
last_name: user.last_name,
|
||||
}).then((result) => {
|
||||
}).then((result: any) => {
|
||||
console.log(result);
|
||||
if (result[0]) {
|
||||
setUser({
|
||||
|
@ -151,11 +170,12 @@ export default function Register() {
|
|||
animationType: "slide-in",
|
||||
}
|
||||
);
|
||||
setRegistering(false);
|
||||
setTimeout(() => {
|
||||
navigation.navigate("Login");
|
||||
}, 10000);
|
||||
} else {
|
||||
toast.show(JSON.stringify(result[1]), {
|
||||
toast.show(JSON.parse(JSON.stringify(result[1])), {
|
||||
type: "warning",
|
||||
placement: "top",
|
||||
duration: 6000,
|
||||
|
@ -163,7 +183,17 @@ export default function Register() {
|
|||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toast.show(
|
||||
"Password does not match confirm password. Please try again"
|
||||
),
|
||||
{
|
||||
type: "warning",
|
||||
placement: "top",
|
||||
duration: 6000,
|
||||
animationType: "slide-in",
|
||||
};
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
|
Loading…
Reference in a new issue