80 lines
2.7 KiB
TypeScript
80 lines
2.7 KiB
TypeScript
import { Link, Stack, useRouter } from 'expo-router';
|
|
import { useState } from 'react';
|
|
import { Pressable, Text, TextInput, View } from 'react-native';
|
|
|
|
import { useAuth } from '@/context/AuthContext';
|
|
import { formatPocketBaseError } from '@/utils/pocketbaseErrors';
|
|
|
|
export default function RegisterScreen() {
|
|
const router = useRouter();
|
|
const { register } = useAuth();
|
|
const [name, setName] = useState('');
|
|
const [email, setEmail] = useState('');
|
|
const [password, setPassword] = useState('');
|
|
const [err, setErr] = useState<string | null>(null);
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
const onSubmit = async () => {
|
|
setErr(null);
|
|
setBusy(true);
|
|
try {
|
|
await register({ name, email, password });
|
|
router.replace('/(tabs)');
|
|
} catch (e) {
|
|
setErr(formatPocketBaseError(e));
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Stack.Screen options={{ title: 'Inscription' }} />
|
|
<View className="flex-1 justify-center bg-slate-50 px-6">
|
|
{err ? (
|
|
<View className="mb-4 rounded-xl border border-red-200 bg-red-50 px-3 py-2">
|
|
<Text className="text-sm text-red-900">{err}</Text>
|
|
</View>
|
|
) : null}
|
|
<Text className="mb-1 text-sm text-slate-600">Nom</Text>
|
|
<TextInput
|
|
className="mb-3 rounded-xl border border-slate-200 bg-white px-3 py-3 text-base text-slate-900"
|
|
value={name}
|
|
onChangeText={setName}
|
|
placeholderTextColor="#94a3b8"
|
|
/>
|
|
<Text className="mb-1 text-sm text-slate-600">Email</Text>
|
|
<TextInput
|
|
className="mb-3 rounded-xl border border-slate-200 bg-white px-3 py-3 text-base text-slate-900"
|
|
autoCapitalize="none"
|
|
keyboardType="email-address"
|
|
value={email}
|
|
onChangeText={setEmail}
|
|
placeholderTextColor="#94a3b8"
|
|
/>
|
|
<Text className="mb-1 text-sm text-slate-600">Mot de passe</Text>
|
|
<TextInput
|
|
className="mb-6 rounded-xl border border-slate-200 bg-white px-3 py-3 text-base text-slate-900"
|
|
secureTextEntry
|
|
value={password}
|
|
onChangeText={setPassword}
|
|
placeholderTextColor="#94a3b8"
|
|
/>
|
|
<Pressable
|
|
className="mb-4 rounded-xl py-3"
|
|
style={{ backgroundColor: busy ? '#94a3b8' : '#1D4ED8' }}
|
|
onPress={onSubmit}
|
|
disabled={busy}
|
|
>
|
|
<Text className="text-center font-semibold text-white">S'inscrire</Text>
|
|
</Pressable>
|
|
<Link href="/auth/login" asChild>
|
|
<Pressable>
|
|
<Text className="text-center text-blue-700">Déjà un compte ? Connexion</Text>
|
|
</Pressable>
|
|
</Link>
|
|
</View>
|
|
</>
|
|
);
|
|
}
|