Skip to content

Commit

Permalink
Properly handled errors on API calls from Withdraw component
Browse files Browse the repository at this point in the history
  • Loading branch information
devAsadNur committed Aug 30, 2023
1 parent d7d529d commit 014397a
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions src/admin/pages/Withdraw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ export default {
methods: {
async getPaymentMethodSelector() {
await dokan.api.get( "/withdraw/payment_methods" )
.done( ( response, status, xhr ) => {
await dokan.api.get( '/withdraw/payment_methods' )
.done( ( response ) => {
this.paymentMethods = [ { id: '', text: '' } ].concat( response.map( payment_method => {
return {
id: payment_method.id,
Expand All @@ -439,6 +439,13 @@ export default {
jQuery( '#filter-payment-methods' ).select2( {
data: this.paymentMethods,
} ).val( this.filter.payment_method ).trigger( 'change' );
} ).fail( ( jqXHR ) => {
this.paymentMethods = [ { id: '', text: '' } ];
let message = dokan_handle_ajax_error( jqXHR );
if ( message ) {
this.showErrorAlert( message );
}
} );
},
Expand Down Expand Up @@ -661,30 +668,31 @@ export default {
end_date: self.filterTransactionDate.end_date
};
dokan.api.get( '/withdraw', args ).done( ( response, status, xhr ) => {
if ( ! response.percentage ) {
self.loading = false;
self.progressbar.isActive = false;
dokan.api.get( '/withdraw', args )
.done( ( response ) => {
if ( ! response.percentage ) {
self.loading = false;
self.progressbar.isActive = false;
return;
}
return;
}
self.progressbar.value = response.percentage;
self.progressbar.value = response.percentage;
if ( response.percentage >= 100 ) {
this.loading = false;
this.progressbar.isActive = false;
if ( response.percentage >= 100 ) {
this.loading = false;
this.progressbar.isActive = false;
// Redirect to the response URL.
window.location.assign( response.url );
} else {
// Run recursive logs to file method again.
self.recursiveWriteLogsToFile( response.step );
}
} ).fail( ( jqXHR ) => {
self.loading = false;
self.progressbar.isActive = false;
} );
// Redirect to the response URL.
window.location.assign( response.url );
} else {
// Run recursive logs to file method again.
self.recursiveWriteLogsToFile( response.step );
}
} ).fail( ( jqXHR ) => {
self.loading = false;
self.progressbar.isActive = false;
} );
},
clearAllFiltering() {
Expand Down Expand Up @@ -813,6 +821,15 @@ export default {
clearSelection(element) {
$(element).val(null).trigger('change');
},
showErrorAlert( message ) {
let self = this;
swal.fire(
self.__( 'Something went wrong', 'dokan' ),
message,
'error'
);
},
}
};
</script>
Expand Down

0 comments on commit 014397a

Please sign in to comment.