Skip to content

Commit db7f896

Browse files
committed
Add better message to toast when updating payments (CORE-635)
1 parent c0bc5d8 commit db7f896

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

src/apps/wallet-admin/src/home/tabs/payments/PaymentsTab.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,15 @@ const ListView: FC<ListViewProps> = (props: ListViewProps) => {
259259

260260
toast.success('Updating payment', { position: toast.POSITION.BOTTOM_RIGHT })
261261
try {
262-
const udpateMessage = await editPayment(updates)
263-
toast.success(udpateMessage, { position: toast.POSITION.BOTTOM_RIGHT })
264-
} catch (err) {
265-
toast.error('Failed to update payment', { position: toast.POSITION.BOTTOM_RIGHT })
262+
const updateMessage = await editPayment(updates)
263+
toast.success(updateMessage, { position: toast.POSITION.BOTTOM_RIGHT })
264+
} catch (err:any) {
265+
if(err?.message){
266+
toast.error(err?.message, { position: toast.POSITION.BOTTOM_RIGHT })
267+
} else {
268+
toast.error('Failed to update payment', { position: toast.POSITION.BOTTOM_RIGHT })
269+
}
270+
266271
return
267272
}
268273

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import { ApiError } from "./ApiError"
2+
13
export default interface ApiResponse<T> {
24
status: 'success' | 'error'
35
data: T
6+
error: ApiError
47
}

src/apps/wallet-admin/src/lib/services/wallet.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,14 @@ export async function editPayment(updates: {
7979
}): Promise<string> {
8080
const body = JSON.stringify(updates)
8181
const url = `${baseUrl}/admin/winnings`
82-
82+
8383
const response = await xhrPatchAsync<string, ApiResponse<string>>(url, body)
8484

8585
if (response.status === 'error') {
86+
if (response.error && response.error.message) {
87+
console.log(response.error.message)
88+
throw new Error(response.error.message)
89+
}
8690
throw new Error('Error editing payment')
8791
}
8892

src/libs/core/lib/xhr/xhr-functions/xhr.functions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,13 @@ function interceptError(instance: AxiosInstance): void {
172172
config => config,
173173
(error: any) => {
174174
// if there is server error message, then return it inside `message` property of error
175-
error.message = error?.response?.data?.message || error.message
175+
if (error?.response?.data?.message) {
176+
error.message = error?.response?.data?.message
177+
} else if (error?.response?.data?.error?.message) {
178+
error.message = error?.response?.data?.error?.message
179+
}
176180
// if there is server errors data, then return it inside `errors` property of error
177181
error.errors = error?.response?.data?.errors
178-
179182
return Promise.reject(error)
180183
},
181184
)

0 commit comments

Comments
 (0)