register address
This commit is contained in:
@@ -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 bo‘lsa
|
||||
if (Array.isArray(firstValue) && typeof firstValue[0] === 'string') {
|
||||
message = firstValue[0];
|
||||
}
|
||||
|
||||
// ✅ 2️⃣ Agar nested object bo‘lsa
|
||||
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 bo‘lsa
|
||||
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
|
||||
});
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user