Skip to content

Commit

Permalink
Integrate wp data view.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aunshon committed Jan 8, 2025
1 parent b2e4e6c commit 9b5f66a
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 166 deletions.
3 changes: 2 additions & 1 deletion includes/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ public function get_styles() {
],
'dokan-react-frontend' => [
'src' => DOKAN_PLUGIN_ASSEST . '/css/frontend.css',
'deps' => [ 'dokan-react-components' ],
'version' => filemtime( DOKAN_DIR . '/assets/css/frontend.css' ),
],
'dokan-react-components' => [
Expand Down Expand Up @@ -589,7 +590,7 @@ public function get_scripts() {
],
'dokan-react-frontend' => [
'src' => $asset_url . '/js/frontend.js',
'deps' => $frontend_shipping_asset['dependencies'],
'deps' => array_merge( $frontend_shipping_asset['dependencies'], [ 'dokan-react-components' ] ),
'version' => $frontend_shipping_asset['version'],
],
'dokan-utilities' => [
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@
},
"dependencies": {
"@getdokan/dokan-ui": "^1.0.18",
"@wordpress/dataviews": "^4.10.0",
"@headlessui/react": "^2.2.0",
"@tanstack/react-table": "^8.20.5",
"@wordpress/components": "^28.9.0",
"@wordpress/data": "^10.9.0",
"@wordpress/dataviews": "^4.10.0",
"@wordpress/dom-ready": "^4.9.0",
"@wordpress/element": "^6.9.0",
"@wordpress/hooks": "^4.9.0",
Expand Down
37 changes: 22 additions & 15 deletions src/Dashboard/Withdraw/Hooks/useWithdrawRequests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useState, useCallback, useRef } from '@wordpress/element';
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
import { PaginationState } from '@tanstack/react-table';

interface WithdrawRequestPayload {
per_page: number;
Expand All @@ -19,6 +18,14 @@ interface WithdrawRequest {
created_date: string;
}

export interface WithdrawTableView {
perPage: number;
page: number;
search: any;
type: string;
titleField: string;
}

export interface UseWithdrawRequestsReturn {
data: WithdrawRequest[] | null;
isLoading: boolean;
Expand All @@ -27,8 +34,10 @@ export interface UseWithdrawRequestsReturn {
refresh: () => void;
totalItems: number;
totalPages: number;
pagination: PaginationState;
lastPayload?: WithdrawRequestPayload | null;
view: WithdrawTableView;
setView: ( view: any ) => void;
setData: ( data: any ) => void;
}

export const useWithdrawRequests = (
Expand All @@ -37,10 +46,14 @@ export const useWithdrawRequests = (
const [ data, setData ] = useState< WithdrawRequest[] | null >( null );
const [ totalItems, setTotalItems ] = useState< number >( 0 );
const [ totalPages, setTotalPages ] = useState< number >( 0 );
const [ pagination, setPagination ] = useState< PaginationState >( {
pageIndex: 0,
pageSize: 10,
} );
const [ view, setView] = useState< WithdrawTableView >({
perPage: 10,
page: 1,
search: '',
type: 'table',
titleField: 'amount',
});

const [ isLoading, setIsLoading ] = useState< boolean >( defaultLoader );
const [ error, setError ] = useState< Error | null >( null );
const lastPayload = useRef< WithdrawRequestPayload | null >( null );
Expand All @@ -61,14 +74,6 @@ export const useWithdrawRequests = (
lastPayload.current = payload;
}

setPagination( ( old ) => {
return {
...old,
pageIndex: payload.page ? payload.page - 1 : 1,
pageSize: payload.per_page,
};
} );

const newURL = addQueryArgs( `/dokan/v1/withdraw`, payload );

const response = await apiFetch< WithdrawRequest[] >( {
Expand Down Expand Up @@ -114,7 +119,9 @@ export const useWithdrawRequests = (
refresh,
totalItems,
totalPages,
pagination,
lastPayload: lastPayload.current,
view,
setView,
setData,
};
};
5 changes: 5 additions & 0 deletions src/Dashboard/Withdraw/PaymentDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ function PaymentDetails( {
<RequestList
withdrawRequests={ withdrawRequests }
status="pending"
loading={
masterLoading ||
withdrawRequests.isLoading ||
settings.isLoading
}
/>
</div>
) }
Expand Down
Loading

0 comments on commit 9b5f66a

Please sign in to comment.