import React, { useState } from 'react'; import { View, Text, TextInput, TouchableOpacity, ScrollView, Switch, StyleSheet, Alert, } from 'react-native'; import { useNavigation } from '@react-navigation/native'; import { useAuth } from '@/store/auth'; import { Colors, Spacing, FontSizes, Radius } from '@/theme/colors'; import { Config } from '@/config'; import type { Gender } from '@/types/api'; export default function RegisterScreen() { const nav = useNavigation(); const { register, loading, error } = useAuth(); const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [phone, setPhone] = useState(''); const [password, setPassword] = useState(''); const [birthdate, setBirthdate] = useState(''); const [gender, setGender] = useState(''); const [city, setCity] = useState(''); const [cAdult, setCAdult] = useState(false); const [cTerms, setCTerms] = useState(false); const [cPrivacy, setCPrivacy] = useState(false); const [cDisclaimer, setCDisclaimer] = useState(false); const allConsents = cAdult && cTerms && cPrivacy && cDisclaimer; const canSubmit = name.trim().length > 0 && (email.trim() || phone.trim()) && password.length >= Config.MIN_PASSWORD_LENGTH && allConsents && !loading; const onSubmit = async () => { if (!allConsents) { Alert.alert('Согласия', 'Подтвердите все 4 пункта: 18+, соглашение, политика, отказ'); return; } try { await register({ email: email.trim() || undefined, phone: phone.trim() || undefined, password, name: name.trim(), birthdate: birthdate.trim() || undefined, gender: gender || undefined, city: city.trim() || undefined, consents: { adult: cAdult, terms: cTerms, privacy: cPrivacy, disclaimer: cDisclaimer, }, }); } catch (e: any) { Alert.alert('Ошибка', e?.response?.data?.error ?? 'не удалось зарегистрироваться'); } }; return ( Регистрация BuhApp — для совершеннолетних Пол {(['m','f','o'] as Gender[]).map((g) => ( setGender(g)}> {g === 'm' ? 'Мужской' : g === 'f' ? 'Женский' : 'Другое'} ))} Согласия (обязательно) {error && {error}} {loading ? 'Отправка...' : 'Создать аккаунт'} nav.navigate('Login')} style={{ marginTop: Spacing.l }}> У меня уже есть аккаунт ); } function Field({ label, ...props }: any) { return ( {label} ); } function ConsentRow({ label, value, onChange }: { label: string; value: boolean; onChange: (v: boolean) => void }) { return ( {label} ); } const styles = StyleSheet.create({ root: { flex: 1, backgroundColor: Colors.bg }, content: { padding: Spacing.l, paddingTop: Spacing.xxl }, title: { fontSize: FontSizes.xxl, fontWeight: '700', color: Colors.text }, subtitle: { fontSize: FontSizes.m, color: Colors.textDim, marginBottom: Spacing.l }, label: { fontSize: FontSizes.s, color: Colors.textDim, marginBottom: Spacing.xs }, input: { borderWidth: 1, borderColor: Colors.border, borderRadius: Radius.m, paddingHorizontal: Spacing.m, paddingVertical: Spacing.s, fontSize: FontSizes.m, color: Colors.text, backgroundColor: Colors.bg, }, row: { flexDirection: 'row', gap: Spacing.s as any }, chip: { paddingVertical: Spacing.s, paddingHorizontal: Spacing.m, borderRadius: Radius.full, borderWidth: 1, borderColor: Colors.border, marginRight: Spacing.s, }, chipActive: { backgroundColor: Colors.primary, borderColor: Colors.primary }, chipText: { color: Colors.text, fontSize: FontSizes.s }, chipTextActive: { color: Colors.textInverse, fontWeight: '600' }, consent: { flexDirection: 'row', alignItems: 'center', marginBottom: Spacing.s, gap: Spacing.s as any }, consentText: { flex: 1, fontSize: FontSizes.s, color: Colors.text }, btn: { backgroundColor: Colors.primary, paddingVertical: Spacing.m, borderRadius: Radius.m, alignItems: 'center', marginTop: Spacing.l, }, btnDisabled: { opacity: 0.5 }, btnText: { color: Colors.textInverse, fontSize: FontSizes.l, fontWeight: '600' }, link: { color: Colors.secondary, textAlign: 'center', fontSize: FontSizes.m }, error: { color: Colors.danger, fontSize: FontSizes.s, marginTop: Spacing.s }, });