@medusajs/loyalty-plugin 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.medusa/server/src/admin/index.js +30277 -0
- package/.medusa/server/src/admin/index.mjs +30256 -0
- package/.medusa/server/src/api/store/carts/[id]/store-credits/route.js +24 -0
- package/.medusa/server/src/api/store/carts/middlewares.js +9 -1
- package/.medusa/server/src/api/store/carts/validators.js +5 -2
- package/.medusa/server/src/links/customer-gift-card-link.js +2 -2
- package/.medusa/server/src/links/customer-store-credit-account-link.js +2 -2
- package/.medusa/server/src/links/order-line-item-gift-card-link.js +2 -2
- package/.medusa/server/src/workflows/carts/workflows/add-store-credits-to-cart.js +104 -0
- package/.medusa/server/src/workflows/hooks/after-order-created.js +2 -2
- package/.medusa/server/src/workflows/hooks/after-order-credit-lines-created.js +3 -3
- package/.medusa/server/src/workflows/hooks/before-payment-collection-refresh.js +1 -1
- package/.medusa/server/src/workflows/hooks/complete-cart-before-payment-authorization.js +1 -1
- package/.medusa/server/src/workflows/orders/workflows/refund-credit-lines.js +115 -0
- package/package.json +14 -9
- package/.medusa/server/src/admin/components/action-menu.js +0 -63
- package/.medusa/server/src/admin/components/chip-group.js +0 -82
- package/.medusa/server/src/admin/components/chip-input.js +0 -157
- package/.medusa/server/src/admin/components/combobox.js +0 -324
- package/.medusa/server/src/admin/components/conditional-tooltip.js +0 -15
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-boolean-cell.js +0 -66
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-cell-container.js +0 -77
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-currency-cell.js +0 -110
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-duplicate-cell.js +0 -16
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-keyboard-shortcut-modal.js +0 -214
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-number-cell.js +0 -77
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-readonly-cell.js +0 -32
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-root.js +0 -743
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-row-error-indicator.js +0 -37
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-skeleton.js +0 -54
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-text-cell.js +0 -66
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-toggleable-number-cell.js +0 -166
- package/.medusa/server/src/admin/components/data-grid/components/index.js +0 -16
- package/.medusa/server/src/admin/components/data-grid/context/data-grid-context.js +0 -7
- package/.medusa/server/src/admin/components/data-grid/context/index.js +0 -6
- package/.medusa/server/src/admin/components/data-grid/context/use-data-grid-context.js +0 -14
- package/.medusa/server/src/admin/components/data-grid/data-grid.js +0 -31
- package/.medusa/server/src/admin/components/data-grid/helpers/create-data-grid-column-helper.js +0 -28
- package/.medusa/server/src/admin/components/data-grid/helpers/create-data-grid-price-columns.js +0 -85
- package/.medusa/server/src/admin/components/data-grid/helpers/index.js +0 -6
- package/.medusa/server/src/admin/components/data-grid/hooks/index.js +0 -31
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-error.js +0 -50
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-handlers.js +0 -123
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-metadata.js +0 -52
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-snapshot.js +0 -43
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell.js +0 -191
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-clipboard-events.js +0 -70
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-column-visibility.js +0 -51
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-duplicate-cell.js +0 -15
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-error-highlighting.js +0 -86
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-form-handlers.js +0 -149
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-keydown-event.js +0 -482
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-mouse-up-event.js +0 -64
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-navigation.js +0 -81
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-query-tool.js +0 -14
- package/.medusa/server/src/admin/components/data-grid/index.js +0 -8
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-bulk-update-command.js +0 -27
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-matrix.js +0 -296
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-query-tool.js +0 -62
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-update-command.js +0 -25
- package/.medusa/server/src/admin/components/data-grid/models/index.js +0 -10
- package/.medusa/server/src/admin/components/data-grid/types.js +0 -1
- package/.medusa/server/src/admin/components/data-grid/utils.js +0 -18
- package/.medusa/server/src/admin/components/data-table/components/data-table-status-cell/data-table-status-cell.js +0 -36
- package/.medusa/server/src/admin/components/data-table/data-table.js +0 -271
- package/.medusa/server/src/admin/components/data-table/helpers/general/use-data-table-date-columns.js +0 -51
- package/.medusa/server/src/admin/components/data-table/helpers/general/use-data-table-date-filters.js +0 -90
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/index.js +0 -10
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-columns.js +0 -48
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-empty-state.js +0 -19
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-filters.js +0 -30
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-query.js +0 -23
- package/.medusa/server/src/admin/components/data-table/index.js +0 -4
- package/.medusa/server/src/admin/components/data-table.js +0 -249
- package/.medusa/server/src/admin/components/display-id.js +0 -18
- package/.medusa/server/src/admin/components/file-upload.js +0 -116
- package/.medusa/server/src/admin/components/form.js +0 -151
- package/.medusa/server/src/admin/components/handle-input.js +0 -22
- package/.medusa/server/src/admin/components/header.js +0 -41
- package/.medusa/server/src/admin/components/icon-avatar.js +0 -27
- package/.medusa/server/src/admin/components/json-view-section.js +0 -139
- package/.medusa/server/src/admin/components/keybound-form.js +0 -32
- package/.medusa/server/src/admin/components/layouts/single-column.js +0 -7
- package/.medusa/server/src/admin/components/layouts/two-column.js +0 -13
- package/.medusa/server/src/admin/components/listicle.js +0 -20
- package/.medusa/server/src/admin/components/modals/index.js +0 -19
- package/.medusa/server/src/admin/components/modals/route-drawer/index.js +0 -4
- package/.medusa/server/src/admin/components/modals/route-drawer/route-drawer.js +0 -57
- package/.medusa/server/src/admin/components/modals/route-focus-modal/index.js +0 -4
- package/.medusa/server/src/admin/components/modals/route-focus-modal/route-focus-modal.js +0 -71
- package/.medusa/server/src/admin/components/modals/route-modal-form/index.js +0 -4
- package/.medusa/server/src/admin/components/modals/route-modal-form/route-modal-form.js +0 -60
- package/.medusa/server/src/admin/components/modals/route-modal-provider/index.js +0 -6
- package/.medusa/server/src/admin/components/modals/route-modal-provider/route-modal-context.js +0 -5
- package/.medusa/server/src/admin/components/modals/route-modal-provider/route-provider.js +0 -30
- package/.medusa/server/src/admin/components/modals/route-modal-provider/use-route-modal.js +0 -12
- package/.medusa/server/src/admin/components/modals/stacked-drawer/index.js +0 -5
- package/.medusa/server/src/admin/components/modals/stacked-drawer/stacked-drawer.js +0 -55
- package/.medusa/server/src/admin/components/modals/stacked-focus-modal/index.js +0 -5
- package/.medusa/server/src/admin/components/modals/stacked-focus-modal/stacked-focus-modal.js +0 -63
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/index.js +0 -6
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-context.js +0 -5
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-provider.js +0 -47
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/use-stacked-modal.js +0 -14
- package/.medusa/server/src/admin/components/placeholder-cell.js +0 -7
- package/.medusa/server/src/admin/components/product/product-cell/index.js +0 -5
- package/.medusa/server/src/admin/components/product/product-cell/product-cell.js +0 -15
- package/.medusa/server/src/admin/components/product/product-status-cell/index.js +0 -5
- package/.medusa/server/src/admin/components/product/product-status-cell/product-status-cell.js +0 -18
- package/.medusa/server/src/admin/components/product/sales-channels-cell/index.js +0 -5
- package/.medusa/server/src/admin/components/product/sales-channels-cell/sales-channels-cell.js +0 -31
- package/.medusa/server/src/admin/components/product/variant-cell/index.js +0 -5
- package/.medusa/server/src/admin/components/product/variant-cell/variant-cell.js +0 -15
- package/.medusa/server/src/admin/components/section-row.js +0 -32
- package/.medusa/server/src/admin/components/sidebar-link.js +0 -31
- package/.medusa/server/src/admin/components/sortable-list.js +0 -152
- package/.medusa/server/src/admin/components/switch-box.js +0 -43
- package/.medusa/server/src/admin/components/tax-badge.js +0 -18
- package/.medusa/server/src/admin/components/thumbnail.js +0 -28
- package/.medusa/server/src/admin/components/upload-media-form-item.js +0 -83
- package/.medusa/server/src/admin/hooks/api/customers.js +0 -26
- package/.medusa/server/src/admin/hooks/api/gift-cards.js +0 -107
- package/.medusa/server/src/admin/hooks/api/order.js +0 -16
- package/.medusa/server/src/admin/hooks/api/price-preferences.js +0 -19
- package/.medusa/server/src/admin/hooks/api/products.js +0 -127
- package/.medusa/server/src/admin/hooks/api/regions.js +0 -17
- package/.medusa/server/src/admin/hooks/api/sales-channels.js +0 -28
- package/.medusa/server/src/admin/hooks/api/store-credit-accounts.js +0 -41
- package/.medusa/server/src/admin/hooks/api/store.js +0 -31
- package/.medusa/server/src/admin/hooks/api/transaction-groups.js +0 -23
- package/.medusa/server/src/admin/hooks/api/transactions.js +0 -23
- package/.medusa/server/src/admin/hooks/commands/use-command-history.js +0 -45
- package/.medusa/server/src/admin/hooks/common/use-combobox-data.js +0 -59
- package/.medusa/server/src/admin/hooks/common/use-data-table-date-filters.js +0 -89
- package/.medusa/server/src/admin/hooks/common/use-date.js +0 -32
- package/.medusa/server/src/admin/hooks/common/use-debounced-search.js +0 -22
- package/.medusa/server/src/admin/hooks/common/use-query-params.js +0 -14
- package/.medusa/server/src/admin/hooks/query/use-customers-filters.js +0 -30
- package/.medusa/server/src/admin/hooks/query/use-transaction-groups-filters.js +0 -30
- package/.medusa/server/src/admin/hooks/sales-channels/index.js +0 -10
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-columns.js +0 -48
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-empty-state.js +0 -19
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-filters.js +0 -30
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-query.js +0 -23
- package/.medusa/server/src/admin/lib/currencies.js +0 -729
- package/.medusa/server/src/admin/lib/query-key.js +0 -17
- package/.medusa/server/src/admin/lib/sdk.js +0 -10
- package/.medusa/server/src/admin/routes/gift-card-products/@create/page.js +0 -75
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@denominations/components/gift-card-product-edit-denominations-form.js +0 -172
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@denominations/page.js +0 -30
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@edit/components/gift-card-product-edit-form.js +0 -180
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@edit/page.js +0 -30
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-general-section.js +0 -97
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-media-section.js +0 -162
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-sales-channel-section.js +0 -89
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-variant-section.js +0 -199
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/edit-product-media-form/edit-product-media-form.js +0 -353
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/edit-product-media-form/index.js +0 -5
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-gallery/index.js +0 -4
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-gallery/product-media-gallery.js +0 -247
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/index.js +0 -4
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/product-media-view-context.js +0 -5
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/product-media-view.js +0 -48
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/use-product-media-view.js +0 -14
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/page.js +0 -28
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/page.js +0 -40
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/prices/components/prices-edit.js +0 -121
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/prices/components/variant-pricing-form.js +0 -72
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/prices/page.js +0 -23
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/sales-channels/components/edit-sales-channel-form.js +0 -123
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/sales-channels/page.js +0 -23
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/general-form-section.js +0 -1
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-denominations-form.js +0 -98
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-details-form.js +0 -28
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-denominations.js +0 -96
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-general.js +0 -90
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-media.js +0 -288
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-organize-section.js +0 -111
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-organize.js +0 -23
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form.js +0 -285
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-sales-channel-stacked-modal.js +0 -124
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/index.js +0 -4
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/schema.js +0 -112
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/types.js +0 -1
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/columns.js +0 -35
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/filters.js +0 -11
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/gift-card-products-table.js +0 -61
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/query.js +0 -23
- package/.medusa/server/src/admin/routes/gift-card-products/page.js +0 -18
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@expiration/page.js +0 -137
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@note/page.js +0 -87
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@owner/components/transfer-icon.js +0 -352
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@owner/page.js +0 -116
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-balance-section.js +0 -49
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-general-section.js +0 -177
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-note-section.js +0 -27
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-order-section.js +0 -33
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-owner-section.js +0 -33
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-transactions-section.js +0 -18
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/transactions-table/columns.js +0 -50
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/transactions-table/query.js +0 -23
- package/.medusa/server/src/admin/routes/gift-cards/_id_/page.js +0 -78
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-card-products-section.js +0 -40
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/columns.js +0 -57
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/filters.js +0 -13
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/gift-cards-table.js +0 -61
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/query.js +0 -23
- package/.medusa/server/src/admin/routes/gift-cards/page.js +0 -27
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/credit-card-icon.js +0 -126
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/store-credit-account-balance-section.js +0 -31
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/store-credit-account-details-section.js +0 -43
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/columns.js +0 -44
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/filters.js +0 -18
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/query.js +0 -37
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/table.js +0 -58
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/page.js +0 -39
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/columns.js +0 -58
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/filters.js +0 -13
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/query.js +0 -31
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/table.js +0 -56
- package/.medusa/server/src/admin/routes/store-credit-accounts/page.js +0 -19
- package/.medusa/server/src/admin/utils/date-utils.js +0 -27
- package/.medusa/server/src/admin/utils/format-amount.js +0 -9
- package/.medusa/server/src/admin/utils/format-date.js +0 -21
- package/.medusa/server/src/admin/utils/refs.js +0 -20
- package/.medusa/server/src/admin/utils/statuses.js +0 -23
- package/.medusa/server/src/admin/utils/validations.js +0 -71
- package/.medusa/server/src/admin/utils/variants.js +0 -92
- package/.medusa/server/src/admin/widgets/customer-gift-cards-widget.js +0 -67
- package/.medusa/server/src/admin/widgets/customer-store-credit-widget.js +0 -42
- package/.medusa/server/src/admin/widgets/order-gift-cards-widget.js +0 -58
- package/.medusa/server/src/workflows/orders/workflows/refund-gift-card-credit-lines.js +0 -96
- package/.medusa/server/types/loyalty/module.js +0 -8
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query";
|
|
2
|
-
import { queryKeysFactory } from "../../lib/query-key.js";
|
|
3
|
-
import { sdk } from "../../lib/sdk.js";
|
|
4
|
-
const giftCardQueryKey = queryKeysFactory("gift-card");
|
|
5
|
-
const useGiftCards = (query, options) => {
|
|
6
|
-
const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
|
|
7
|
-
query: query2,
|
|
8
|
-
headers
|
|
9
|
-
});
|
|
10
|
-
const { data, ...rest } = useQuery({
|
|
11
|
-
...options,
|
|
12
|
-
queryFn: () => fetchGiftCards(query),
|
|
13
|
-
queryKey: giftCardQueryKey.list(query)
|
|
14
|
-
});
|
|
15
|
-
return { ...data, ...rest };
|
|
16
|
-
};
|
|
17
|
-
const useGiftCard = (id, query, options) => {
|
|
18
|
-
const fetchGiftCard = (id2, query2, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
|
|
19
|
-
query: query2,
|
|
20
|
-
headers
|
|
21
|
-
});
|
|
22
|
-
const { data, ...rest } = useQuery({
|
|
23
|
-
queryFn: () => fetchGiftCard(id, query),
|
|
24
|
-
queryKey: giftCardQueryKey.detail(id),
|
|
25
|
-
...options
|
|
26
|
-
});
|
|
27
|
-
return { ...data, ...rest };
|
|
28
|
-
};
|
|
29
|
-
const useRedeemGiftCard = (id, options) => {
|
|
30
|
-
const queryClient = useQueryClient();
|
|
31
|
-
const redeemGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}/redeem`, {
|
|
32
|
-
body,
|
|
33
|
-
method: "POST"
|
|
34
|
-
});
|
|
35
|
-
return useMutation({
|
|
36
|
-
mutationFn: (body) => redeemGiftCard(id, body),
|
|
37
|
-
onSuccess: (data, variables, context) => {
|
|
38
|
-
var _a;
|
|
39
|
-
queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
|
|
40
|
-
queryClient.invalidateQueries({ queryKey: giftCardQueryKey.detail(id) });
|
|
41
|
-
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data, variables, context);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
const useTransferGiftCard = (id, options) => {
|
|
46
|
-
const queryClient = useQueryClient();
|
|
47
|
-
const transferGiftCard = async (id2, body) => sdk.client.fetch(
|
|
48
|
-
`/admin/gift-cards/${id2}/transfer`,
|
|
49
|
-
{
|
|
50
|
-
body,
|
|
51
|
-
method: "POST"
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
return useMutation({
|
|
55
|
-
mutationFn: (body) => transferGiftCard(id, body),
|
|
56
|
-
onSuccess: (data, variables, context) => {
|
|
57
|
-
var _a;
|
|
58
|
-
queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
|
|
59
|
-
queryClient.invalidateQueries({ queryKey: giftCardQueryKey.detail(id) });
|
|
60
|
-
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data, variables, context);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
const useUpdateGiftCard = (id, options) => {
|
|
65
|
-
const queryClient = useQueryClient();
|
|
66
|
-
const updateGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
|
|
67
|
-
body,
|
|
68
|
-
method: "POST"
|
|
69
|
-
});
|
|
70
|
-
return useMutation({
|
|
71
|
-
mutationFn: async (payload) => updateGiftCard(id, payload),
|
|
72
|
-
onSuccess: (data, variables, context) => {
|
|
73
|
-
var _a;
|
|
74
|
-
queryClient.invalidateQueries({
|
|
75
|
-
queryKey: giftCardQueryKey.detail(id)
|
|
76
|
-
});
|
|
77
|
-
queryClient.invalidateQueries({
|
|
78
|
-
queryKey: giftCardQueryKey.lists()
|
|
79
|
-
});
|
|
80
|
-
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data, variables, context);
|
|
81
|
-
},
|
|
82
|
-
...options
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
const useDeleteGiftCard = (id, options) => {
|
|
86
|
-
const queryClient = useQueryClient();
|
|
87
|
-
const deleteGiftCard = async (id2) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
|
|
88
|
-
method: "DELETE"
|
|
89
|
-
});
|
|
90
|
-
return useMutation({
|
|
91
|
-
mutationFn: () => deleteGiftCard(id),
|
|
92
|
-
onSuccess: (data, variables, context) => {
|
|
93
|
-
var _a;
|
|
94
|
-
queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
|
|
95
|
-
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data, variables, context);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
export {
|
|
100
|
-
giftCardQueryKey,
|
|
101
|
-
useDeleteGiftCard,
|
|
102
|
-
useGiftCard,
|
|
103
|
-
useGiftCards,
|
|
104
|
-
useRedeemGiftCard,
|
|
105
|
-
useTransferGiftCard,
|
|
106
|
-
useUpdateGiftCard
|
|
107
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { useQuery } from "@tanstack/react-query";
|
|
2
|
-
import { queryKeysFactory } from "../../lib/query-key.js";
|
|
3
|
-
import { sdk } from "../../lib/sdk.js";
|
|
4
|
-
const ORDERS_QUERY_KEY = "orders";
|
|
5
|
-
const orderQueryKeys = queryKeysFactory(ORDERS_QUERY_KEY);
|
|
6
|
-
const useOrder = (id, query, options) => {
|
|
7
|
-
const { data, ...rest } = useQuery({
|
|
8
|
-
queryFn: async () => sdk.admin.order.retrieve(id, query),
|
|
9
|
-
queryKey: orderQueryKeys.detail(id, query),
|
|
10
|
-
...options
|
|
11
|
-
});
|
|
12
|
-
return { ...data, ...rest };
|
|
13
|
-
};
|
|
14
|
-
export {
|
|
15
|
-
useOrder
|
|
16
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useQuery } from "@tanstack/react-query";
|
|
2
|
-
import { queryKeysFactory } from "../../lib/query-key.js";
|
|
3
|
-
import { sdk } from "../../lib/sdk.js";
|
|
4
|
-
const PRICE_PREFERENCES_QUERY_KEY = "price-preferences";
|
|
5
|
-
const pricePreferencesQueryKeys = queryKeysFactory(
|
|
6
|
-
PRICE_PREFERENCES_QUERY_KEY
|
|
7
|
-
);
|
|
8
|
-
const usePricePreferences = (query, options) => {
|
|
9
|
-
const { data, ...rest } = useQuery({
|
|
10
|
-
queryFn: () => sdk.admin.pricePreference.list(query),
|
|
11
|
-
queryKey: pricePreferencesQueryKeys.list(query),
|
|
12
|
-
...options
|
|
13
|
-
});
|
|
14
|
-
return { ...data, ...rest };
|
|
15
|
-
};
|
|
16
|
-
export {
|
|
17
|
-
pricePreferencesQueryKeys,
|
|
18
|
-
usePricePreferences
|
|
19
|
-
};
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query";
|
|
2
|
-
import { queryKeysFactory } from "../../lib/query-key.js";
|
|
3
|
-
import { sdk } from "../../lib/sdk.js";
|
|
4
|
-
const PRODUCTS_QUERY_KEY = "products";
|
|
5
|
-
const productsQueryKeys = queryKeysFactory(PRODUCTS_QUERY_KEY);
|
|
6
|
-
const VARIANTS_QUERY_KEY = "product_variants";
|
|
7
|
-
const variantsQueryKeys = queryKeysFactory(VARIANTS_QUERY_KEY);
|
|
8
|
-
const useProducts = (query, options) => {
|
|
9
|
-
const { data, ...rest } = useQuery({
|
|
10
|
-
queryFn: () => sdk.admin.product.list(query),
|
|
11
|
-
queryKey: productsQueryKeys.list(query),
|
|
12
|
-
...options
|
|
13
|
-
});
|
|
14
|
-
return { ...data, ...rest };
|
|
15
|
-
};
|
|
16
|
-
const useProduct = (id, query, options) => {
|
|
17
|
-
const { data, ...rest } = useQuery({
|
|
18
|
-
queryFn: () => sdk.admin.product.retrieve(id, query),
|
|
19
|
-
queryKey: productsQueryKeys.detail(id, query),
|
|
20
|
-
...options
|
|
21
|
-
});
|
|
22
|
-
return { ...data, ...rest };
|
|
23
|
-
};
|
|
24
|
-
const useCreateProduct = (options) => {
|
|
25
|
-
const queryClient = useQueryClient();
|
|
26
|
-
return useMutation({
|
|
27
|
-
mutationFn: (payload) => sdk.admin.product.create(payload),
|
|
28
|
-
onSuccess: (data, variables, context) => {
|
|
29
|
-
var _a;
|
|
30
|
-
queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() });
|
|
31
|
-
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data, variables, context);
|
|
32
|
-
},
|
|
33
|
-
...options
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
const useDeleteProduct = (id, options) => {
|
|
37
|
-
const queryClient = useQueryClient();
|
|
38
|
-
return useMutation({
|
|
39
|
-
mutationFn: () => sdk.admin.product.delete(id),
|
|
40
|
-
onSuccess: (data, variables, context) => {
|
|
41
|
-
var _a;
|
|
42
|
-
queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() });
|
|
43
|
-
queryClient.invalidateQueries({ queryKey: productsQueryKeys.detail(id) });
|
|
44
|
-
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data, variables, context);
|
|
45
|
-
},
|
|
46
|
-
...options
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
const useProductVariants = (productId, query, options) => {
|
|
50
|
-
const { data, ...rest } = useQuery({
|
|
51
|
-
queryFn: () => sdk.admin.product.listVariants(productId, query),
|
|
52
|
-
queryKey: variantsQueryKeys.list({ productId, ...query }),
|
|
53
|
-
...options
|
|
54
|
-
});
|
|
55
|
-
return { ...data, ...rest };
|
|
56
|
-
};
|
|
57
|
-
const useDeleteVariantLazy = (productId, options) => {
|
|
58
|
-
const queryClient = useQueryClient();
|
|
59
|
-
return useMutation({
|
|
60
|
-
mutationFn: ({ variantId }) => sdk.admin.product.deleteVariant(productId, variantId),
|
|
61
|
-
onSuccess: (data, variables, context) => {
|
|
62
|
-
var _a;
|
|
63
|
-
queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() });
|
|
64
|
-
queryClient.invalidateQueries({
|
|
65
|
-
queryKey: variantsQueryKeys.detail(variables.variantId)
|
|
66
|
-
});
|
|
67
|
-
queryClient.invalidateQueries({
|
|
68
|
-
queryKey: productsQueryKeys.detail(productId)
|
|
69
|
-
});
|
|
70
|
-
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data, variables, context);
|
|
71
|
-
},
|
|
72
|
-
...options
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
const useUpdateProduct = (id, options) => {
|
|
76
|
-
const queryClient = useQueryClient();
|
|
77
|
-
return useMutation({
|
|
78
|
-
mutationFn: (payload) => sdk.admin.product.update(id, payload),
|
|
79
|
-
onSuccess: async (data, variables, context) => {
|
|
80
|
-
var _a;
|
|
81
|
-
await queryClient.invalidateQueries({
|
|
82
|
-
queryKey: productsQueryKeys.lists()
|
|
83
|
-
});
|
|
84
|
-
await queryClient.invalidateQueries({
|
|
85
|
-
queryKey: productsQueryKeys.details()
|
|
86
|
-
});
|
|
87
|
-
await queryClient.invalidateQueries({
|
|
88
|
-
queryKey: variantsQueryKeys.lists()
|
|
89
|
-
});
|
|
90
|
-
await queryClient.invalidateQueries({
|
|
91
|
-
queryKey: variantsQueryKeys.details()
|
|
92
|
-
});
|
|
93
|
-
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data, variables, context);
|
|
94
|
-
},
|
|
95
|
-
...options
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
const useUpdateProductVariantsBatch = (productId, options) => {
|
|
99
|
-
const queryClient = useQueryClient();
|
|
100
|
-
return useMutation({
|
|
101
|
-
mutationFn: (payload) => sdk.admin.product.batchVariants(productId, {
|
|
102
|
-
update: payload
|
|
103
|
-
}),
|
|
104
|
-
onSuccess: (data, variables, context) => {
|
|
105
|
-
var _a;
|
|
106
|
-
queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() });
|
|
107
|
-
queryClient.invalidateQueries({ queryKey: variantsQueryKeys.details() });
|
|
108
|
-
queryClient.invalidateQueries({
|
|
109
|
-
queryKey: productsQueryKeys.detail(productId)
|
|
110
|
-
});
|
|
111
|
-
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data, variables, context);
|
|
112
|
-
},
|
|
113
|
-
...options
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
export {
|
|
117
|
-
productsQueryKeys,
|
|
118
|
-
useCreateProduct,
|
|
119
|
-
useDeleteProduct,
|
|
120
|
-
useDeleteVariantLazy,
|
|
121
|
-
useProduct,
|
|
122
|
-
useProductVariants,
|
|
123
|
-
useProducts,
|
|
124
|
-
useUpdateProduct,
|
|
125
|
-
useUpdateProductVariantsBatch,
|
|
126
|
-
variantsQueryKeys
|
|
127
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useQuery } from "@tanstack/react-query";
|
|
2
|
-
import { queryKeysFactory } from "../../lib/query-key.js";
|
|
3
|
-
import { sdk } from "../../lib/sdk.js";
|
|
4
|
-
const REGIONS_QUERY_KEY = "regions";
|
|
5
|
-
const regionsQueryKeys = queryKeysFactory(REGIONS_QUERY_KEY);
|
|
6
|
-
const useRegions = (query, options) => {
|
|
7
|
-
const { data, ...rest } = useQuery({
|
|
8
|
-
queryFn: () => sdk.admin.region.list(query),
|
|
9
|
-
queryKey: regionsQueryKeys.list(query),
|
|
10
|
-
...options
|
|
11
|
-
});
|
|
12
|
-
return { ...data, ...rest };
|
|
13
|
-
};
|
|
14
|
-
export {
|
|
15
|
-
regionsQueryKeys,
|
|
16
|
-
useRegions
|
|
17
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { useQuery } from "@tanstack/react-query";
|
|
2
|
-
import { queryKeysFactory } from "../../lib/query-key.js";
|
|
3
|
-
import { sdk } from "../../lib/sdk.js";
|
|
4
|
-
const SALES_CHANNELS_QUERY_KEY = "sales-channels";
|
|
5
|
-
const salesChannelsQueryKeys = queryKeysFactory(
|
|
6
|
-
SALES_CHANNELS_QUERY_KEY
|
|
7
|
-
);
|
|
8
|
-
const useSalesChannel = (id, options) => {
|
|
9
|
-
const { data, ...rest } = useQuery({
|
|
10
|
-
queryKey: salesChannelsQueryKeys.detail(id),
|
|
11
|
-
queryFn: async () => sdk.admin.salesChannel.retrieve(id),
|
|
12
|
-
...options
|
|
13
|
-
});
|
|
14
|
-
return { ...data, ...rest };
|
|
15
|
-
};
|
|
16
|
-
const useSalesChannels = (query, options) => {
|
|
17
|
-
const { data, ...rest } = useQuery({
|
|
18
|
-
queryFn: () => sdk.admin.salesChannel.list(query),
|
|
19
|
-
queryKey: salesChannelsQueryKeys.list(query),
|
|
20
|
-
...options
|
|
21
|
-
});
|
|
22
|
-
return { ...data, ...rest };
|
|
23
|
-
};
|
|
24
|
-
export {
|
|
25
|
-
salesChannelsQueryKeys,
|
|
26
|
-
useSalesChannel,
|
|
27
|
-
useSalesChannels
|
|
28
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { useQuery } from "@tanstack/react-query";
|
|
2
|
-
import { queryKeysFactory } from "../../lib/query-key.js";
|
|
3
|
-
import { sdk } from "../../lib/sdk.js";
|
|
4
|
-
const storeCreditAccountQueryKey = queryKeysFactory(
|
|
5
|
-
"store-credit-account"
|
|
6
|
-
);
|
|
7
|
-
const useStoreCreditAccounts = (query, options) => {
|
|
8
|
-
const fetchStoreCreditAccounts = (query2, headers) => sdk.client.fetch(
|
|
9
|
-
`/admin/store-credit-accounts`,
|
|
10
|
-
{
|
|
11
|
-
query: query2,
|
|
12
|
-
headers
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
const { data, ...rest } = useQuery({
|
|
16
|
-
queryFn: () => fetchStoreCreditAccounts(query),
|
|
17
|
-
queryKey: storeCreditAccountQueryKey.list(query),
|
|
18
|
-
...options
|
|
19
|
-
});
|
|
20
|
-
return { ...data, ...rest };
|
|
21
|
-
};
|
|
22
|
-
const useStoreCreditAccount = (id, query, options) => {
|
|
23
|
-
const fetchStoreCreditAccount = (query2, headers) => sdk.client.fetch(
|
|
24
|
-
`/admin/store-credit-accounts/${id}`,
|
|
25
|
-
{
|
|
26
|
-
query: query2,
|
|
27
|
-
headers
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
const { data, ...rest } = useQuery({
|
|
31
|
-
queryFn: () => fetchStoreCreditAccount(query),
|
|
32
|
-
queryKey: storeCreditAccountQueryKey.list(query),
|
|
33
|
-
...options
|
|
34
|
-
});
|
|
35
|
-
return { ...data, ...rest };
|
|
36
|
-
};
|
|
37
|
-
export {
|
|
38
|
-
storeCreditAccountQueryKey,
|
|
39
|
-
useStoreCreditAccount,
|
|
40
|
-
useStoreCreditAccounts
|
|
41
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { FetchError } from "@medusajs/js-sdk";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
|
-
import { queryKeysFactory } from "../../lib/query-key.js";
|
|
4
|
-
import { sdk } from "../../lib/sdk.js";
|
|
5
|
-
const STORE_QUERY_KEY = "store";
|
|
6
|
-
const storeQueryKeys = queryKeysFactory(STORE_QUERY_KEY);
|
|
7
|
-
async function retrieveActiveStore(query) {
|
|
8
|
-
var _a;
|
|
9
|
-
const response = await sdk.admin.store.list(query);
|
|
10
|
-
const activeStore = (_a = response.stores) == null ? void 0 : _a[0];
|
|
11
|
-
if (!activeStore) {
|
|
12
|
-
throw new FetchError("No active store found", "Not Found", 404);
|
|
13
|
-
}
|
|
14
|
-
return { store: activeStore };
|
|
15
|
-
}
|
|
16
|
-
const useStore = (query, options) => {
|
|
17
|
-
const { data, ...rest } = useQuery({
|
|
18
|
-
queryFn: () => retrieveActiveStore(query),
|
|
19
|
-
queryKey: storeQueryKeys.details(),
|
|
20
|
-
...options
|
|
21
|
-
});
|
|
22
|
-
return {
|
|
23
|
-
...data,
|
|
24
|
-
...rest
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
export {
|
|
28
|
-
retrieveActiveStore,
|
|
29
|
-
storeQueryKeys,
|
|
30
|
-
useStore
|
|
31
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { useQuery } from "@tanstack/react-query";
|
|
2
|
-
import { queryKeysFactory } from "../../lib/query-key.js";
|
|
3
|
-
import { sdk } from "../../lib/sdk.js";
|
|
4
|
-
const transactionGroupQueryKey = queryKeysFactory("transaction-group");
|
|
5
|
-
const useTransactionGroups = (query, options) => {
|
|
6
|
-
const fetchTransactionGroups = (query2, headers) => sdk.client.fetch(
|
|
7
|
-
`/admin/transaction-groups`,
|
|
8
|
-
{
|
|
9
|
-
query: query2,
|
|
10
|
-
headers
|
|
11
|
-
}
|
|
12
|
-
);
|
|
13
|
-
const { data, ...rest } = useQuery({
|
|
14
|
-
queryFn: () => fetchTransactionGroups(query),
|
|
15
|
-
queryKey: transactionGroupQueryKey.list(query),
|
|
16
|
-
...options
|
|
17
|
-
});
|
|
18
|
-
return { ...data, ...rest };
|
|
19
|
-
};
|
|
20
|
-
export {
|
|
21
|
-
transactionGroupQueryKey,
|
|
22
|
-
useTransactionGroups
|
|
23
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { useQuery } from "@tanstack/react-query";
|
|
2
|
-
import { queryKeysFactory } from "../../lib/query-key.js";
|
|
3
|
-
import { sdk } from "../../lib/sdk.js";
|
|
4
|
-
const transactionQueryKey = queryKeysFactory("transaction");
|
|
5
|
-
const useStoreCreditAccountTransactions = (id, query, options) => {
|
|
6
|
-
const fetchStoreCreditAccountTransactions = (query2, headers) => sdk.client.fetch(
|
|
7
|
-
`/admin/store-credit-accounts/${id}/transactions`,
|
|
8
|
-
{
|
|
9
|
-
query: query2,
|
|
10
|
-
headers
|
|
11
|
-
}
|
|
12
|
-
);
|
|
13
|
-
const { data, ...rest } = useQuery({
|
|
14
|
-
queryFn: () => fetchStoreCreditAccountTransactions(query),
|
|
15
|
-
queryKey: transactionQueryKey.list(query),
|
|
16
|
-
...options
|
|
17
|
-
});
|
|
18
|
-
return { ...data, ...rest };
|
|
19
|
-
};
|
|
20
|
-
export {
|
|
21
|
-
transactionQueryKey,
|
|
22
|
-
useStoreCreditAccountTransactions
|
|
23
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { useState, useCallback } from "react";
|
|
2
|
-
const useCommandHistory = (maxHistory = 20) => {
|
|
3
|
-
const [past, setPast] = useState([]);
|
|
4
|
-
const [future, setFuture] = useState([]);
|
|
5
|
-
const canUndo = past.length > 0;
|
|
6
|
-
const canRedo = future.length > 0;
|
|
7
|
-
const undo = useCallback(() => {
|
|
8
|
-
if (!canUndo) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
const previous = past[past.length - 1];
|
|
12
|
-
const newPast = past.slice(0, past.length - 1);
|
|
13
|
-
previous.undo();
|
|
14
|
-
setPast(newPast);
|
|
15
|
-
setFuture([previous, ...future.slice(0, maxHistory - 1)]);
|
|
16
|
-
}, [canUndo, future, past, maxHistory]);
|
|
17
|
-
const redo = useCallback(() => {
|
|
18
|
-
if (!canRedo) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const next = future[0];
|
|
22
|
-
const newFuture = future.slice(1);
|
|
23
|
-
next.redo();
|
|
24
|
-
setPast([...past, next].slice(0, maxHistory - 1));
|
|
25
|
-
setFuture(newFuture);
|
|
26
|
-
}, [canRedo, future, past, maxHistory]);
|
|
27
|
-
const execute = useCallback(
|
|
28
|
-
(command) => {
|
|
29
|
-
command.execute();
|
|
30
|
-
setPast((past2) => [...past2, command].slice(0, maxHistory - 1));
|
|
31
|
-
setFuture([]);
|
|
32
|
-
},
|
|
33
|
-
[maxHistory]
|
|
34
|
-
);
|
|
35
|
-
return {
|
|
36
|
-
undo,
|
|
37
|
-
redo,
|
|
38
|
-
execute,
|
|
39
|
-
canUndo,
|
|
40
|
-
canRedo
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
export {
|
|
44
|
-
useCommandHistory
|
|
45
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { useQuery, useInfiniteQuery, keepPreviousData } from "@tanstack/react-query";
|
|
2
|
-
import { useDebouncedSearch } from "./use-debounced-search.js";
|
|
3
|
-
const useComboboxData = ({
|
|
4
|
-
queryKey,
|
|
5
|
-
queryFn,
|
|
6
|
-
getOptions,
|
|
7
|
-
defaultValue,
|
|
8
|
-
defaultValueKey,
|
|
9
|
-
pageSize = 10
|
|
10
|
-
}) => {
|
|
11
|
-
const { searchValue, onSearchValueChange, query } = useDebouncedSearch();
|
|
12
|
-
const queryInitialDataBy = defaultValueKey || "id";
|
|
13
|
-
const { data: initialData } = useQuery({
|
|
14
|
-
queryKey,
|
|
15
|
-
queryFn: async () => {
|
|
16
|
-
return queryFn({
|
|
17
|
-
[queryInitialDataBy]: defaultValue,
|
|
18
|
-
limit: Array.isArray(defaultValue) ? defaultValue.length : 1
|
|
19
|
-
});
|
|
20
|
-
},
|
|
21
|
-
enabled: !!defaultValue
|
|
22
|
-
});
|
|
23
|
-
const { data, ...rest } = useInfiniteQuery({
|
|
24
|
-
queryKey: [...queryKey, query],
|
|
25
|
-
queryFn: async ({ pageParam = 0 }) => {
|
|
26
|
-
return await queryFn({
|
|
27
|
-
q: query,
|
|
28
|
-
limit: pageSize,
|
|
29
|
-
offset: pageParam
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
initialPageParam: 0,
|
|
33
|
-
getNextPageParam: (lastPage) => {
|
|
34
|
-
const moreItemsExist = lastPage.count > lastPage.offset + lastPage.limit;
|
|
35
|
-
return moreItemsExist ? lastPage.offset + lastPage.limit : void 0;
|
|
36
|
-
},
|
|
37
|
-
placeholderData: keepPreviousData
|
|
38
|
-
});
|
|
39
|
-
const options = (data == null ? void 0 : data.pages.flatMap((page) => getOptions(page))) ?? [];
|
|
40
|
-
const defaultOptions = initialData ? getOptions(initialData) : [];
|
|
41
|
-
const disabled = !rest.isPending && !options.length && !searchValue;
|
|
42
|
-
if (defaultValue && defaultOptions.length && !searchValue) {
|
|
43
|
-
defaultOptions.forEach((option) => {
|
|
44
|
-
if (!options.find((o) => o.value === option.value)) {
|
|
45
|
-
options.unshift(option);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
options,
|
|
51
|
-
searchValue,
|
|
52
|
-
onSearchValueChange,
|
|
53
|
-
disabled,
|
|
54
|
-
...rest
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
export {
|
|
58
|
-
useComboboxData
|
|
59
|
-
};
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { createDataTableFilterHelper } from "@medusajs/ui";
|
|
2
|
-
import { subDays, subMonths } from "date-fns";
|
|
3
|
-
import { useMemo } from "react";
|
|
4
|
-
import { getFullDate } from "../../utils/date-utils.js";
|
|
5
|
-
const filterHelper = createDataTableFilterHelper();
|
|
6
|
-
const useDateFilterOptions = () => {
|
|
7
|
-
const today = useMemo(() => {
|
|
8
|
-
const date = /* @__PURE__ */ new Date();
|
|
9
|
-
date.setHours(0, 0, 0, 0);
|
|
10
|
-
return date;
|
|
11
|
-
}, []);
|
|
12
|
-
return useMemo(() => {
|
|
13
|
-
return [
|
|
14
|
-
{
|
|
15
|
-
label: "Today",
|
|
16
|
-
value: {
|
|
17
|
-
$gte: today.toISOString()
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
label: "Last 7 days",
|
|
22
|
-
value: {
|
|
23
|
-
$gte: subDays(today, 7).toISOString()
|
|
24
|
-
// 7 days ago
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
label: "Last 30 days",
|
|
29
|
-
value: {
|
|
30
|
-
$gte: subDays(today, 30).toISOString()
|
|
31
|
-
// 30 days ago
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
label: "Last 90 days",
|
|
36
|
-
value: {
|
|
37
|
-
$gte: subDays(today, 90).toISOString()
|
|
38
|
-
// 90 days ago
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
label: "Last 12 months",
|
|
43
|
-
value: {
|
|
44
|
-
$gte: subMonths(today, 12).toISOString()
|
|
45
|
-
// 12 months ago
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
];
|
|
49
|
-
}, [today]);
|
|
50
|
-
};
|
|
51
|
-
const useDataTableDateFilters = (disableRangeOption) => {
|
|
52
|
-
const dateFilterOptions = useDateFilterOptions();
|
|
53
|
-
const rangeOptions = useMemo(() => {
|
|
54
|
-
if (disableRangeOption) {
|
|
55
|
-
return {
|
|
56
|
-
disableRangeOption: true
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
rangeOptionStartLabel: "Starting",
|
|
61
|
-
rangeOptionEndLabel: "Ending",
|
|
62
|
-
rangeOptionLabel: "Custom",
|
|
63
|
-
options: dateFilterOptions
|
|
64
|
-
};
|
|
65
|
-
}, [disableRangeOption, dateFilterOptions]);
|
|
66
|
-
return useMemo(() => {
|
|
67
|
-
return [
|
|
68
|
-
filterHelper.accessor("created_at", {
|
|
69
|
-
type: "date",
|
|
70
|
-
label: "Created at",
|
|
71
|
-
format: "date",
|
|
72
|
-
formatDateValue: (date) => getFullDate({ date }),
|
|
73
|
-
options: dateFilterOptions,
|
|
74
|
-
...rangeOptions
|
|
75
|
-
}),
|
|
76
|
-
filterHelper.accessor("updated_at", {
|
|
77
|
-
type: "date",
|
|
78
|
-
label: "Updated at",
|
|
79
|
-
format: "date",
|
|
80
|
-
formatDateValue: (date) => getFullDate({ date }),
|
|
81
|
-
options: dateFilterOptions,
|
|
82
|
-
...rangeOptions
|
|
83
|
-
})
|
|
84
|
-
];
|
|
85
|
-
}, [dateFilterOptions, getFullDate, rangeOptions]);
|
|
86
|
-
};
|
|
87
|
-
export {
|
|
88
|
-
useDataTableDateFilters
|
|
89
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { formatDistance, sub, format } from "date-fns";
|
|
2
|
-
import { enUS } from "/Users/oliverjuhl/Desktop/medusa/loyalty-plugin/node_modules/date-fns/locale.mjs";
|
|
3
|
-
const useDate = () => {
|
|
4
|
-
const locale = enUS;
|
|
5
|
-
const getFullDate = ({
|
|
6
|
-
date,
|
|
7
|
-
includeTime = false
|
|
8
|
-
}) => {
|
|
9
|
-
const ensuredDate = new Date(date);
|
|
10
|
-
if (isNaN(ensuredDate.getTime())) {
|
|
11
|
-
return "";
|
|
12
|
-
}
|
|
13
|
-
const timeFormat = includeTime ? "p" : "";
|
|
14
|
-
return format(ensuredDate, `PP ${timeFormat}`, {
|
|
15
|
-
locale
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
function getRelativeDate(date) {
|
|
19
|
-
const now = /* @__PURE__ */ new Date();
|
|
20
|
-
return formatDistance(sub(new Date(date), { minutes: 0 }), now, {
|
|
21
|
-
addSuffix: true,
|
|
22
|
-
locale
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
getFullDate,
|
|
27
|
-
getRelativeDate
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
export {
|
|
31
|
-
useDate
|
|
32
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import debounce from "/Users/oliverjuhl/Desktop/medusa/loyalty-plugin/node_modules/lodash/debounce.js";
|
|
2
|
-
import { useState, useCallback, useEffect } from "react";
|
|
3
|
-
const useDebouncedSearch = () => {
|
|
4
|
-
const [searchValue, onSearchValueChange] = useState("");
|
|
5
|
-
const [debouncedQuery, setDebouncedQuery] = useState("");
|
|
6
|
-
const debouncedUpdate = useCallback(
|
|
7
|
-
debounce((query) => setDebouncedQuery(query), 300),
|
|
8
|
-
[]
|
|
9
|
-
);
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
debouncedUpdate(searchValue);
|
|
12
|
-
return () => debouncedUpdate.cancel();
|
|
13
|
-
}, [searchValue, debouncedUpdate]);
|
|
14
|
-
return {
|
|
15
|
-
searchValue,
|
|
16
|
-
onSearchValueChange,
|
|
17
|
-
query: debouncedQuery || void 0
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
export {
|
|
21
|
-
useDebouncedSearch
|
|
22
|
-
};
|