Skip to content

Commit

Permalink
Fix response useOrder vercel#2
Browse files Browse the repository at this point in the history
  • Loading branch information
vinhnt1706 committed Mar 1, 2022
1 parent 43e0d81 commit db621fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 8 additions & 3 deletions framework/magento/order/use-order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ export const handler: SWRHook<any> = {
query: getAllOrdersQuery,
},
async fetcher({ input, options, fetch }) {
const data = await fetch({...options})
return data?.customer?.orders?.items
console.log(input)
const data = await fetch({
...options,
variables: input
})
return data?.customer?.orders
},
useHook:
({ useData }) =>
(input) => {
const response = useData({
input: input,
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
})

Expand All @@ -27,7 +32,7 @@ export const handler: SWRHook<any> = {
Object.create(response, {
isEmpty: {
get() {
return (response.data?.length ?? 0) <= 0
return (response.data?.items?.length ?? 0) <= 0
},
enumerable: true,
},
Expand Down
9 changes: 7 additions & 2 deletions framework/magento/utils/queries/get-all-orders-query.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const getAllOrdersQuery = /* GraphQL */ `
query {
query getAllOrders(
$currentPage: Int = 1
$pageSize: Int = 10
){
customer {
orders(
pageSize: 20
currentPage: $currentPage
pageSize: $pageSize
) {
total_count
items {
id
order_date
Expand Down

0 comments on commit db621fc

Please sign in to comment.