Skip to content

Commit 95af0b2

Browse files
committed
enhance: change the withdraw exporter to woocommerce one and add the proper filtering
1 parent 30577f8 commit 95af0b2

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

includes/REST/WithdrawExportController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,19 @@ public function get_items( $request ) {
8888
}
8989

9090
if ( ! empty( $request['status'] ) ) {
91-
$args['status'] = $request['status'];
91+
$args['status'] = dokan()->withdraw->get_status_code( $request['status'] );
9292
}
9393

9494
if ( ! empty( $request['payment_method'] ) ) {
9595
$args['method'] = $request['payment_method'];
9696
}
9797

9898
if ( ! empty( $request['after'] ) ) {
99-
$args['after'] = $request['after'];
99+
$args['start_date'] = $request['after'];
100100
}
101101

102102
if ( ! empty( $request['before'] ) ) {
103-
$args['before'] = $request['before'];
103+
$args['end_date'] = $request['before'];
104104
}
105105

106106
// Set pagination

src/admin/dashboard/pages/withdraw/index.tsx

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
DokanModal,
2222
} from '@dokan/components';
2323

24-
import { Trash, ArrowDown, Home, Calendar, CreditCard } from 'lucide-react';
24+
import { Trash, ArrowDown, Home, Calendar, CreditCard, Loader2 } from 'lucide-react';
2525

2626
// Define withdraw statuses for tab filtering
2727
const WITHDRAW_STATUSES = [
@@ -88,6 +88,7 @@ const WithdrawPage = () => {
8888
approved: 0,
8989
cancelled: 0,
9090
} );
91+
const [ isExporting, setIsExporting ] = useState( false );
9192
const [ filterArgs, setFilterArgs ] = useState( {} );
9293
const [ activeStatus, setActiveStatus ] = useState( 'pending' );
9394
const [ vendorFilter, setVendorFilter ] = useState< VendorSelect | null >(
@@ -544,27 +545,54 @@ const WithdrawPage = () => {
544545
const tabsAdditionalContents = [
545546
<button
546547
type="button"
547-
className="inline-flex items-center gap-2 rounded-md border border-gray-300 bg-white px-3 py-1.5 text-sm text-[#575757] hover:bg-[#7047EB] hover:text-white"
548+
disabled={ isExporting }
549+
className="inline-flex items-center gap-2 rounded-md border border-gray-300 bg-white px-3 py-1.5 text-sm text-[#575757] hover:bg-[#7047EB] hover:text-white disabled:opacity-50 disabled:cursor-not-allowed"
548550
onClick={ async () => {
551+
setIsExporting(true);
552+
549553
try {
550-
// Minimal placeholder; backend export flow may vary.
551-
// Attempt to hit export endpoint via same query params.
552-
const path = addQueryArgs( 'dokan/v2/withdraw', {
553-
...view,
554-
is_export: true,
555-
} );
556-
const res = await apiFetch( { path } );
557-
if ( res && res.url ) {
558-
window.location.assign( res.url as string );
554+
const reportArgs = {
555+
status:
556+
activeStatus === 'all' ? undefined : activeStatus,
557+
user_id: filterArgs.user_id,
558+
payment_method: filterArgs.payment_method,
559+
after: filterArgs.start_date,
560+
before: filterArgs.end_date,
561+
};
562+
563+
const exportResponse = await apiFetch({
564+
path: '/dokan/v1/reports/withdraws/export',
565+
method: 'POST',
566+
data: {
567+
report_args: reportArgs,
568+
per_page: 100,
569+
email: false,
570+
},
571+
});
572+
573+
if (exportResponse.export_id) {
574+
await pollExportStatus(exportResponse.export_id);
575+
} else {
576+
throw new Error('Failed to initiate export');
559577
}
560-
} catch ( e ) {
561-
// eslint-disable-next-line no-console
562-
console.error( 'Export failed or not supported yet', e );
578+
} catch (e) {
579+
alert(__('Export failed. Please try again.', 'dokan-lite'));
580+
} finally {
581+
setIsExporting(false);
563582
}
564-
} }
583+
}}
565584
>
566-
<ArrowDown size={ 16 } />
567-
{ __( 'Export', 'dokan-lite' ) }
585+
{ isExporting ? (
586+
<>
587+
<Loader2 className="animate-spin" size={16} />
588+
{ __( 'Exporting...', 'dokan-lite' ) }
589+
</>
590+
) : (
591+
<>
592+
<ArrowDown size={16} />
593+
{ __( 'Export', 'dokan-lite' ) }
594+
</>
595+
) }
568596
</button>,
569597
];
570598

0 commit comments

Comments
 (0)