125 lines
3.2 KiB
TypeScript
125 lines
3.2 KiB
TypeScript
import React from 'react';
|
|
import {View, Text, Platform, useWindowDimensions} from 'react-native';
|
|
import axios from 'axios';
|
|
import {useToast} from 'react-native-toast-notifications';
|
|
import {Button, TextInput} from 'react-native-paper';
|
|
import {useDispatch} from 'react-redux';
|
|
import {login} from '../../redux/reducers';
|
|
import {ReactNavigationDracula as t} from '../../themes';
|
|
import {ps} from '../../utils';
|
|
|
|
export default function SignUp() {
|
|
const [username, setUsername] = React.useState('');
|
|
const [password, setPassword] = React.useState('');
|
|
const [confirm, setConfirm] = React.useState('');
|
|
const toast = useToast();
|
|
const dispatch = useDispatch();
|
|
const {height, width} = useWindowDimensions();
|
|
|
|
function signUpFunction(dispatch) {
|
|
if (confirm != password) {
|
|
toast.show('The password and its confirmation are not the same', {
|
|
type: 'warning',
|
|
});
|
|
return;
|
|
}
|
|
|
|
axios
|
|
.put(
|
|
'https://notifysync.simailadjalim.fr/user',
|
|
{
|
|
username: username,
|
|
password: password,
|
|
},
|
|
{
|
|
headers: {'Content-Type': 'multipart/form-data'},
|
|
},
|
|
)
|
|
.then((response, status) => {
|
|
toast.show('Account created, logging in !', {type: 'success'});
|
|
axios
|
|
.post(
|
|
'https://notifysync.simailadjalim.fr/user',
|
|
{
|
|
username: username,
|
|
password: password,
|
|
},
|
|
{
|
|
headers: {'Content-Type': 'multipart/form-data'},
|
|
},
|
|
)
|
|
.then((response, status) => {
|
|
let token = response.data.token;
|
|
dispatch(login({username: username, token: token}));
|
|
toast.show('login successful .w.', {type: 'success'});
|
|
})
|
|
.catch(response => {
|
|
toast.show(response.response.data.status);
|
|
});
|
|
//
|
|
})
|
|
.catch(response => {
|
|
toast.show(response.response.data.status);
|
|
});
|
|
}
|
|
|
|
return (
|
|
<View
|
|
style={[
|
|
{
|
|
borderRadius: 12,
|
|
height: '100%',
|
|
},
|
|
{
|
|
flex: 1,
|
|
margin: ps(8),
|
|
padding: ps(8),
|
|
paddingTop: ps(8),
|
|
gap: 10,
|
|
flexDirection: 'column',
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
backgroundColor: width > 600 ? t.colors.card : t.colors.background,
|
|
},
|
|
]}>
|
|
<Text style={{fontWeight: 'bold', fontSize: 30, color: t.colors.text}}>
|
|
Créer un compte
|
|
</Text>
|
|
<TextInput
|
|
label="Nom d'utilisateur"
|
|
mode="outlined"
|
|
value={username}
|
|
onChangeText={setUsername}
|
|
style={{
|
|
width: 300,
|
|
}}
|
|
/>
|
|
<TextInput
|
|
label="Mot de passe"
|
|
mode="outlined"
|
|
value={password}
|
|
onChangeText={setPassword}
|
|
style={{
|
|
width: 300,
|
|
}}
|
|
/>
|
|
<TextInput
|
|
label="Confirmer le mot de passe"
|
|
mode="outlined"
|
|
value={confirm}
|
|
onChangeText={setConfirm}
|
|
style={{
|
|
width: 300,
|
|
}}
|
|
/>
|
|
<Button
|
|
mode="contained"
|
|
onPress={() => {
|
|
dispatch(signUpFunction);
|
|
}}>
|
|
S'enregistrer
|
|
</Button>
|
|
</View>
|
|
);
|
|
}
|