fix(lint&types): resolve all lint warnings, typecheck errors and effect state updates across frontend application and admin panel

This commit is contained in:
parsa aghaei committed 2026-08-03 10:13:11 +03:30
1 parent 920dd532e8
commit c1b2f416ed
29 files changed
+442 -352

No files matched your search

+28 -9
View File
@@ -94,7 +94,16 @@ export const useUserStore = create<UserStore>()(
addAddress: async (address) => {
try {
// Remove ID so backend generates UUID
const { id, ...addressData } = address;
const addressData = {
title: address.title,
receptorName: address.receptorName,
phone: address.phone,
province: address.province,
city: address.city,
detail: address.detail,
zipCode: address.zipCode,
isDefault: address.isDefault,
};
await api.post('/users/addresses', addressData);
await useUserStore.getState().fetchProfile();
} catch (error) {
@@ -104,7 +113,16 @@ export const useUserStore = create<UserStore>()(
},
updateAddress: async (id, updated) => {
try {
const { id: _, ...addressData } = updated;
const addressData = {
title: updated.title,
receptorName: updated.receptorName,
phone: updated.phone,
province: updated.province,
city: updated.city,
detail: updated.detail,
zipCode: updated.zipCode,
isDefault: updated.isDefault,
};
await api.patch(`/users/addresses/${id}`, addressData);
await useUserStore.getState().fetchProfile();
} catch (error) {
@@ -201,14 +219,15 @@ export const useUserStore = create<UserStore>()(
return;
}
set((state) => {
const pd = profileData as unknown as Record<string, unknown>;
const backendWallet = Number(profileData.walletBalance || 0);
const backendCharity = Number(profileData.charityDonationTotal || 0);
const backendTransactions = (profileData as any).walletTransactions?.map((t: any) => ({
const backendTransactions = (pd.walletTransactions as Array<{ id: string; type: string; amount: number; createdAt: string; status: string }>)?.map((t) => ({
id: t.id,
type: t.type === 'deposit' ? 'top_up' : 'purchase',
type: (t.type === 'deposit' ? 'top_up' : 'purchase') as Transaction['type'],
amount: Number(t.amount),
date: t.createdAt,
status: t.status === 'completed' ? 'success' : t.status === 'failed' ? 'failed' : 'pending'
status: (t.status === 'completed' ? 'success' : t.status === 'failed' ? 'failed' : 'pending') as Transaction['status']
})) || [];
return {
@@ -221,7 +240,7 @@ export const useUserStore = create<UserStore>()(
mobile: profileData.mobile || "",
walletBalance: backendWallet,
charityDonationTotal: backendCharity,
addresses: (profileData as any).addresses?.length > 0 ? (profileData as any).addresses : state.profile.addresses,
addresses: Array.isArray(pd.addresses) && pd.addresses.length > 0 ? (pd.addresses as Address[]) : state.profile.addresses,
transactions: backendTransactions.length > 0 ? backendTransactions : state.profile.transactions
}
};
@@ -230,11 +249,11 @@ export const useUserStore = create<UserStore>()(
// Sync orders list to CartStore while preserving local petId & address mappings
if (profileData.orders) {
const currentLocalOrders = useCartStore.getState().orders;
const mergedOrders = profileData.orders.map((bo: any) => {
const mergedOrders = (profileData.orders as Record<string, unknown>[]).map((bo) => {
const localMatch = currentLocalOrders.find(lo => lo.id === bo.id);
return {
...bo,
petId: bo.petId || bo.pet?.id || localMatch?.petId,
petId: bo.petId || (bo.pet as { id?: string })?.id || localMatch?.petId,
shippingAddress: bo.shippingAddress || localMatch?.shippingAddress
};
});
@@ -242,7 +261,7 @@ export const useUserStore = create<UserStore>()(
}
// Sync pets list to PetStore
if (profileData.pets) {
usePetStore.getState().setPets(profileData.pets);
usePetStore.getState().setPets(profileData.pets as Record<string, unknown>[]);
}
} catch (error) {
console.error("Failed to fetch user profile:", error);