update response error

This commit is contained in:
Raja Oktafrianto
2025-05-12 15:57:22 +07:00
parent 109939b0b4
commit a0bc7d13a1
2 changed files with 50 additions and 22 deletions

View File

@ -64,7 +64,7 @@ const AddDialog = () => {
const [customers, setCustomers] = useState<CustomerProps[]>([]);
const { reload } = useDataGrid();
const { PostData, PutData } = useCallApi();
const [errors, setErrors] = useState<Record<string, string>>({});
const initialState = {
@ -164,11 +164,12 @@ const AddDialog = () => {
toast.error(response?.message || 'Failed to create transfer type');
return false;
}
} catch (error) {
} catch (error: any) {
toast.error(
error instanceof Error
? error.message
: 'An error occurred while creating transfer type'
error?.response?.data?.message ||
(error instanceof Error
? error.message
: 'An error occurred while creating transfer type')
);
return false;
}
@ -203,8 +204,9 @@ const AddDialog = () => {
order_direction: sorting[0].desc ? 'DESC' : 'ASC'
});
setCustomers(response?.data.list);
} catch (error) {
} catch (error: any) {
console.error('Error fetching customer', error);
toast.error(error?.response?.data?.message || 'Failed to fetch customer data');
}
};
@ -284,7 +286,9 @@ const AddDialog = () => {
}
}}
/>
{errors.name && <span className="text-red-500 text-xs mt-1">{errors.name}</span>}
{errors.name && (
<span className="text-red-500 text-xs mt-1">{errors.name}</span>
)}
</div>
</div>
</div>
@ -308,7 +312,9 @@ const AddDialog = () => {
}
}}
/>
{errors.description && <span className="text-red-500 text-xs mt-1">{errors.description}</span>}
{errors.description && (
<span className="text-red-500 text-xs mt-1">{errors.description}</span>
)}
</div>
</div>
</div>
@ -408,7 +414,9 @@ const AddDialog = () => {
))}
</SelectContent>
</Select>
{errors.wallet_origin && <span className="text-red-500 text-xs mt-1">{errors.wallet_origin}</span>}
{errors.wallet_origin && (
<span className="text-red-500 text-xs mt-1">{errors.wallet_origin}</span>
)}
</div>
</div>
</div>
@ -427,7 +435,9 @@ const AddDialog = () => {
setErrors((prev) => ({ ...prev, wallet_destination: '' }));
}}
>
<SelectTrigger className={errors.wallet_destination ? 'border-red-500' : ''}>
<SelectTrigger
className={errors.wallet_destination ? 'border-red-500' : ''}
>
<SelectValue placeholder="Select Wallet" />
</SelectTrigger>
<SelectContent>
@ -438,7 +448,11 @@ const AddDialog = () => {
))}
</SelectContent>
</Select>
{errors.wallet_destination && <span className="text-red-500 text-xs mt-1">{errors.wallet_destination}</span>}
{errors.wallet_destination && (
<span className="text-red-500 text-xs mt-1">
{errors.wallet_destination}
</span>
)}
</div>
</div>
</div>
@ -485,7 +499,9 @@ const AddDialog = () => {
<SelectItem value="DN">Donation</SelectItem>
</SelectContent>
</Select>
{errors.type && <span className="text-red-500 text-xs mt-1">{errors.type}</span>}
{errors.type && (
<span className="text-red-500 text-xs mt-1">{errors.type}</span>
)}
</div>
</div>
</div>
@ -512,7 +528,9 @@ const AddDialog = () => {
<SelectItem value="N">No</SelectItem>
</SelectContent>
</Select>
{errors.status_approval && <span className="text-red-500 text-xs mt-1">{errors.status_approval}</span>}
{errors.status_approval && (
<span className="text-red-500 text-xs mt-1">{errors.status_approval}</span>
)}
</div>
</div>
</div>
@ -543,7 +561,9 @@ const AddDialog = () => {
<SelectItem value="N">Top Up Patner</SelectItem>
</SelectContent>
</Select>
{errors.status_kind && <span className="text-red-500 text-xs mt-1">{errors.status_kind}</span>}
{errors.status_kind && (
<span className="text-red-500 text-xs mt-1">{errors.status_kind}</span>
)}
</div>
</div>
</div>
@ -571,7 +591,9 @@ const AddDialog = () => {
<SelectItem value="N">Inactive</SelectItem>
</SelectContent>
</Select>
{errors.status && <span className="text-red-500 text-xs mt-1">{errors.status}</span>}
{errors.status && (
<span className="text-red-500 text-xs mt-1">{errors.status}</span>
)}
</div>
</div>
</div>
@ -599,4 +621,4 @@ const AddDialog = () => {
);
};
export default AddDialog;
export default AddDialog;

View File

@ -234,8 +234,10 @@ const EditDialog = () => {
toast.error(response?.message || 'Failed to update transfer type');
return false;
}
} catch (error) {
toast.error(error instanceof Error ? error.message : 'Failed to Update Transfer Type');
} catch (error: any) {
toast.error(
error?.response?.data?.message || error.message || 'Failed to Update Transfer Type'
);
return false;
}
}, [formField, selectedTransferType]);
@ -257,8 +259,9 @@ const EditDialog = () => {
if (response?.status && response?.data) {
setCustomers(response.data.list);
}
} catch (error) {
} catch (error: any) {
console.error('Error fetching customer', error);
toast.error(error?.response?.data?.message || 'Failed to fetch customer data');
}
};
@ -281,8 +284,9 @@ const EditDialog = () => {
if (response?.status && response?.data) {
setGroups(response.data.list);
}
} catch (error) {
} catch (error: any) {
console.error('Error fetching groups', error);
toast.error(error?.response?.data?.message || 'Failed to fetch groups');
}
};
@ -305,8 +309,9 @@ const EditDialog = () => {
if (response?.status && response?.data) {
setWallets(response.data.list);
}
} catch (error) {
} catch (error: any) {
console.error('Error fetching wallets', error);
toast.error(error?.response?.data?.message || 'Failed to fetch wallets');
}
};
@ -353,8 +358,9 @@ const EditDialog = () => {
}));
}
// console.log(response);
} catch (error) {
} catch (error: any) {
console.error('Error fetching transaction type', error);
toast.error(error?.response?.data?.message || 'Failed to load transaction type data');
setAlert({
show: true,
message: 'Failed to load transaction type data'