register address

This commit is contained in:
Samandar Turgunboyev
2026-03-26 14:23:58 +05:00
parent fee9213c59
commit a671706fb3
12 changed files with 555 additions and 311 deletions

View File

@@ -25,6 +25,15 @@ interface Category {
is_leaf: boolean;
}
type DRFError = {
[key: string]: Array<
| string
| {
[key: string]: string[];
}
>;
};
export default function CategorySelectScreen() {
const router = useRouter();
const { t } = useTranslation();
@@ -74,28 +83,55 @@ export default function CategorySelectScreen() {
referral: string;
first_name: string;
last_name: string;
district: number;
district: string;
company_name: string;
address: number;
address: string;
}) => auth_api.register(body),
onSuccess: async () => {
router.replace('/(auth)/register-confirm');
await AsyncStorage.setItem('phone', phone);
},
onError: (err: AxiosError) => {
const errMessage = (err.response?.data as any)?.data?.stir?.[0];
const errMessageDetail = (err.response?.data as any)?.data?.detail;
const errMessageReffral = (err.response?.data as any).data.referral[0];
const errMessageDetailData = (err.response?.data as any)?.data;
onError: (error: AxiosError<DRFError>) => {
const data = error.response?.data as any;
const message =
errMessage ||
errMessageReffral ||
errMessageDetail ||
errMessageDetailData ||
t('Xatolik yuz berdi');
let message = t('Xatolik yuz berdi');
Toast.error(String(message));
if (data) {
const source = data.data || data; // 🔥 ba'zida data ichida keladi
if (typeof source === 'object') {
const firstKey = Object.keys(source)[0];
const firstValue = source[firstKey];
// ✅ 1⃣ Agar oddiy string array bolsa
if (Array.isArray(firstValue) && typeof firstValue[0] === 'string') {
message = firstValue[0];
}
// ✅ 2⃣ Agar nested object bolsa
else if (Array.isArray(firstValue) && typeof firstValue[0] === 'object') {
const firstErrorObj = firstValue[0];
const innerKey = Object.keys(firstErrorObj)[0];
const innerValue = firstErrorObj[innerKey];
if (Array.isArray(innerValue)) {
message = innerValue[0];
}
}
// ✅ 3⃣ Agar string bolsa
else if (typeof firstValue === 'string') {
message = firstValue;
}
}
}
// ❗ Network error fallback
if (!error.response) {
message = error.message;
}
Toast.error(message);
}
});
@@ -163,8 +199,8 @@ export default function CategorySelectScreen() {
director_full_name,
first_name,
last_name,
district: Number(district),
address: Number(address),
district: district,
address: address,
company_name
});
}}