diff --git a/.circleci/config.yml b/.circleci/config.yml index a5c9acf31..4c15af0f8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -258,6 +258,7 @@ workflows: only: - dev - LVT-256 + - CORE-635 - deployQa: context: org-global diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..4fb4b46dd --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +* * \ No newline at end of file diff --git a/src/apps/wallet-admin/src/home/tabs/payments/PaymentsTab.tsx b/src/apps/wallet-admin/src/home/tabs/payments/PaymentsTab.tsx index b14a0dcf8..9a4bdd02e 100644 --- a/src/apps/wallet-admin/src/home/tabs/payments/PaymentsTab.tsx +++ b/src/apps/wallet-admin/src/home/tabs/payments/PaymentsTab.tsx @@ -37,6 +37,8 @@ function formatStatus(status: string): string { return 'Paid' case 'CANCELLED': return 'Cancel' + case 'PROCESSING': + return 'Processing' default: return status.replaceAll('_', ' ') } @@ -217,6 +219,7 @@ const ListView: FC = (props: ListViewProps) => { return confirmFlow?.content }, [confirmFlow]) + // eslint-disable-next-line complexity const updatePayment = async (paymentId: string): Promise => { const currentEditState = editStateRef.current // Send to server only the fields that have changed @@ -257,10 +260,15 @@ const ListView: FC = (props: ListViewProps) => { toast.success('Updating payment', { position: toast.POSITION.BOTTOM_RIGHT }) try { - const udpateMessage = await editPayment(updates) - toast.success(udpateMessage, { position: toast.POSITION.BOTTOM_RIGHT }) - } catch (err) { - toast.error('Failed to update payment', { position: toast.POSITION.BOTTOM_RIGHT }) + const updateMessage = await editPayment(updates) + toast.success(updateMessage, { position: toast.POSITION.BOTTOM_RIGHT }) + } catch (err:any) { + if (err?.message) { + toast.error(err?.message, { position: toast.POSITION.BOTTOM_RIGHT }) + } else { + toast.error('Failed to update payment', { position: toast.POSITION.BOTTOM_RIGHT }) + } + return } @@ -354,7 +362,7 @@ const ListView: FC = (props: ListViewProps) => { }, { label: 'Processing', - value: 'Processing', + value: 'PROCESSING', }, ], type: 'dropdown', diff --git a/src/apps/wallet-admin/src/lib/models/ApiResponse.ts b/src/apps/wallet-admin/src/lib/models/ApiResponse.ts index 3221e7793..6adfdc08f 100644 --- a/src/apps/wallet-admin/src/lib/models/ApiResponse.ts +++ b/src/apps/wallet-admin/src/lib/models/ApiResponse.ts @@ -1,4 +1,7 @@ +import { ApiError } from './ApiError' + export default interface ApiResponse { status: 'success' | 'error' data: T + error: ApiError } diff --git a/src/apps/wallet-admin/src/lib/services/wallet.ts b/src/apps/wallet-admin/src/lib/services/wallet.ts index a70e875f6..3475cb4e4 100644 --- a/src/apps/wallet-admin/src/lib/services/wallet.ts +++ b/src/apps/wallet-admin/src/lib/services/wallet.ts @@ -83,6 +83,10 @@ export async function editPayment(updates: { const response = await xhrPatchAsync>(url, body) if (response.status === 'error') { + if (response.error && response.error.message) { + throw new Error(response.error.message) + } + throw new Error('Error editing payment') } diff --git a/src/libs/core/lib/xhr/xhr-functions/xhr.functions.ts b/src/libs/core/lib/xhr/xhr-functions/xhr.functions.ts index af5a3d9e2..d6d560343 100644 --- a/src/libs/core/lib/xhr/xhr-functions/xhr.functions.ts +++ b/src/libs/core/lib/xhr/xhr-functions/xhr.functions.ts @@ -172,10 +172,14 @@ function interceptError(instance: AxiosInstance): void { config => config, (error: any) => { // if there is server error message, then return it inside `message` property of error - error.message = error?.response?.data?.message || error.message + if (error?.response?.data?.message) { + error.message = error?.response?.data?.message + } else if (error?.response?.data?.error?.message) { + error.message = error?.response?.data?.error?.message + } + // if there is server errors data, then return it inside `errors` property of error error.errors = error?.response?.data?.errors - return Promise.reject(error) }, )