forked from Winz18/Online-Learning-Mobile_app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSignupScreen.tsx
96 lines (90 loc) · 2.47 KB
/
SignupScreen.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import type { PropsWithChildren } from "react";
import React, { useState } from "react";
import { Alert, Button, ScrollView, StyleSheet, Text, TextInput } from "react-native";
import { NavigationProp } from "@react-navigation/native";
import axios from "axios";
type SectionProps = PropsWithChildren<{
navigation: NavigationProp<any, any>;
}>;
function SignUpScreen({ navigation }: SectionProps): React.JSX.Element {
const [username, setUsername] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [password2, setPassword2] = useState("");
const handleSignUp = () => {
console.log(username, email, password, password2);
axios
.post("http://10.0.2.2:8000/api/auth/register/", {
username,
email,
password,
password2
})
.then(response => {
Alert.alert("Success", "User registered successfully");
navigation.navigate("Login");
})
.catch(error => {
console.error(error);
Alert.alert("Error", "An error occurred. Please try again.");
});
};
return (
<ScrollView contentContainerStyle={styles.container}>
<Text style={styles.title}>Sign Up</Text>
<TextInput
style={styles.input}
placeholder="Username"
value={username}
onChangeText={setUsername}
/>
<TextInput
style={styles.input}
placeholder="Email"
value={email}
onChangeText={setEmail}
keyboardType="email-address"
/>
<TextInput
style={styles.input}
placeholder="Password"
value={password}
onChangeText={setPassword}
secureTextEntry
/>
<TextInput
style={styles.input}
placeholder="Confirm Password"
value={password2}
onChangeText={setPassword2}
secureTextEntry
/>
<Button title="Sign Up" onPress={handleSignUp} />
<Text>{"\n"}</Text>
<Button title="Back to login" onPress={() => navigation.navigate("Login")} />
</ScrollView>
);
}
const styles = StyleSheet.create({
container: {
flexGrow: 1,
justifyContent: "center",
alignItems: "center",
padding: 16,
backgroundColor: "#f5f5f5"
},
title: {
fontSize: 30,
marginBottom: 20,
fontWeight: "bold"
},
input: {
width: "100%",
padding: 10,
marginVertical: 10,
borderWidth: 1,
borderColor: "#cccccc",
borderRadius: 8
}
});
export default SignUpScreen;