register update
This commit is contained in:
@@ -9,7 +9,7 @@ import { ScrollView, StyleSheet, Text, TouchableOpacity } from 'react-native';
|
||||
|
||||
export default function CategorySelectScreen() {
|
||||
const router = useRouter();
|
||||
const { phone, stir, person_type, director_full_name, referal, first_name, last_name } = useLocalSearchParams<{
|
||||
const { phone, stir, person_type, director_full_name, referal, first_name, last_name, address, company_name } = useLocalSearchParams<{
|
||||
phone: string;
|
||||
stir: string;
|
||||
person_type: 'band' | 'ytt';
|
||||
@@ -17,10 +17,10 @@ export default function CategorySelectScreen() {
|
||||
director_full_name: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
address: string;
|
||||
company_name: string;
|
||||
}>();
|
||||
|
||||
console.log(referal);
|
||||
|
||||
const [selected, setSelected] = React.useState<number | null>(null);
|
||||
|
||||
const { data } = useQuery({
|
||||
@@ -34,10 +34,13 @@ export default function CategorySelectScreen() {
|
||||
stir: string;
|
||||
person_type: string;
|
||||
activate_types: number[];
|
||||
referal: string;
|
||||
referral: string;
|
||||
director_full_name: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
district: number;
|
||||
company_name: string;
|
||||
address: number;
|
||||
}) => auth_api.register(body),
|
||||
onSuccess: () => router.replace('/'),
|
||||
});
|
||||
@@ -68,10 +71,13 @@ export default function CategorySelectScreen() {
|
||||
person_type: person_type,
|
||||
phone: `998${phone}`,
|
||||
stir: stir,
|
||||
referal: String(referal),
|
||||
referral: String(referal),
|
||||
director_full_name: String(director_full_name),
|
||||
first_name: String(first_name),
|
||||
last_name: String(last_name),
|
||||
district: Number(address),
|
||||
company_name: String(company_name),
|
||||
address: Number(address),
|
||||
});
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -1,27 +1,22 @@
|
||||
import AuthHeader from '@/components/ui/AuthHeader';
|
||||
import { decryptToken } from '@/constants/crypto';
|
||||
import { formatPhone, normalizeDigits } from '@/constants/formatPhone';
|
||||
import { formatText, formatTextToLatin } from '@/constants/formatText';
|
||||
import { products_api } from '@/screens/home/lib/api';
|
||||
import BottomSheet, {
|
||||
BottomSheetBackdrop,
|
||||
BottomSheetFlatList,
|
||||
BottomSheetTextInput,
|
||||
} from '@gorhom/bottom-sheet';
|
||||
import BottomSheet, { BottomSheetBackdrop, BottomSheetFlatList, BottomSheetTextInput } from '@gorhom/bottom-sheet';
|
||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||
import { AxiosError } from 'axios';
|
||||
import { Image } from 'expo-image';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { useRouter } from 'expo-router';
|
||||
import {
|
||||
Building2,
|
||||
CheckIcon,
|
||||
ChevronDown,
|
||||
Globe,
|
||||
Hash,
|
||||
Search,
|
||||
ShieldCheck,
|
||||
User,
|
||||
UserPlus,
|
||||
UserPlus
|
||||
} from 'lucide-react-native';
|
||||
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
ActivityIndicator,
|
||||
@@ -34,72 +29,78 @@ import {
|
||||
} from 'react-native';
|
||||
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
|
||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||
import { auth_api } from '../login/lib/api';
|
||||
import { auth_api, GetInfo } from '../login/lib/api';
|
||||
import PhonePrefix from '../login/ui/PhonePrefix';
|
||||
import { useRegister } from './lib/useRegisterStore';
|
||||
import { UseLoginForm } from '../login/ui/UseLoginForm';
|
||||
|
||||
function getHeaderInfo(personType: string | null) {
|
||||
switch (personType) {
|
||||
case 'yatt':
|
||||
return {
|
||||
label: 'YATT',
|
||||
icon: <User size={32} color="#ffffff" />,
|
||||
gradient: ['#10b981', '#059669'] as [string, string],
|
||||
};
|
||||
case 'band':
|
||||
return {
|
||||
label: "O'zini o'zi band qilgan",
|
||||
icon: <ShieldCheck size={32} color="#ffffff" />,
|
||||
gradient: ['#3b82f6', '#2563eb'] as [string, string],
|
||||
};
|
||||
case 'legal_entity':
|
||||
return {
|
||||
label: 'Yuridik shaxs',
|
||||
icon: <Building2 size={32} color="#ffffff" />,
|
||||
gradient: ['#f59e0b', '#d97706'] as [string, string],
|
||||
};
|
||||
default:
|
||||
return {
|
||||
label: "Ro'yxatdan o'tish",
|
||||
icon: <UserPlus size={32} color="#ffffff" />,
|
||||
gradient: ['#10b981', '#059669'] as [string, string],
|
||||
};
|
||||
}
|
||||
interface CoordsData {
|
||||
lat: number;
|
||||
lon: number;
|
||||
polygon: [number, number][][];
|
||||
}
|
||||
|
||||
export default function RegisterFormScreen() {
|
||||
const router = useRouter();
|
||||
const {
|
||||
personType,
|
||||
phone,
|
||||
setPhone,
|
||||
referal,
|
||||
setReferal,
|
||||
jshshr,
|
||||
setJshshr,
|
||||
passportSeries,
|
||||
setPassportSeries,
|
||||
passportNumber,
|
||||
setPassportNumber,
|
||||
inn,
|
||||
setInn,
|
||||
info,
|
||||
setInfo,
|
||||
directorInfo,
|
||||
setDirectorInfo,
|
||||
} = useRegister();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [loading, setLoading] = React.useState(false);
|
||||
const [directorJshshr, setDirectorJshshr] = React.useState('');
|
||||
const [directorLoading, setDirectorLoading] = React.useState(false);
|
||||
const [directorInfoError, setErrorDirectorInfo] = useState<string | null>(null);
|
||||
|
||||
// Country select
|
||||
const [selectedCountry, setSelectedCountry] = useState<string>('UZ');
|
||||
const [countrySearch, setCountrySearch] = useState<string>('');
|
||||
const { phone, setPhone } = UseLoginForm();
|
||||
const countrySheetRef = useRef<BottomSheet>(null);
|
||||
const snapPoints = useMemo(() => ['60%', '90%'], []);
|
||||
const [selectedCountry, setSelectedCountry] = useState<string>('UZ');
|
||||
const [countrySearch, setCountrySearch] = useState<string>('');
|
||||
|
||||
const [stir, setStir] = useState('');
|
||||
const [info, setInfo] = useState<GetInfo | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [referal, setReferal] = useState('');
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [district, setDistrict] = useState<string | null>(null)
|
||||
const [region, setRegion] = useState<string | null>(null)
|
||||
const [token, setTokens] = useState<{ name: string, value: string } | null>(null)
|
||||
|
||||
const [directorTinInput, setDirectorTinInput] = useState('');
|
||||
|
||||
const { data } = useQuery({
|
||||
queryKey: ["tokens"],
|
||||
queryFn: async () => auth_api.get_tokens(),
|
||||
select(data) {
|
||||
return data.data.data.results
|
||||
},
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (data?.length) {
|
||||
const token = data[0]
|
||||
const tokenValue = decryptToken(token.value)
|
||||
if (tokenValue) {
|
||||
setTokens({ name: token.key, value: tokenValue })
|
||||
}
|
||||
}
|
||||
}, [data])
|
||||
|
||||
const { mutate } = useMutation({
|
||||
mutationFn: (stir: string) => auth_api.get_info({ value: stir, token: token?.value || "", tokenName: token?.name || "" }),
|
||||
onSuccess: (res) => {
|
||||
setInfo(res.data);
|
||||
setLoading(false);
|
||||
setError(null)
|
||||
setDistrict(res.data.address)
|
||||
},
|
||||
onError: () => {
|
||||
setInfo(null);
|
||||
setLoading(false);
|
||||
setError("Foydalanuvchi topilmadi")
|
||||
},
|
||||
});
|
||||
|
||||
const { data: districts } = useQuery({
|
||||
queryKey: ["discrit"],
|
||||
queryFn: async () => auth_api.get_district(),
|
||||
})
|
||||
|
||||
const { data: regions } = useQuery({
|
||||
queryKey: ["regions"],
|
||||
queryFn: async () => auth_api.get_region(),
|
||||
})
|
||||
|
||||
const { data: countryResponse, isLoading: countryLoading } = useQuery({
|
||||
queryKey: ['country-detail'],
|
||||
@@ -107,6 +108,111 @@ export default function RegisterFormScreen() {
|
||||
select: (res) => res.data?.data || [],
|
||||
});
|
||||
|
||||
const getRegionDistrictFromAddress = async (address: string) => {
|
||||
try {
|
||||
const encoded = encodeURIComponent(address + ", Uzbekistan");
|
||||
const res = await fetch(
|
||||
`https://nominatim.openstreetmap.org/search?q=${encoded}&format=json&addressdetails=1&limit=1`,
|
||||
{ headers: { 'Accept-Language': 'uz', 'User-Agent': 'MyApp/1.0 (turgunboyevsamandar4@gamil.com)' } }
|
||||
);
|
||||
const data = await res.json();
|
||||
|
||||
if (data.length > 0) {
|
||||
const addr = data[0].address;
|
||||
return {
|
||||
district: addr.county || addr.district || addr.suburb,
|
||||
region: addr.state,
|
||||
};
|
||||
}
|
||||
} catch (e) { }
|
||||
return null;
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (district) {
|
||||
const dis = formatText(district)?.split(" ")[0].toLocaleUpperCase()
|
||||
let reg = null
|
||||
if (dis) {
|
||||
reg = districts?.data.find((item) => item.name.includes(dis))
|
||||
};
|
||||
|
||||
if (reg) {
|
||||
const region = regions?.data.find((item) => item.regionId == reg.regionId)
|
||||
setRegion(region?.name || "")
|
||||
}
|
||||
}
|
||||
}, [district])
|
||||
|
||||
|
||||
const [districtId, setDistrictId] = useState<number | null>(null);
|
||||
const [regionId, setRegionId] = useState<number | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!district || !countryResponse?.length) return;
|
||||
|
||||
const resolve = async () => {
|
||||
const geo = await getRegionDistrictFromAddress(district.split(" ")[0]);
|
||||
|
||||
const searchRegion = geo?.region || region;
|
||||
const searchDistrict = geo?.district || district
|
||||
|
||||
for (const country of countryResponse) {
|
||||
const regionName = formatTextToLatin(searchRegion)?.split(" ")[0];
|
||||
let foundRegion = null
|
||||
if (regionName) {
|
||||
foundRegion = country.region.find((r: any) =>
|
||||
formatTextToLatin(r.name)?.includes(regionName)
|
||||
);
|
||||
}
|
||||
|
||||
if (foundRegion) {
|
||||
setRegionId(foundRegion.id);
|
||||
setDistrictId(null);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const reg of country.region || []) {
|
||||
const dis = formatTextToLatin(searchDistrict)?.split(" ")[0].toUpperCase();
|
||||
let foundDistrict = null
|
||||
if (dis) {
|
||||
foundDistrict = reg.districts.find((d: any) => {
|
||||
return formatTextToLatin(d.name)?.toUpperCase().includes(dis.slice(0, 4))
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
if (foundDistrict) {
|
||||
setDistrictId(foundDistrict.id);
|
||||
setRegionId(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
resolve();
|
||||
}, [district, countryResponse]);
|
||||
|
||||
useEffect(() => {
|
||||
if (info === null || (stir.length === 9 && info.name && info.fullName)) {
|
||||
setError(null)
|
||||
} else if (info?.name === null || info?.fullName === null) {
|
||||
setError("Sizning shaxsiy ma'lumotlaringiz topilmadi")
|
||||
} else if (!info?.selfEmployment && !info?.isItd) {
|
||||
setError("Siz o'zini o'zi band qilgan yoki yakka tartibdagi tadbirkorlik bo'lishingiz kerak")
|
||||
}
|
||||
}, [info])
|
||||
|
||||
const hasDirectorTin = info?.directorPinfl && String(info.directorPinfl).length > 0;
|
||||
|
||||
const isDirectorTinValid = !hasDirectorTin || directorTinInput === String(info.directorPinfl);
|
||||
const hasValidName = Boolean(info?.name || info?.fullName);
|
||||
|
||||
const filteredCountries = useMemo(() => {
|
||||
if (!countrySearch.trim()) return countryResponse || [];
|
||||
const q = countrySearch.toLowerCase().trim();
|
||||
return (countryResponse || []).filter((c: any) => c.name?.toLowerCase().includes(q));
|
||||
}, [countryResponse, countrySearch]);
|
||||
|
||||
const openCountrySheet = useCallback(() => {
|
||||
Keyboard.dismiss();
|
||||
setTimeout(() => {
|
||||
@@ -114,10 +220,13 @@ export default function RegisterFormScreen() {
|
||||
}, 100);
|
||||
}, []);
|
||||
|
||||
const closeCountrySheet = useCallback(() => {
|
||||
countrySheetRef.current?.close();
|
||||
setTimeout(() => setCountrySearch(''), 300);
|
||||
}, []);
|
||||
const selectedCountryName = useMemo(() => {
|
||||
if (!selectedCountry) return t('Tanlang');
|
||||
return (
|
||||
countryResponse?.find((c: any) => c.flag?.toUpperCase() === selectedCountry)?.name ||
|
||||
t('Tanlang')
|
||||
);
|
||||
}, [selectedCountry, countryResponse, t]);
|
||||
|
||||
const renderBackdrop = useCallback(
|
||||
(props: any) => (
|
||||
@@ -132,223 +241,20 @@ export default function RegisterFormScreen() {
|
||||
[]
|
||||
);
|
||||
|
||||
const selectedCountryName = useMemo(() => {
|
||||
if (!selectedCountry) return t('Tanlang');
|
||||
return (
|
||||
countryResponse?.find((c: any) => c.flag?.toUpperCase() === selectedCountry)?.name ||
|
||||
t('Tanlang')
|
||||
);
|
||||
}, [selectedCountry, countryResponse, t]);
|
||||
const closeCountrySheet = useCallback(() => {
|
||||
countrySheetRef.current?.close();
|
||||
setTimeout(() => setCountrySearch(''), 300);
|
||||
}, []);
|
||||
|
||||
const filteredCountries = useMemo(() => {
|
||||
if (!countrySearch.trim()) return countryResponse || [];
|
||||
const q = countrySearch.toLowerCase().trim();
|
||||
return (countryResponse || []).filter((c: any) => c.name?.toLowerCase().includes(q));
|
||||
}, [countryResponse, countrySearch]);
|
||||
|
||||
const headerInfo = getHeaderInfo(personType);
|
||||
|
||||
const isYattOrBand = personType === 'yatt' || personType === 'band';
|
||||
const isLegal = personType === 'legal_entity';
|
||||
|
||||
const { mutate: fetchInfo } = useMutation({
|
||||
mutationFn: (body: {
|
||||
value: string;
|
||||
type: string;
|
||||
passport_series?: string;
|
||||
passport_number?: string;
|
||||
}) => auth_api.get_info(body),
|
||||
onSuccess: (res) => {
|
||||
setInfo(res.data.data);
|
||||
setLoading(false);
|
||||
setDirectorJshshr('');
|
||||
setDirectorInfo(null);
|
||||
setErrorDirectorInfo(null);
|
||||
},
|
||||
onError: () => {
|
||||
setInfo(null);
|
||||
setLoading(false);
|
||||
setDirectorJshshr('');
|
||||
setDirectorInfo(null);
|
||||
setErrorDirectorInfo(null);
|
||||
},
|
||||
});
|
||||
|
||||
const { mutate: fetchDirectorInfo } = useMutation({
|
||||
mutationFn: (body: { value: string }) => auth_api.get_director_info(body),
|
||||
onSuccess: (res) => {
|
||||
const directorData = res.data;
|
||||
const rows: Array<{ inn: string }> = directorData?.data?.entity?.name?.rows ?? [];
|
||||
const innMatch = rows.some((row) => row.inn === inn);
|
||||
|
||||
if (!innMatch) {
|
||||
setDirectorInfo(null);
|
||||
setErrorDirectorInfo(t("Bu direktor ko'rsatilgan tashkilotga tegishli emas"));
|
||||
setDirectorLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setDirectorInfo(directorData);
|
||||
setDirectorLoading(false);
|
||||
setErrorDirectorInfo(null);
|
||||
},
|
||||
onError: (error: AxiosError) => {
|
||||
const err = error.response?.data as {
|
||||
status: boolean;
|
||||
data: {
|
||||
detail: string;
|
||||
error: { message: string };
|
||||
status_code: number;
|
||||
};
|
||||
};
|
||||
setDirectorInfo(null);
|
||||
setErrorDirectorInfo(err?.data?.detail ?? t('Xatolik yuz berdi'));
|
||||
setDirectorLoading(false);
|
||||
},
|
||||
});
|
||||
|
||||
const handleJshshrChange = useCallback(
|
||||
(text: string) => {
|
||||
const v = normalizeDigits(text).slice(0, 14);
|
||||
setJshshr(v);
|
||||
if (v.length === 14) {
|
||||
setLoading(true);
|
||||
if (personType) {
|
||||
fetchInfo({ value: v, type: personType });
|
||||
}
|
||||
}
|
||||
},
|
||||
[setJshshr, fetchInfo, personType]
|
||||
);
|
||||
|
||||
const handleInnChange = useCallback(
|
||||
(text: string) => {
|
||||
const v = normalizeDigits(text).slice(0, 9);
|
||||
setInn(v);
|
||||
if (v.length === 9) {
|
||||
setLoading(true);
|
||||
if (personType) {
|
||||
fetchInfo({ value: v, type: personType });
|
||||
}
|
||||
}
|
||||
},
|
||||
[setInn, fetchInfo, personType]
|
||||
);
|
||||
|
||||
const handlePassportSeriesChange = useCallback(
|
||||
(text: string) => {
|
||||
const v = text
|
||||
.toUpperCase()
|
||||
.replace(/[^A-Z]/g, '')
|
||||
.slice(0, 2);
|
||||
setPassportSeries(v);
|
||||
if (personType && passportNumber.length === 7 && jshshr.length === 14) {
|
||||
setLoading(true);
|
||||
fetchInfo({
|
||||
type: personType,
|
||||
passport_number: passportNumber,
|
||||
passport_series: v,
|
||||
value: jshshr,
|
||||
});
|
||||
}
|
||||
},
|
||||
[setPassportSeries, passportNumber, jshshr, personType, fetchInfo]
|
||||
);
|
||||
|
||||
const handlePassportNumberChange = useCallback(
|
||||
(text: string) => {
|
||||
const v = normalizeDigits(text).slice(0, 7);
|
||||
setPassportNumber(v);
|
||||
if (personType && passportSeries.length === 2 && jshshr.length === 14) {
|
||||
setLoading(true);
|
||||
fetchInfo({
|
||||
type: personType,
|
||||
passport_number: v,
|
||||
passport_series: passportSeries,
|
||||
value: jshshr,
|
||||
});
|
||||
}
|
||||
},
|
||||
[setPassportNumber, passportSeries, jshshr, personType, fetchInfo]
|
||||
);
|
||||
|
||||
const handleDirectorJshshrChange = useCallback(
|
||||
(text: string) => {
|
||||
const v = normalizeDigits(text).slice(0, 14);
|
||||
setDirectorJshshr(v);
|
||||
setDirectorInfo(null);
|
||||
setErrorDirectorInfo(null);
|
||||
if (v.length === 14) {
|
||||
setDirectorLoading(true);
|
||||
fetchDirectorInfo({ value: v });
|
||||
}
|
||||
},
|
||||
[fetchDirectorInfo]
|
||||
);
|
||||
|
||||
const hasValidName = Boolean(info?.name || info?.fullName);
|
||||
const hasValidInfo = Boolean(info?.lastname || info?.firstname || info?.middlename);
|
||||
|
||||
const isValid = (() => {
|
||||
const phoneValid = phone.length === 9;
|
||||
const referalValid = referal.length > 0;
|
||||
const countryValid = Boolean(selectedCountry && selectedCountry !== 'all');
|
||||
|
||||
if (isYattOrBand) {
|
||||
return (
|
||||
phoneValid &&
|
||||
referalValid &&
|
||||
countryValid &&
|
||||
jshshr.length === 14 &&
|
||||
passportSeries.length === 2 &&
|
||||
passportNumber.length === 7 &&
|
||||
info
|
||||
);
|
||||
}
|
||||
|
||||
if (isLegal) {
|
||||
return (
|
||||
phoneValid &&
|
||||
referalValid &&
|
||||
countryValid &&
|
||||
inn.length === 9 &&
|
||||
info &&
|
||||
directorJshshr.length === 14 &&
|
||||
directorInfo
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
})();
|
||||
|
||||
const handleContinue = () => {
|
||||
const directorFullName = isLegal
|
||||
? (directorInfo?.data?.entrepreneur?.rows[0]?.entrepreneur ?? '')
|
||||
: `${info?.firstname ?? ''} ${info?.lastname ?? ''} ${info?.middlename ?? ''}`.trim();
|
||||
|
||||
const countryObj = countryResponse?.find((c: any) => c.flag?.toUpperCase() === selectedCountry);
|
||||
|
||||
router.push({
|
||||
pathname: '/(auth)/select-category',
|
||||
params: {
|
||||
phone,
|
||||
stir: isLegal ? inn : jshshr,
|
||||
person_type: personType ?? '',
|
||||
passport_series: passportSeries,
|
||||
passport_number: passportNumber,
|
||||
director_full_name: directorFullName,
|
||||
referal: referal,
|
||||
first_name: info?.firstname ?? '',
|
||||
last_name: info?.lastname ?? '',
|
||||
middle_name: info?.middlename ?? '',
|
||||
country: countryObj?.name ?? '',
|
||||
country_id: selectedCountry,
|
||||
},
|
||||
});
|
||||
};
|
||||
const valid =
|
||||
phone.length === 9 &&
|
||||
(stir.length === 9 || stir.length === 14) &&
|
||||
info &&
|
||||
hasValidName &&
|
||||
isDirectorTinValid &&
|
||||
error === null;
|
||||
|
||||
return (
|
||||
// ✅ Fragment — BottomSheet tashqarida bo'lishi uchun
|
||||
<>
|
||||
<KeyboardAwareScrollView
|
||||
enableOnAndroid
|
||||
@@ -356,12 +262,11 @@ export default function RegisterFormScreen() {
|
||||
extraScrollHeight={120}
|
||||
style={styles.keyboardScroll}
|
||||
>
|
||||
{/* ✅ TouchableWithoutFeedback yo'q — onStartShouldSetResponder ishlatildi */}
|
||||
<View
|
||||
style={styles.container}
|
||||
onStartShouldSetResponder={() => {
|
||||
Keyboard.dismiss();
|
||||
return false; // false — child elementlar (buttonlar) ham ishlaydi
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<LinearGradient
|
||||
@@ -375,168 +280,90 @@ export default function RegisterFormScreen() {
|
||||
|
||||
<AuthHeader />
|
||||
|
||||
{/* ✅ SafeAreaView va ichki ScrollView yo'q — to'g'ridan View */}
|
||||
<SafeAreaView style={{ flex: 1 }} edges={['bottom']}>
|
||||
<View style={styles.scrollContent}>
|
||||
<View style={styles.header}>
|
||||
<View style={styles.iconContainer}>
|
||||
<LinearGradient
|
||||
colors={headerInfo.gradient}
|
||||
colors={['#10b981', '#059669']}
|
||||
style={styles.iconGradient}
|
||||
start={{ x: 0, y: 0 }}
|
||||
end={{ x: 1, y: 1 }}
|
||||
>
|
||||
{headerInfo.icon}
|
||||
<UserPlus size={32} color="#fff" />
|
||||
</LinearGradient>
|
||||
</View>
|
||||
<Text style={styles.title}>{t(headerInfo.label)}</Text>
|
||||
<Text style={styles.subtitle}>
|
||||
{isYattOrBand
|
||||
? t("JSHSHR va passport ma'lumotlarini kiriting")
|
||||
: t('INN raqamini kiriting')}
|
||||
</Text>
|
||||
<Text style={styles.title}>{t('Ro\'yxatdan o\'tish')}</Text>
|
||||
</View>
|
||||
|
||||
<View style={styles.card}>
|
||||
<View style={styles.formGap}>
|
||||
{/* ---- YATT / BAND ---- */}
|
||||
{isYattOrBand && (
|
||||
<>
|
||||
<View>
|
||||
<Text style={styles.label}>{t('JSHSHR')}</Text>
|
||||
<View style={styles.input}>
|
||||
<Hash size={18} color="#94a3b8" />
|
||||
<TextInput
|
||||
value={jshshr}
|
||||
keyboardType="numeric"
|
||||
placeholder={t('JSHSHR kiriting (14 raqam)')}
|
||||
placeholderTextColor="#94a3b8"
|
||||
style={styles.textInput}
|
||||
onChangeText={handleJshshrChange}
|
||||
maxLength={14}
|
||||
testID="jshshr-input"
|
||||
/>
|
||||
{loading && jshshr.length >= 14 && (
|
||||
<ActivityIndicator size="small" color="#3b82f6" />
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View>
|
||||
<Text style={styles.label}>{t('Passport seriya va raqami')}</Text>
|
||||
<View style={styles.passportRow}>
|
||||
<View style={[styles.input, styles.passportSeries]}>
|
||||
<TextInput
|
||||
value={passportSeries}
|
||||
placeholder="AA"
|
||||
placeholderTextColor="#94a3b8"
|
||||
style={styles.textInput}
|
||||
onChangeText={handlePassportSeriesChange}
|
||||
maxLength={2}
|
||||
autoCapitalize="characters"
|
||||
testID="passport-series-input"
|
||||
/>
|
||||
</View>
|
||||
<View style={[styles.input, styles.passportNumber]}>
|
||||
<TextInput
|
||||
value={passportNumber}
|
||||
keyboardType="numeric"
|
||||
placeholder="1234567"
|
||||
placeholderTextColor="#94a3b8"
|
||||
style={styles.textInput}
|
||||
onChangeText={handlePassportNumberChange}
|
||||
maxLength={7}
|
||||
testID="passport-number-input"
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* ---- LEGAL ENTITY: INN ---- */}
|
||||
{isLegal && (
|
||||
<View>
|
||||
<View>
|
||||
<Text style={styles.label}>{t('INN')}</Text>
|
||||
<View style={styles.input}>
|
||||
<Hash size={18} color="#94a3b8" />
|
||||
<TextInput
|
||||
value={inn}
|
||||
keyboardType="numeric"
|
||||
placeholder={t('INN kiriting (9 raqam)')}
|
||||
placeholderTextColor="#94a3b8"
|
||||
style={styles.textInput}
|
||||
onChangeText={handleInnChange}
|
||||
maxLength={9}
|
||||
testID="inn-input"
|
||||
/>
|
||||
{loading && inn.length >= 9 && (
|
||||
<ActivityIndicator size="small" color="#3b82f6" />
|
||||
<Text style={styles.label}>{t('Davlat')}</Text>
|
||||
<TouchableOpacity
|
||||
style={[
|
||||
styles.input,
|
||||
styles.inputDisabled,
|
||||
]}
|
||||
onPress={openCountrySheet}
|
||||
activeOpacity={0.7}
|
||||
testID="country-select"
|
||||
disabled
|
||||
>
|
||||
{countryLoading ? (
|
||||
<ActivityIndicator size="small" color="#3b82f6" style={{ flex: 1 }} />
|
||||
) : (
|
||||
<>
|
||||
<Image
|
||||
source={{ uri: `https://flagcdn.com/w320/${selectedCountry.toLowerCase()}.png` }}
|
||||
style={{ width: 30, height: 15 }}
|
||||
resizeMode="cover"
|
||||
/>
|
||||
<Text
|
||||
style={[
|
||||
styles.textInput,
|
||||
{ color: '#94a3b8' },
|
||||
]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{selectedCountryName}
|
||||
</Text>
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
<ChevronDown size={18} color={'#cbd5e1'} />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* ---- LEGAL ENTITY: Kompaniya ma'lumoti ---- */}
|
||||
{isLegal &&
|
||||
info &&
|
||||
(hasValidName ? (
|
||||
<View style={styles.infoBox}>
|
||||
<Text style={styles.infoLabel}>{t('Tashkilot')}</Text>
|
||||
<Text style={styles.infoText}>{info.fullName || info.name}</Text>
|
||||
</View>
|
||||
) : hasValidInfo ? (
|
||||
<View style={[styles.infoBox, { flexDirection: 'row', gap: 5 }]}>
|
||||
<Text style={styles.infoLabel}>{t('Tashkilot')}</Text>
|
||||
<Text style={styles.infoText}>{info.firstname}</Text>
|
||||
<Text style={styles.infoText}>{info.lastname}</Text>
|
||||
<Text style={styles.infoText}>{info.middlename}</Text>
|
||||
</View>
|
||||
) : (
|
||||
<View style={styles.errorBox}>
|
||||
<Text style={styles.errorText}>{t('Tashkilot topilmadi')}</Text>
|
||||
</View>
|
||||
))}
|
||||
<View>
|
||||
<Text style={styles.label}>{t('STIR')}</Text>
|
||||
<View style={styles.input}>
|
||||
<Hash size={18} color="#94a3b8" />
|
||||
<TextInput
|
||||
value={stir}
|
||||
keyboardType="numeric"
|
||||
placeholder={t('STIR')}
|
||||
placeholderTextColor="#94a3b8"
|
||||
style={{ flex: 1, color: "black" }}
|
||||
onChangeText={(text) => {
|
||||
const v = normalizeDigits(text).slice(0, 14);
|
||||
setStir(v);
|
||||
|
||||
{/* ---- LEGAL ENTITY: Direktor JSHSHR ---- */}
|
||||
{isLegal && info && (
|
||||
<View>
|
||||
<Text style={styles.label}>{t('Direktor JSHSHR')}</Text>
|
||||
<View style={styles.input}>
|
||||
<Hash size={18} color="#94a3b8" />
|
||||
<TextInput
|
||||
value={directorJshshr}
|
||||
keyboardType="numeric"
|
||||
placeholder={t('Direktor JSHSHR (14 raqam)')}
|
||||
placeholderTextColor="#94a3b8"
|
||||
style={styles.textInput}
|
||||
onChangeText={handleDirectorJshshrChange}
|
||||
maxLength={14}
|
||||
testID="director-jshshr-input"
|
||||
/>
|
||||
{directorLoading && directorJshshr.length >= 14 && (
|
||||
<ActivityIndicator size="small" color="#3b82f6" />
|
||||
)}
|
||||
</View>
|
||||
|
||||
{directorInfo && (
|
||||
<View style={[styles.infoBox, { marginTop: 8 }]}>
|
||||
<Text style={styles.infoLabel}>{t('Direktor')}</Text>
|
||||
<Text style={styles.infoText}>
|
||||
{directorInfo?.data?.entrepreneur?.rows[0]?.entrepreneur}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
|
||||
{directorInfoError && (
|
||||
<View style={[styles.errorBox, { marginTop: 8 }]}>
|
||||
<Text style={styles.errorText}>{directorInfoError}</Text>
|
||||
</View>
|
||||
)}
|
||||
if (v.length === 9 || v.length === 14) {
|
||||
setLoading(true);
|
||||
mutate(v);
|
||||
setRegionId(null)
|
||||
setDistrictId(null)
|
||||
setRegion(null)
|
||||
setDistrict(null)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{loading && <ActivityIndicator size="small" />}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* ---- Referal ---- */}
|
||||
<View>
|
||||
<Text style={styles.label}>{t('Referal')}</Text>
|
||||
<View style={styles.input}>
|
||||
@@ -553,7 +380,6 @@ export default function RegisterFormScreen() {
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* ---- Telefon ---- */}
|
||||
<View>
|
||||
<Text style={styles.label}>{t('Telefon raqami')}</Text>
|
||||
<View style={styles.input}>
|
||||
@@ -563,38 +389,62 @@ export default function RegisterFormScreen() {
|
||||
placeholder="90 123 45 67"
|
||||
placeholderTextColor="#94a3b8"
|
||||
keyboardType="phone-pad"
|
||||
style={styles.textInput}
|
||||
onChangeText={(t) => setPhone(normalizeDigits(t).slice(0, 9))}
|
||||
testID="phone-input"
|
||||
style={{ flex: 1 }}
|
||||
onChangeText={(t) => setPhone(normalizeDigits(t))}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* ---- YATT/BAND info ---- */}
|
||||
{!isLegal &&
|
||||
info &&
|
||||
(hasValidName ? (
|
||||
<View style={styles.infoBox}>
|
||||
<Text style={styles.infoText}>{info.fullName || info.name}</Text>
|
||||
{hasDirectorTin && (
|
||||
<View>
|
||||
<Text style={styles.label}>{t('Direktor STIR')}</Text>
|
||||
<View style={[styles.input, { backgroundColor: isDirectorTinValid ? '#f0fdf4' : '#f8fafc' }]}>
|
||||
<Hash size={18} color="#94a3b8" />
|
||||
<TextInput
|
||||
value={directorTinInput}
|
||||
keyboardType="numeric"
|
||||
placeholder={t('Direktor STIR')}
|
||||
placeholderTextColor="#94a3b8"
|
||||
style={{ flex: 1 }}
|
||||
maxLength={14}
|
||||
onChangeText={(t) => setDirectorTinInput(normalizeDigits(t))}
|
||||
/>
|
||||
</View>
|
||||
) : hasValidInfo ? (
|
||||
<View style={[styles.infoBox, { flexDirection: 'row', gap: 5 }]}>
|
||||
<Text style={styles.infoText}>{info.firstname}</Text>
|
||||
<Text style={styles.infoText}>{info.lastname}</Text>
|
||||
<Text style={styles.infoText}>{info.middlename}</Text>
|
||||
</View>
|
||||
) : (
|
||||
<View style={styles.errorBox}>
|
||||
<Text style={styles.errorText}>{t('Foydalanuvchi topilmadi')}</Text>
|
||||
</View>
|
||||
))}
|
||||
|
||||
{/* ---- Davom etish tugmasi ---- */}
|
||||
{directorTinInput.length === 14 && !isDirectorTinValid && (
|
||||
<Text style={styles.error}>{t('Direktor STIR noto‘g‘ri')}</Text>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
|
||||
{error !== null ?
|
||||
<Text style={styles.notFound}>{t(error)}</Text>
|
||||
: info && hasValidName &&
|
||||
<Text style={styles.info}>{info.fullName || info.name}</Text>
|
||||
}
|
||||
|
||||
<TouchableOpacity
|
||||
disabled={!isValid}
|
||||
style={[styles.btn, !isValid && styles.disabled]}
|
||||
onPress={handleContinue}
|
||||
testID="continue-button"
|
||||
disabled={!valid}
|
||||
style={[styles.btn, !valid && styles.disabled]}
|
||||
onPress={() => {
|
||||
if (error === null) {
|
||||
router.push({
|
||||
pathname: '/(auth)/select-category',
|
||||
params: {
|
||||
phone,
|
||||
first_name: stir.length === 9 ? info?.director : info?.fullName,
|
||||
last_name: stir.length === 9 ? info?.director : info?.fullName,
|
||||
company_name: info?.name,
|
||||
district: districtId !== null ? districtId : regionId,
|
||||
address: districtId !== null ? districtId : regionId,
|
||||
director_full_name: stir.length === 9 ? info?.director : info?.fullName,
|
||||
stir,
|
||||
referal,
|
||||
person_type: stir.length === 9 ? 'legal_entity' : info?.selfEmployment ? 'band' : info?.isItd ? 'ytt' : 'ytt',
|
||||
},
|
||||
})
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Text style={styles.btnText}>{t('Davom etish')}</Text>
|
||||
</TouchableOpacity>
|
||||
@@ -602,10 +452,9 @@ export default function RegisterFormScreen() {
|
||||
</View>
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
</View>
|
||||
</KeyboardAwareScrollView>
|
||||
</View >
|
||||
</KeyboardAwareScrollView >
|
||||
|
||||
{/* ✅ BottomSheet KeyboardAwareScrollView TASHQARISIDA */}
|
||||
<BottomSheet
|
||||
ref={countrySheetRef}
|
||||
index={-1}
|
||||
@@ -682,13 +531,12 @@ export default function RegisterFormScreen() {
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</BottomSheet>
|
||||
</BottomSheet >
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
// ✅ KeyboardAwareScrollView uchun style
|
||||
keyboardScroll: {
|
||||
flex: 1,
|
||||
backgroundColor: '#0f172a',
|
||||
@@ -877,6 +725,7 @@ const styles = StyleSheet.create({
|
||||
infoBox: {
|
||||
backgroundColor: '#f0fdf4',
|
||||
padding: 14,
|
||||
marginTop: 10,
|
||||
borderRadius: 14,
|
||||
borderWidth: 1,
|
||||
borderColor: '#bbf7d0',
|
||||
@@ -948,4 +797,26 @@ const styles = StyleSheet.create({
|
||||
backgroundColor: '#f1f5f9',
|
||||
borderColor: '#e2e8f0',
|
||||
},
|
||||
|
||||
info: {
|
||||
padding: 12,
|
||||
borderRadius: 12,
|
||||
fontWeight: '700',
|
||||
backgroundColor: '#f0fdf4',
|
||||
},
|
||||
error: {
|
||||
color: '#dc2626',
|
||||
fontSize: 12,
|
||||
marginTop: 4,
|
||||
fontWeight: '600',
|
||||
},
|
||||
notFound: {
|
||||
backgroundColor: '#fef2f2',
|
||||
padding: 12,
|
||||
borderRadius: 12,
|
||||
fontWeight: '700',
|
||||
color: '#dc2626',
|
||||
borderWidth: 1,
|
||||
borderColor: '#fecaca',
|
||||
},
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import createContextHook from '@nkzw/create-context-hook';
|
||||
import { useState } from 'react';
|
||||
import { GetDirectorInfoResponse } from '../../login/lib/api';
|
||||
import { GetInfo } from '../../login/lib/api';
|
||||
|
||||
export type PersonType = 'yatt' | 'band' | 'legal_entity' | null;
|
||||
|
||||
@@ -19,14 +19,14 @@ interface RegisterState {
|
||||
setPassportNumber: (number: string) => void;
|
||||
inn: string;
|
||||
setInn: (inn: string) => void;
|
||||
info: any;
|
||||
setInfo: (info: any) => void;
|
||||
info: GetInfo | null;
|
||||
setInfo: (info: GetInfo | null) => void;
|
||||
reset_full: () => void;
|
||||
reset: () => void;
|
||||
directorJshshr: string;
|
||||
setDirectorJshshr: (directorJshshr: string) => void;
|
||||
directorInfo: GetDirectorInfoResponse | null;
|
||||
setDirectorInfo: (directorInfo: GetDirectorInfoResponse | null) => void;
|
||||
directorInfo: GetInfo | null;
|
||||
setDirectorInfo: (directorInfo: GetInfo | null) => void;
|
||||
}
|
||||
|
||||
export const [RegisterProvider, useRegister] = createContextHook<RegisterState>(() => {
|
||||
@@ -37,9 +37,9 @@ export const [RegisterProvider, useRegister] = createContextHook<RegisterState>(
|
||||
const [passportSeries, setPassportSeries] = useState<string>('');
|
||||
const [passportNumber, setPassportNumber] = useState<string>('');
|
||||
const [inn, setInn] = useState<string>('');
|
||||
const [info, setInfo] = useState<any>(null);
|
||||
const [info, setInfo] = useState<GetInfo | null>(null);
|
||||
const [directorJshshr, setDirectorJshshr] = useState<string>('');
|
||||
const [directorInfo, setDirectorInfo] = useState<GetDirectorInfoResponse | null>(null);
|
||||
const [directorInfo, setDirectorInfo] = useState<GetInfo | null>(null);
|
||||
|
||||
const reset_full = () => {
|
||||
setPersonType(null);
|
||||
|
||||
Reference in New Issue
Block a user