added login modal

This commit is contained in:
Samandar Turgunboyev
2025-11-24 10:52:21 +05:00
parent 9aac17072f
commit 684d09e6b5
23 changed files with 1871 additions and 1351 deletions

View File

@@ -12,6 +12,7 @@ import { authApi } from 'api/auth';
import { registerPayload } from 'api/auth/type';
import { Branch, branchApi } from 'api/branch';
import AppText from 'components/AppText';
import ErrorNotification from 'components/ErrorNotification';
import formatPhone from 'helpers/formatPhone';
import { useEffect, useRef, useState } from 'react';
import { Controller, useForm } from 'react-hook-form';
@@ -57,7 +58,8 @@ const recommended = [
const FirstStep = ({ onNext }: { onNext: () => void }) => {
const { t } = useTranslation();
const [filialDropdownVisible, setFilialDropdownVisible] = useState(false);
const [error, setError] = useState<string>();
const [error, setError] = useState<string>('Xatolik yuz berdi');
const [visible, setVisible] = useState(false);
const { setUser } = useUserStore(state => state);
const { data: branchList } = useQuery({
queryKey: ['branchList'],
@@ -69,8 +71,14 @@ const FirstStep = ({ onNext }: { onNext: () => void }) => {
onSuccess: res => {
onNext();
},
onError: err => {
setError('Xatolik yuz berdi');
onError: (err: any) => {
setVisible(true);
setError(
err?.response?.data?.message ||
err?.response?.message ||
'Xatolik yuz berdi',
);
},
});
@@ -104,6 +112,27 @@ const FirstStep = ({ onNext }: { onNext: () => void }) => {
const addressRef = useRef<TextInput>(null);
const onSubmit = (data: FirstStepFormType) => {
if (
errors.address ||
errors.branchId ||
errors.firstName ||
errors.lastName ||
errors.phoneNumber ||
errors.recommend
) {
const firstError =
errors.address?.message ||
errors.branchId?.message ||
errors.firstName?.message ||
errors.lastName?.message ||
errors.phoneNumber?.message ||
errors.recommend?.message ||
'Xatolik yuz berdi';
setError(firstError);
setVisible(true);
return;
}
setUser({
firstName: data.firstName,
lastName: data.lastName,
@@ -123,6 +152,20 @@ const FirstStep = ({ onNext }: { onNext: () => void }) => {
});
};
const onErrorSubmit = (errors: any) => {
const firstError =
errors.address?.message ||
errors.branchId?.message ||
errors.firstName?.message ||
errors.lastName?.message ||
errors.phoneNumber?.message ||
errors.recommend?.message;
setError(
firstError ? "Ma'lumotlarni to'liq kiriting" : 'Xatolik yuz berdi',
);
setVisible(true);
};
useEffect(() => {
if (route.params?.termsAccepted) {
setTermsAccepted(true);
@@ -194,6 +237,11 @@ const FirstStep = ({ onNext }: { onNext: () => void }) => {
{t("Ro'yxatdan o'tish")}
</AppText>
<ErrorNotification
setVisible={setVisible}
error={error}
visible={visible}
/>
{/* Ism */}
<Controller
control={control}
@@ -211,11 +259,6 @@ const FirstStep = ({ onNext }: { onNext: () => void }) => {
returnKeyType="next"
onSubmitEditing={() => lastNameRef.current?.focus()}
/>
{errors.firstName && (
<AppText style={RegisterStyle.errorText}>
{t(errors.firstName.message || '')}
</AppText>
)}
</View>
)}
/>
@@ -239,11 +282,6 @@ const FirstStep = ({ onNext }: { onNext: () => void }) => {
returnKeyType="next"
onSubmitEditing={() => phoneRef.current?.focus()}
/>
{errors.lastName && (
<AppText style={RegisterStyle.errorText}>
{t(errors.lastName.message || '')}
</AppText>
)}
</View>
)}
/>
@@ -280,11 +318,6 @@ const FirstStep = ({ onNext }: { onNext: () => void }) => {
() => setFilialDropdownVisible(true) // ❗ Branch select ochiladi
}
/>
{errors.phoneNumber && (
<AppText style={RegisterStyle.errorText}>
{t(errors.phoneNumber.message || '')}
</AppText>
)}
</View>
);
}}
@@ -354,11 +387,6 @@ const FirstStep = ({ onNext }: { onNext: () => void }) => {
</ScrollView>
</View>
)}
{errors.branchId && (
<AppText style={RegisterStyle.errorText}>
{t(errors.branchId.message || '')}
</AppText>
)}
</View>
)}
/>
@@ -386,11 +414,6 @@ const FirstStep = ({ onNext }: { onNext: () => void }) => {
() => setRecommendedDropdownVisible(true) // ❗ recommend select ochiladi
}
/>
{errors.address && (
<AppText style={RegisterStyle.errorText}>
{t(errors.address.message || '')}
</AppText>
)}
</View>
)}
/>
@@ -452,16 +475,6 @@ const FirstStep = ({ onNext }: { onNext: () => void }) => {
</ScrollView>
</View>
)}
{errors.recommend && (
<AppText style={RegisterStyle.errorText}>
{t(errors.recommend.message || '')}
</AppText>
)}
{error && (
<AppText style={[RegisterStyle.errorText]}>
{t(error)}
</AppText>
)}
</View>
)}
/>
@@ -513,7 +526,7 @@ const FirstStep = ({ onNext }: { onNext: () => void }) => {
</TouchableOpacity>
</View>
<TouchableOpacity
onPress={handleSubmit(onSubmit)}
onPress={handleSubmit(onSubmit, onErrorSubmit)}
style={[
RegisterStyle.button,
(!termsAccepted || isPending) &&