@medusajs/loyalty-plugin 0.0.1
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/components/action-menu.js +63 -0
- package/.medusa/server/src/admin/components/chip-group.js +82 -0
- package/.medusa/server/src/admin/components/chip-input.js +157 -0
- package/.medusa/server/src/admin/components/combobox.js +324 -0
- package/.medusa/server/src/admin/components/conditional-tooltip.js +15 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-boolean-cell.js +66 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-cell-container.js +77 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-currency-cell.js +110 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-duplicate-cell.js +16 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-keyboard-shortcut-modal.js +214 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-number-cell.js +77 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-readonly-cell.js +32 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-root.js +743 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-row-error-indicator.js +37 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-skeleton.js +54 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-text-cell.js +66 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-toggleable-number-cell.js +166 -0
- package/.medusa/server/src/admin/components/data-grid/components/index.js +16 -0
- package/.medusa/server/src/admin/components/data-grid/context/data-grid-context.js +7 -0
- package/.medusa/server/src/admin/components/data-grid/context/index.js +6 -0
- package/.medusa/server/src/admin/components/data-grid/context/use-data-grid-context.js +14 -0
- package/.medusa/server/src/admin/components/data-grid/data-grid.js +31 -0
- package/.medusa/server/src/admin/components/data-grid/helpers/create-data-grid-column-helper.js +28 -0
- package/.medusa/server/src/admin/components/data-grid/helpers/create-data-grid-price-columns.js +85 -0
- package/.medusa/server/src/admin/components/data-grid/helpers/index.js +6 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/index.js +31 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-error.js +50 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-handlers.js +123 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-metadata.js +52 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-snapshot.js +43 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell.js +191 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-clipboard-events.js +70 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-column-visibility.js +51 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-duplicate-cell.js +15 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-error-highlighting.js +86 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-form-handlers.js +149 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-keydown-event.js +482 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-mouse-up-event.js +64 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-navigation.js +81 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-query-tool.js +14 -0
- package/.medusa/server/src/admin/components/data-grid/index.js +8 -0
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-bulk-update-command.js +27 -0
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-matrix.js +296 -0
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-query-tool.js +62 -0
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-update-command.js +25 -0
- package/.medusa/server/src/admin/components/data-grid/models/index.js +10 -0
- package/.medusa/server/src/admin/components/data-grid/types.js +1 -0
- package/.medusa/server/src/admin/components/data-grid/utils.js +18 -0
- package/.medusa/server/src/admin/components/data-table/components/data-table-status-cell/data-table-status-cell.js +36 -0
- package/.medusa/server/src/admin/components/data-table/data-table.js +271 -0
- package/.medusa/server/src/admin/components/data-table/helpers/general/use-data-table-date-columns.js +51 -0
- package/.medusa/server/src/admin/components/data-table/helpers/general/use-data-table-date-filters.js +90 -0
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/index.js +10 -0
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-columns.js +48 -0
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-empty-state.js +19 -0
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-filters.js +30 -0
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-query.js +23 -0
- package/.medusa/server/src/admin/components/data-table/index.js +4 -0
- package/.medusa/server/src/admin/components/data-table.js +249 -0
- package/.medusa/server/src/admin/components/display-id.js +18 -0
- package/.medusa/server/src/admin/components/file-upload.js +116 -0
- package/.medusa/server/src/admin/components/form.js +151 -0
- package/.medusa/server/src/admin/components/handle-input.js +22 -0
- package/.medusa/server/src/admin/components/header.js +41 -0
- package/.medusa/server/src/admin/components/icon-avatar.js +27 -0
- package/.medusa/server/src/admin/components/json-view-section.js +139 -0
- package/.medusa/server/src/admin/components/keybound-form.js +32 -0
- package/.medusa/server/src/admin/components/layouts/single-column.js +7 -0
- package/.medusa/server/src/admin/components/layouts/two-column.js +13 -0
- package/.medusa/server/src/admin/components/listicle.js +20 -0
- package/.medusa/server/src/admin/components/modals/index.js +19 -0
- package/.medusa/server/src/admin/components/modals/route-drawer/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-drawer/route-drawer.js +57 -0
- package/.medusa/server/src/admin/components/modals/route-focus-modal/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-focus-modal/route-focus-modal.js +71 -0
- package/.medusa/server/src/admin/components/modals/route-modal-form/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-modal-form/route-modal-form.js +60 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/index.js +6 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/route-modal-context.js +5 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/route-provider.js +30 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/use-route-modal.js +12 -0
- package/.medusa/server/src/admin/components/modals/stacked-drawer/index.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-drawer/stacked-drawer.js +55 -0
- package/.medusa/server/src/admin/components/modals/stacked-focus-modal/index.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-focus-modal/stacked-focus-modal.js +63 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/index.js +6 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-context.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-provider.js +47 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/use-stacked-modal.js +14 -0
- package/.medusa/server/src/admin/components/placeholder-cell.js +7 -0
- package/.medusa/server/src/admin/components/product/product-cell/index.js +5 -0
- package/.medusa/server/src/admin/components/product/product-cell/product-cell.js +15 -0
- package/.medusa/server/src/admin/components/product/product-status-cell/index.js +5 -0
- package/.medusa/server/src/admin/components/product/product-status-cell/product-status-cell.js +18 -0
- package/.medusa/server/src/admin/components/product/sales-channels-cell/index.js +5 -0
- package/.medusa/server/src/admin/components/product/sales-channels-cell/sales-channels-cell.js +31 -0
- package/.medusa/server/src/admin/components/product/variant-cell/index.js +5 -0
- package/.medusa/server/src/admin/components/product/variant-cell/variant-cell.js +15 -0
- package/.medusa/server/src/admin/components/section-row.js +32 -0
- package/.medusa/server/src/admin/components/sidebar-link.js +31 -0
- package/.medusa/server/src/admin/components/sortable-list.js +152 -0
- package/.medusa/server/src/admin/components/switch-box.js +43 -0
- package/.medusa/server/src/admin/components/tax-badge.js +18 -0
- package/.medusa/server/src/admin/components/thumbnail.js +28 -0
- package/.medusa/server/src/admin/components/upload-media-form-item.js +83 -0
- package/.medusa/server/src/admin/hooks/api/customers.js +26 -0
- package/.medusa/server/src/admin/hooks/api/gift-cards.js +107 -0
- package/.medusa/server/src/admin/hooks/api/order.js +16 -0
- package/.medusa/server/src/admin/hooks/api/price-preferences.js +19 -0
- package/.medusa/server/src/admin/hooks/api/products.js +127 -0
- package/.medusa/server/src/admin/hooks/api/regions.js +17 -0
- package/.medusa/server/src/admin/hooks/api/sales-channels.js +28 -0
- package/.medusa/server/src/admin/hooks/api/store-credit-accounts.js +41 -0
- package/.medusa/server/src/admin/hooks/api/store.js +31 -0
- package/.medusa/server/src/admin/hooks/api/transaction-groups.js +23 -0
- package/.medusa/server/src/admin/hooks/api/transactions.js +23 -0
- package/.medusa/server/src/admin/hooks/commands/use-command-history.js +45 -0
- package/.medusa/server/src/admin/hooks/common/use-combobox-data.js +59 -0
- package/.medusa/server/src/admin/hooks/common/use-data-table-date-filters.js +89 -0
- package/.medusa/server/src/admin/hooks/common/use-date.js +32 -0
- package/.medusa/server/src/admin/hooks/common/use-debounced-search.js +22 -0
- package/.medusa/server/src/admin/hooks/common/use-query-params.js +14 -0
- package/.medusa/server/src/admin/hooks/query/use-customers-filters.js +30 -0
- package/.medusa/server/src/admin/hooks/query/use-transaction-groups-filters.js +30 -0
- package/.medusa/server/src/admin/hooks/sales-channels/index.js +10 -0
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-columns.js +48 -0
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-empty-state.js +19 -0
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-filters.js +30 -0
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-query.js +23 -0
- package/.medusa/server/src/admin/lib/currencies.js +729 -0
- package/.medusa/server/src/admin/lib/query-key.js +17 -0
- package/.medusa/server/src/admin/lib/sdk.js +10 -0
- package/.medusa/server/src/admin/routes/gift-card-products/@create/page.js +75 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@denominations/components/gift-card-product-edit-denominations-form.js +172 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@denominations/page.js +30 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@edit/components/gift-card-product-edit-form.js +180 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@edit/page.js +30 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-general-section.js +97 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-media-section.js +162 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-sales-channel-section.js +89 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-variant-section.js +199 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/edit-product-media-form/edit-product-media-form.js +353 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/edit-product-media-form/index.js +5 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-gallery/index.js +4 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-gallery/product-media-gallery.js +247 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/index.js +4 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/product-media-view-context.js +5 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/product-media-view.js +48 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/use-product-media-view.js +14 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/page.js +28 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/page.js +40 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/prices/components/prices-edit.js +121 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/prices/components/variant-pricing-form.js +72 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/prices/page.js +23 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/sales-channels/components/edit-sales-channel-form.js +123 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/sales-channels/page.js +23 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/general-form-section.js +1 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-denominations-form.js +98 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-details-form.js +28 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-denominations.js +96 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-general.js +90 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-media.js +288 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-organize-section.js +111 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-organize.js +23 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form.js +285 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-sales-channel-stacked-modal.js +124 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/index.js +4 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/schema.js +112 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/types.js +1 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/columns.js +35 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/filters.js +11 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/gift-card-products-table.js +61 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/query.js +23 -0
- package/.medusa/server/src/admin/routes/gift-card-products/page.js +18 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@expiration/page.js +137 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@note/page.js +87 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@owner/components/transfer-icon.js +352 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@owner/page.js +116 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-balance-section.js +49 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-general-section.js +177 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-note-section.js +27 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-order-section.js +33 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-owner-section.js +33 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-transactions-section.js +18 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/transactions-table/columns.js +50 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/transactions-table/query.js +23 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/page.js +78 -0
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-card-products-section.js +40 -0
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/columns.js +57 -0
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/filters.js +13 -0
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/gift-cards-table.js +61 -0
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/query.js +23 -0
- package/.medusa/server/src/admin/routes/gift-cards/page.js +27 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/credit-card-icon.js +126 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/store-credit-account-balance-section.js +31 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/store-credit-account-details-section.js +43 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/columns.js +44 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/filters.js +18 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/query.js +37 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/table.js +58 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/page.js +39 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/columns.js +58 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/filters.js +13 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/query.js +31 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/table.js +56 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/page.js +19 -0
- package/.medusa/server/src/admin/utils/date-utils.js +27 -0
- package/.medusa/server/src/admin/utils/format-amount.js +9 -0
- package/.medusa/server/src/admin/utils/format-date.js +21 -0
- package/.medusa/server/src/admin/utils/refs.js +20 -0
- package/.medusa/server/src/admin/utils/statuses.js +23 -0
- package/.medusa/server/src/admin/utils/validations.js +71 -0
- package/.medusa/server/src/admin/utils/variants.js +92 -0
- package/.medusa/server/src/admin/widgets/customer-gift-cards-widget.js +67 -0
- package/.medusa/server/src/admin/widgets/customer-store-credit-widget.js +42 -0
- package/.medusa/server/src/admin/widgets/order-gift-cards-widget.js +58 -0
- package/.medusa/server/src/api/admin/gift-cards/[id]/redeem/route.js +25 -0
- package/.medusa/server/src/api/admin/gift-cards/[id]/route.js +41 -0
- package/.medusa/server/src/api/admin/gift-cards/[id]/transfer/route.js +24 -0
- package/.medusa/server/src/api/admin/gift-cards/middlewares.js +55 -0
- package/.medusa/server/src/api/admin/gift-cards/query-config.js +29 -0
- package/.medusa/server/src/api/admin/gift-cards/route.js +42 -0
- package/.medusa/server/src/api/admin/gift-cards/validators.js +69 -0
- package/.medusa/server/src/api/admin/store-credit-accounts/[id]/route.js +24 -0
- package/.medusa/server/src/api/admin/store-credit-accounts/[id]/transactions/route.js +23 -0
- package/.medusa/server/src/api/admin/store-credit-accounts/middlewares.js +38 -0
- package/.medusa/server/src/api/admin/store-credit-accounts/query-config.js +43 -0
- package/.medusa/server/src/api/admin/store-credit-accounts/route.js +52 -0
- package/.medusa/server/src/api/admin/store-credit-accounts/validators.js +51 -0
- package/.medusa/server/src/api/admin/transaction-groups/middlewares.js +16 -0
- package/.medusa/server/src/api/admin/transaction-groups/query-config.js +13 -0
- package/.medusa/server/src/api/admin/transaction-groups/route.js +27 -0
- package/.medusa/server/src/api/admin/transaction-groups/validators.js +19 -0
- package/.medusa/server/src/api/middlewares.js +22 -0
- package/.medusa/server/src/api/store/carts/[id]/gift-cards/route.js +43 -0
- package/.medusa/server/src/api/store/carts/middlewares.js +26 -0
- package/.medusa/server/src/api/store/carts/query-config.js +9 -0
- package/.medusa/server/src/api/store/carts/validators.js +15 -0
- package/.medusa/server/src/api/store/gift-card-invitations/[code]/accept/route.js +24 -0
- package/.medusa/server/src/api/store/gift-card-invitations/[code]/reject/route.js +24 -0
- package/.medusa/server/src/api/store/gift-card-invitations/middlewares.js +30 -0
- package/.medusa/server/src/api/store/gift-card-invitations/query-config.js +17 -0
- package/.medusa/server/src/api/store/gift-card-invitations/validators.js +14 -0
- package/.medusa/server/src/api/store/gift-cards/[id]/invitation/route.js +26 -0
- package/.medusa/server/src/api/store/gift-cards/[id]/redeem/route.js +24 -0
- package/.medusa/server/src/api/store/gift-cards/[id]/route.js +16 -0
- package/.medusa/server/src/api/store/gift-cards/middlewares.js +46 -0
- package/.medusa/server/src/api/store/gift-cards/query-config.js +26 -0
- package/.medusa/server/src/api/store/gift-cards/route.js +28 -0
- package/.medusa/server/src/api/store/gift-cards/validators.js +26 -0
- package/.medusa/server/src/api/store/store-credit-accounts/[id]/route.js +31 -0
- package/.medusa/server/src/api/store/store-credit-accounts/middlewares.js +28 -0
- package/.medusa/server/src/api/store/store-credit-accounts/query-config.js +24 -0
- package/.medusa/server/src/api/store/store-credit-accounts/route.js +40 -0
- package/.medusa/server/src/api/store/store-credit-accounts/validators.js +17 -0
- package/.medusa/server/src/links/cart-gift-cards-link.js +13 -0
- package/.medusa/server/src/links/customer-gift-card-link.js +13 -0
- package/.medusa/server/src/links/customer-store-credit-account-link.js +13 -0
- package/.medusa/server/src/links/order-gift-cards-link.js +13 -0
- package/.medusa/server/src/links/order-line-item-gift-card-link.js +19 -0
- package/.medusa/server/src/modules/loyalty/index.js +12 -0
- package/.medusa/server/src/modules/loyalty/migrations/Migration20250123130553.js +17 -0
- package/.medusa/server/src/modules/loyalty/migrations/Migration20250127174331.js +19 -0
- package/.medusa/server/src/modules/loyalty/migrations/Migration20250206141026.js +19 -0
- package/.medusa/server/src/modules/loyalty/migrations/Migration20250206141429.js +14 -0
- package/.medusa/server/src/modules/loyalty/migrations/Migration20250206144714.js +14 -0
- package/.medusa/server/src/modules/loyalty/models/gift-card-invitation.js +20 -0
- package/.medusa/server/src/modules/loyalty/models/gift-card.js +28 -0
- package/.medusa/server/src/modules/loyalty/service.js +15 -0
- package/.medusa/server/src/modules/store-credit/index.js +12 -0
- package/.medusa/server/src/modules/store-credit/migrations/Migration20250129115518.js +16 -0
- package/.medusa/server/src/modules/store-credit/migrations/Migration20250130213237.js +18 -0
- package/.medusa/server/src/modules/store-credit/migrations/Migration20250130220640.js +19 -0
- package/.medusa/server/src/modules/store-credit/migrations/Migration20250131205753.js +14 -0
- package/.medusa/server/src/modules/store-credit/models/account-transaction.js +27 -0
- package/.medusa/server/src/modules/store-credit/models/store-credit-account.js +29 -0
- package/.medusa/server/src/modules/store-credit/models/transaction-group.js +28 -0
- package/.medusa/server/src/modules/store-credit/service.js +412 -0
- package/.medusa/server/src/providers/index.js +12 -0
- package/.medusa/server/src/providers/store-credit-payment/index.js +12 -0
- package/.medusa/server/src/providers/store-credit-payment/service.js +181 -0
- package/.medusa/server/src/subscribers/create-gift-card.js +94 -0
- package/.medusa/server/src/types/cart/index.js +3 -0
- package/.medusa/server/src/types/http/gift-card.js +3 -0
- package/.medusa/server/src/types/http/index.js +21 -0
- package/.medusa/server/src/types/http/store-credit-account.js +3 -0
- package/.medusa/server/src/types/http/transaction-group.js +3 -0
- package/.medusa/server/src/types/http/transaction.js +3 -0
- package/.medusa/server/src/types/index.js +21 -0
- package/.medusa/server/src/types/loyalty/index.js +20 -0
- package/.medusa/server/src/types/loyalty/module.js +17 -0
- package/.medusa/server/src/types/loyalty/service.js +3 -0
- package/.medusa/server/src/types/loyalty/workflows.js +3 -0
- package/.medusa/server/src/types/modules.js +14 -0
- package/.medusa/server/src/types/store-credit/index.js +19 -0
- package/.medusa/server/src/types/store-credit/module.js +10 -0
- package/.medusa/server/src/types/store-credit/service.js +3 -0
- package/.medusa/server/src/workflows/carts/workflows/add-gift-card-to-cart.js +167 -0
- package/.medusa/server/src/workflows/carts/workflows/confirm-cart-credit-lines.js +95 -0
- package/.medusa/server/src/workflows/carts/workflows/refresh-cart-gift-cards.js +136 -0
- package/.medusa/server/src/workflows/carts/workflows/remove-gift-cart-from-cart.js +66 -0
- package/.medusa/server/src/workflows/common/steps/validate-presence-of.js +11 -0
- package/.medusa/server/src/workflows/gift-card-invitation/steps/create-gift-card-invitation.js +17 -0
- package/.medusa/server/src/workflows/gift-card-invitation/steps/delete-gift-card-invitation.js +20 -0
- package/.medusa/server/src/workflows/gift-card-invitation/steps/update-gift-card-invitation.js +31 -0
- package/.medusa/server/src/workflows/gift-card-invitation/workflows/accept-gift-card-invitation.js +79 -0
- package/.medusa/server/src/workflows/gift-card-invitation/workflows/create-gift-card-invitation.js +66 -0
- package/.medusa/server/src/workflows/gift-card-invitation/workflows/delete-gift-card-invitation.js +10 -0
- package/.medusa/server/src/workflows/gift-card-invitation/workflows/reject-gift-card-invitation.js +70 -0
- package/.medusa/server/src/workflows/gift-cards/steps/create-gift-cards.js +17 -0
- package/.medusa/server/src/workflows/gift-cards/steps/delete-gift-cards.js +17 -0
- package/.medusa/server/src/workflows/gift-cards/steps/retrieve-gift-card-balance.js +20 -0
- package/.medusa/server/src/workflows/gift-cards/steps/update-gift-cards.js +34 -0
- package/.medusa/server/src/workflows/gift-cards/workflows/create-gift-cards.js +12 -0
- package/.medusa/server/src/workflows/gift-cards/workflows/delete-gift-card.js +19 -0
- package/.medusa/server/src/workflows/gift-cards/workflows/redeem-gift-card.js +90 -0
- package/.medusa/server/src/workflows/gift-cards/workflows/transfer-gift-card.js +48 -0
- package/.medusa/server/src/workflows/gift-cards/workflows/update-gift-cards.js +12 -0
- package/.medusa/server/src/workflows/hooks/after-order-created.js +31 -0
- package/.medusa/server/src/workflows/hooks/after-order-credit-lines-created.js +31 -0
- package/.medusa/server/src/workflows/hooks/before-payment-collection-refresh.js +26 -0
- package/.medusa/server/src/workflows/hooks/complete-cart-before-payment-authorization.js +27 -0
- package/.medusa/server/src/workflows/orders/workflows/link-gift-cards-to-order.js +58 -0
- package/.medusa/server/src/workflows/orders/workflows/refund-gift-card-credit-lines.js +96 -0
- package/.medusa/server/src/workflows/store-credit/steps/create-store-credit-accounts.js +17 -0
- package/.medusa/server/src/workflows/store-credit/steps/create-transaction-groups.js +17 -0
- package/.medusa/server/src/workflows/store-credit/steps/credit-account.js +17 -0
- package/.medusa/server/src/workflows/store-credit/steps/debit-account.js +17 -0
- package/.medusa/server/src/workflows/store-credit/workflows/create-store-credit-accounts.js +57 -0
- package/.medusa/server/src/workflows/store-credit/workflows/create-transaction-groups.js +12 -0
- package/.medusa/server/src/workflows/store-credit/workflows/credit-accounts.js +12 -0
- package/.medusa/server/src/workflows/store-credit/workflows/debit-accounts.js +12 -0
- package/.medusa/server/types/loyalty/module.js +8 -0
- package/README.md +62 -0
- package/package.json +94 -0
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { defaultDropAnimationSideEffects, useSensors, useSensor, PointerSensor, KeyboardSensor, DndContext, DragOverlay } from "/Users/oliverjuhl/Desktop/medusa/loyalty-plugin/node_modules/@dnd-kit/core/dist/core.esm.js";
|
|
3
|
+
import { sortableKeyboardCoordinates, SortableContext, rectSortingStrategy, arrayMove, useSortable } from "/Users/oliverjuhl/Desktop/medusa/loyalty-plugin/node_modules/@dnd-kit/sortable/dist/sortable.esm.js";
|
|
4
|
+
import { CSS } from "/Users/oliverjuhl/Desktop/medusa/loyalty-plugin/node_modules/@dnd-kit/utilities/dist/utilities.esm.js";
|
|
5
|
+
import { zodResolver } from "/Users/oliverjuhl/Desktop/medusa/loyalty-plugin/node_modules/@hookform/resolvers/zod/dist/zod.mjs";
|
|
6
|
+
import { ThumbnailBadge } from "@medusajs/icons";
|
|
7
|
+
import { toast, Button, CommandBar, clx, Checkbox, Tooltip } from "@medusajs/ui";
|
|
8
|
+
import { useState, useCallback, Fragment } from "react";
|
|
9
|
+
import { useForm, useFieldArray } from "/Users/oliverjuhl/Desktop/medusa/loyalty-plugin/node_modules/react-hook-form/dist/index.esm.mjs";
|
|
10
|
+
import { Link } from "react-router-dom";
|
|
11
|
+
import { KeyboundForm } from "../../../../../../components/keybound-form.js";
|
|
12
|
+
import "../../../../../../components/modals/route-drawer/route-drawer.js";
|
|
13
|
+
import { RouteFocusModal } from "../../../../../../components/modals/route-focus-modal/route-focus-modal.js";
|
|
14
|
+
import "../../../../../../components/modals/route-modal-provider/route-modal-context.js";
|
|
15
|
+
import { useRouteModal } from "../../../../../../components/modals/route-modal-provider/use-route-modal.js";
|
|
16
|
+
import "../../../../../../components/modals/stacked-drawer/stacked-drawer.js";
|
|
17
|
+
import "../../../../../../components/modals/stacked-focus-modal/stacked-focus-modal.js";
|
|
18
|
+
import "../../../../../../components/modals/stacked-modal-provider/stacked-modal-context.js";
|
|
19
|
+
import { UploadMediaFormItem } from "../../../../../../components/upload-media-form-item.js";
|
|
20
|
+
import { useUpdateProduct } from "../../../../../../hooks/api/products.js";
|
|
21
|
+
import { sdk } from "../../../../../../lib/sdk.js";
|
|
22
|
+
import { EditProductMediaSchema } from "../../../../components/gift-card-product-create-form/schema.js";
|
|
23
|
+
const EditProductMediaForm = ({ product }) => {
|
|
24
|
+
const [selection, setSelection] = useState({});
|
|
25
|
+
const { handleSuccess } = useRouteModal();
|
|
26
|
+
const form = useForm({
|
|
27
|
+
defaultValues: {
|
|
28
|
+
media: getDefaultValues(product.images, product.thumbnail)
|
|
29
|
+
},
|
|
30
|
+
resolver: zodResolver(EditProductMediaSchema)
|
|
31
|
+
});
|
|
32
|
+
const { fields, append, remove, update } = useFieldArray({
|
|
33
|
+
name: "media",
|
|
34
|
+
control: form.control,
|
|
35
|
+
keyName: "field_id"
|
|
36
|
+
});
|
|
37
|
+
const [activeId, setActiveId] = useState(null);
|
|
38
|
+
const sensors = useSensors(
|
|
39
|
+
useSensor(PointerSensor),
|
|
40
|
+
useSensor(KeyboardSensor, {
|
|
41
|
+
coordinateGetter: sortableKeyboardCoordinates
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
const handleDragStart = (event) => {
|
|
45
|
+
setActiveId(event.active.id);
|
|
46
|
+
};
|
|
47
|
+
const handleDragEnd = (event) => {
|
|
48
|
+
setActiveId(null);
|
|
49
|
+
const { active, over } = event;
|
|
50
|
+
if (active.id !== (over == null ? void 0 : over.id)) {
|
|
51
|
+
const oldIndex = fields.findIndex((item) => item.field_id === active.id);
|
|
52
|
+
const newIndex = fields.findIndex((item) => item.field_id === (over == null ? void 0 : over.id));
|
|
53
|
+
form.setValue("media", arrayMove(fields, oldIndex, newIndex), {
|
|
54
|
+
shouldDirty: true,
|
|
55
|
+
shouldTouch: true
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const handleDragCancel = () => {
|
|
60
|
+
setActiveId(null);
|
|
61
|
+
};
|
|
62
|
+
const { mutateAsync, isPending } = useUpdateProduct(product.id);
|
|
63
|
+
const handleSubmit = form.handleSubmit(async ({ media }) => {
|
|
64
|
+
var _a;
|
|
65
|
+
const filesToUpload = media.map((m, i) => ({ file: m.file, index: i })).filter((m) => !!m.file);
|
|
66
|
+
let uploaded = [];
|
|
67
|
+
if (filesToUpload.length) {
|
|
68
|
+
const { files: uploads } = await sdk.admin.upload.create({ files: filesToUpload.map((m) => m.file) }).catch(() => {
|
|
69
|
+
form.setError("media", {
|
|
70
|
+
type: "invalid_file",
|
|
71
|
+
message: "Failed to upload media"
|
|
72
|
+
});
|
|
73
|
+
return { files: [] };
|
|
74
|
+
});
|
|
75
|
+
uploaded = uploads;
|
|
76
|
+
}
|
|
77
|
+
const withUpdatedUrls = media.map((entry, i) => {
|
|
78
|
+
var _a2;
|
|
79
|
+
const toUploadIndex = filesToUpload.findIndex((m) => m.index === i);
|
|
80
|
+
if (toUploadIndex > -1) {
|
|
81
|
+
return { ...entry, url: (_a2 = uploaded[toUploadIndex]) == null ? void 0 : _a2.url };
|
|
82
|
+
}
|
|
83
|
+
return entry;
|
|
84
|
+
});
|
|
85
|
+
const thumbnail = (_a = withUpdatedUrls.find((m) => m.isThumbnail)) == null ? void 0 : _a.url;
|
|
86
|
+
await mutateAsync(
|
|
87
|
+
{
|
|
88
|
+
images: withUpdatedUrls.map((file) => ({ url: file.url, id: file.id })),
|
|
89
|
+
thumbnail: thumbnail || null
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
onSuccess: () => {
|
|
93
|
+
toast.success("Product media updated");
|
|
94
|
+
handleSuccess();
|
|
95
|
+
},
|
|
96
|
+
onError: (error) => {
|
|
97
|
+
toast.error(error.message);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
const handleCheckedChange = useCallback(
|
|
103
|
+
(id) => {
|
|
104
|
+
return (val) => {
|
|
105
|
+
if (!val) {
|
|
106
|
+
const { [id]: _, ...rest } = selection;
|
|
107
|
+
setSelection(rest);
|
|
108
|
+
} else {
|
|
109
|
+
setSelection((prev) => ({ ...prev, [id]: true }));
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
[selection]
|
|
114
|
+
);
|
|
115
|
+
const handleDelete = () => {
|
|
116
|
+
const ids = Object.keys(selection);
|
|
117
|
+
const indices = ids.map((id) => fields.findIndex((m) => m.id === id));
|
|
118
|
+
remove(indices);
|
|
119
|
+
setSelection({});
|
|
120
|
+
};
|
|
121
|
+
const handlePromoteToThumbnail = () => {
|
|
122
|
+
const ids = Object.keys(selection);
|
|
123
|
+
if (!ids.length) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const currentThumbnailIndex = fields.findIndex((m) => m.isThumbnail);
|
|
127
|
+
if (currentThumbnailIndex > -1) {
|
|
128
|
+
update(currentThumbnailIndex, {
|
|
129
|
+
...fields[currentThumbnailIndex],
|
|
130
|
+
isThumbnail: false
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const index = fields.findIndex((m) => m.id === ids[0]);
|
|
134
|
+
update(index, {
|
|
135
|
+
...fields[index],
|
|
136
|
+
isThumbnail: true
|
|
137
|
+
});
|
|
138
|
+
setSelection({});
|
|
139
|
+
};
|
|
140
|
+
const selectionCount = Object.keys(selection).length;
|
|
141
|
+
return /* @__PURE__ */ jsx(RouteFocusModal.Form, { blockSearchParams: true, form, children: /* @__PURE__ */ jsxs(
|
|
142
|
+
KeyboundForm,
|
|
143
|
+
{
|
|
144
|
+
className: "flex size-full flex-col overflow-hidden",
|
|
145
|
+
onSubmit: handleSubmit,
|
|
146
|
+
children: [
|
|
147
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, { children: /* @__PURE__ */ jsx("div", { className: "flex items-center justify-end gap-x-2", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", asChild: true, children: /* @__PURE__ */ jsx(Link, { to: { pathname: ".", search: void 0 }, children: "Gallery" }) }) }) }),
|
|
148
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-col overflow-hidden", children: /* @__PURE__ */ jsxs("div", { className: "flex size-full flex-col-reverse lg:grid lg:grid-cols-[1fr_560px]", children: [
|
|
149
|
+
/* @__PURE__ */ jsx(
|
|
150
|
+
DndContext,
|
|
151
|
+
{
|
|
152
|
+
sensors,
|
|
153
|
+
onDragEnd: handleDragEnd,
|
|
154
|
+
onDragStart: handleDragStart,
|
|
155
|
+
onDragCancel: handleDragCancel,
|
|
156
|
+
children: /* @__PURE__ */ jsx("div", { className: "bg-ui-bg-subtle size-full overflow-auto", children: /* @__PURE__ */ jsxs("div", { className: "grid h-fit auto-rows-auto grid-cols-4 gap-6 p-6", children: [
|
|
157
|
+
/* @__PURE__ */ jsx(
|
|
158
|
+
SortableContext,
|
|
159
|
+
{
|
|
160
|
+
items: fields.map((m) => m.field_id),
|
|
161
|
+
strategy: rectSortingStrategy,
|
|
162
|
+
children: fields.map((m) => {
|
|
163
|
+
return /* @__PURE__ */ jsx(
|
|
164
|
+
MediaGridItem,
|
|
165
|
+
{
|
|
166
|
+
onCheckedChange: handleCheckedChange(m.id),
|
|
167
|
+
checked: !!selection[m.id],
|
|
168
|
+
media: m
|
|
169
|
+
},
|
|
170
|
+
m.field_id
|
|
171
|
+
);
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
),
|
|
175
|
+
/* @__PURE__ */ jsx(DragOverlay, { dropAnimation: dropAnimationConfig, children: activeId ? /* @__PURE__ */ jsx(
|
|
176
|
+
MediaGridItemOverlay,
|
|
177
|
+
{
|
|
178
|
+
media: fields.find((m) => m.field_id === activeId),
|
|
179
|
+
checked: !!selection[fields.find((m) => m.field_id === activeId).id]
|
|
180
|
+
}
|
|
181
|
+
) : null })
|
|
182
|
+
] }) })
|
|
183
|
+
}
|
|
184
|
+
),
|
|
185
|
+
/* @__PURE__ */ jsx("div", { className: "bg-ui-bg-base overflow-auto border-b px-6 py-4 lg:border-b-0 lg:border-l", children: /* @__PURE__ */ jsx(UploadMediaFormItem, { form, append }) })
|
|
186
|
+
] }) }),
|
|
187
|
+
/* @__PURE__ */ jsx(CommandBar, { open: !!selectionCount, children: /* @__PURE__ */ jsxs(CommandBar.Bar, { children: [
|
|
188
|
+
/* @__PURE__ */ jsxs(CommandBar.Value, { children: [
|
|
189
|
+
selectionCount,
|
|
190
|
+
" selected"
|
|
191
|
+
] }),
|
|
192
|
+
/* @__PURE__ */ jsx(CommandBar.Seperator, {}),
|
|
193
|
+
selectionCount === 1 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
194
|
+
/* @__PURE__ */ jsx(
|
|
195
|
+
CommandBar.Command,
|
|
196
|
+
{
|
|
197
|
+
action: handlePromoteToThumbnail,
|
|
198
|
+
label: "Make thumbnail",
|
|
199
|
+
shortcut: "t"
|
|
200
|
+
}
|
|
201
|
+
),
|
|
202
|
+
/* @__PURE__ */ jsx(CommandBar.Seperator, {})
|
|
203
|
+
] }),
|
|
204
|
+
/* @__PURE__ */ jsx(
|
|
205
|
+
CommandBar.Command,
|
|
206
|
+
{
|
|
207
|
+
action: handleDelete,
|
|
208
|
+
label: "Delete",
|
|
209
|
+
shortcut: "d"
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
] }) }),
|
|
213
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
214
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
|
|
215
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
216
|
+
] }) })
|
|
217
|
+
]
|
|
218
|
+
}
|
|
219
|
+
) });
|
|
220
|
+
};
|
|
221
|
+
const getDefaultValues = (images, thumbnail) => {
|
|
222
|
+
const media = (images == null ? void 0 : images.map((image) => ({
|
|
223
|
+
id: image.id,
|
|
224
|
+
url: image.url,
|
|
225
|
+
isThumbnail: image.url === thumbnail,
|
|
226
|
+
file: null
|
|
227
|
+
}))) || [];
|
|
228
|
+
if (thumbnail && !media.some((mediaItem) => mediaItem.url === thumbnail)) {
|
|
229
|
+
const id = Math.random().toString(36).substring(7);
|
|
230
|
+
media.unshift({
|
|
231
|
+
id,
|
|
232
|
+
url: thumbnail,
|
|
233
|
+
isThumbnail: true,
|
|
234
|
+
file: null
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return media;
|
|
238
|
+
};
|
|
239
|
+
const dropAnimationConfig = {
|
|
240
|
+
sideEffects: defaultDropAnimationSideEffects({
|
|
241
|
+
styles: {
|
|
242
|
+
active: {
|
|
243
|
+
opacity: "0.4"
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
};
|
|
248
|
+
const MediaGridItem = ({
|
|
249
|
+
media,
|
|
250
|
+
checked,
|
|
251
|
+
onCheckedChange
|
|
252
|
+
}) => {
|
|
253
|
+
const handleToggle = useCallback(
|
|
254
|
+
(value) => {
|
|
255
|
+
onCheckedChange(value);
|
|
256
|
+
},
|
|
257
|
+
[onCheckedChange]
|
|
258
|
+
);
|
|
259
|
+
const {
|
|
260
|
+
attributes,
|
|
261
|
+
listeners,
|
|
262
|
+
setNodeRef,
|
|
263
|
+
setActivatorNodeRef,
|
|
264
|
+
transform,
|
|
265
|
+
transition,
|
|
266
|
+
isDragging
|
|
267
|
+
} = useSortable({ id: media.field_id });
|
|
268
|
+
const style = {
|
|
269
|
+
opacity: isDragging ? 0.4 : void 0,
|
|
270
|
+
transform: CSS.Transform.toString(transform),
|
|
271
|
+
transition
|
|
272
|
+
};
|
|
273
|
+
return /* @__PURE__ */ jsxs(
|
|
274
|
+
"div",
|
|
275
|
+
{
|
|
276
|
+
className: clx(
|
|
277
|
+
"shadow-elevation-card-rest hover:shadow-elevation-card-hover focus-visible:shadow-borders-focus bg-ui-bg-subtle-hover group relative aspect-square h-auto max-w-full overflow-hidden rounded-lg outline-none"
|
|
278
|
+
),
|
|
279
|
+
style,
|
|
280
|
+
ref: setNodeRef,
|
|
281
|
+
children: [
|
|
282
|
+
media.isThumbnail && /* @__PURE__ */ jsx("div", { className: "absolute left-2 top-2", children: /* @__PURE__ */ jsx(Tooltip, { content: "Thumbnail", children: /* @__PURE__ */ jsx(ThumbnailBadge, {}) }) }),
|
|
283
|
+
/* @__PURE__ */ jsx(
|
|
284
|
+
"div",
|
|
285
|
+
{
|
|
286
|
+
className: clx("absolute inset-0 cursor-grab touch-none outline-none", {
|
|
287
|
+
"cursor-grabbing": isDragging
|
|
288
|
+
}),
|
|
289
|
+
ref: setActivatorNodeRef,
|
|
290
|
+
...attributes,
|
|
291
|
+
...listeners
|
|
292
|
+
}
|
|
293
|
+
),
|
|
294
|
+
/* @__PURE__ */ jsx(
|
|
295
|
+
"div",
|
|
296
|
+
{
|
|
297
|
+
className: clx("transition-fg absolute right-2 top-2 opacity-0", {
|
|
298
|
+
"group-focus-within:opacity-100 group-hover:opacity-100 group-focus:opacity-100": !isDragging && !checked,
|
|
299
|
+
"opacity-100": checked
|
|
300
|
+
}),
|
|
301
|
+
children: /* @__PURE__ */ jsx(
|
|
302
|
+
Checkbox,
|
|
303
|
+
{
|
|
304
|
+
onClick: (e) => {
|
|
305
|
+
e.stopPropagation();
|
|
306
|
+
},
|
|
307
|
+
checked,
|
|
308
|
+
onCheckedChange: handleToggle
|
|
309
|
+
}
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
),
|
|
313
|
+
/* @__PURE__ */ jsx(
|
|
314
|
+
"img",
|
|
315
|
+
{
|
|
316
|
+
src: media.url,
|
|
317
|
+
alt: "",
|
|
318
|
+
className: "size-full object-cover object-center"
|
|
319
|
+
}
|
|
320
|
+
)
|
|
321
|
+
]
|
|
322
|
+
}
|
|
323
|
+
);
|
|
324
|
+
};
|
|
325
|
+
const MediaGridItemOverlay = ({
|
|
326
|
+
media,
|
|
327
|
+
checked
|
|
328
|
+
}) => {
|
|
329
|
+
return /* @__PURE__ */ jsxs("div", { className: "shadow-elevation-card-rest hover:shadow-elevation-card-hover focus-visible:shadow-borders-focus bg-ui-bg-subtle-hover group relative aspect-square h-auto max-w-full cursor-grabbing overflow-hidden rounded-lg outline-none", children: [
|
|
330
|
+
media.isThumbnail && /* @__PURE__ */ jsx("div", { className: "absolute left-2 top-2", children: /* @__PURE__ */ jsx(ThumbnailBadge, {}) }),
|
|
331
|
+
/* @__PURE__ */ jsx(
|
|
332
|
+
"div",
|
|
333
|
+
{
|
|
334
|
+
className: clx("transition-fg absolute right-2 top-2 opacity-0", {
|
|
335
|
+
"opacity-100": checked
|
|
336
|
+
}),
|
|
337
|
+
children: /* @__PURE__ */ jsx(Checkbox, { checked })
|
|
338
|
+
}
|
|
339
|
+
),
|
|
340
|
+
/* @__PURE__ */ jsx(
|
|
341
|
+
"img",
|
|
342
|
+
{
|
|
343
|
+
src: media.url,
|
|
344
|
+
alt: "",
|
|
345
|
+
className: "size-full object-cover object-center"
|
|
346
|
+
}
|
|
347
|
+
)
|
|
348
|
+
] });
|
|
349
|
+
};
|
|
350
|
+
export {
|
|
351
|
+
EditProductMediaForm,
|
|
352
|
+
MediaGridItemOverlay
|
|
353
|
+
};
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Trash, ArrowDownTray, ThumbnailBadge, TriangleLeftMini, TriangleRightMini } from "@medusajs/icons";
|
|
3
|
+
import { usePrompt, IconButton, Button, Text, Tooltip, clx } from "@medusajs/ui";
|
|
4
|
+
import { useState, useCallback, useEffect } from "react";
|
|
5
|
+
import { useLocation, Link } from "react-router-dom";
|
|
6
|
+
import "../../../../../../components/modals/route-drawer/route-drawer.js";
|
|
7
|
+
import { RouteFocusModal } from "../../../../../../components/modals/route-focus-modal/route-focus-modal.js";
|
|
8
|
+
import "../../../../../../components/modals/route-modal-provider/route-modal-context.js";
|
|
9
|
+
import "../../../../../../components/modals/stacked-drawer/stacked-drawer.js";
|
|
10
|
+
import "../../../../../../components/modals/stacked-focus-modal/stacked-focus-modal.js";
|
|
11
|
+
import "../../../../../../components/modals/stacked-modal-provider/stacked-modal-context.js";
|
|
12
|
+
import { useUpdateProduct } from "../../../../../../hooks/api/products.js";
|
|
13
|
+
const ProductMediaGallery = ({ product }) => {
|
|
14
|
+
const { state } = useLocation();
|
|
15
|
+
const [curr, setCurr] = useState((state == null ? void 0 : state.curr) || 0);
|
|
16
|
+
const prompt = usePrompt();
|
|
17
|
+
const { mutateAsync, isPending } = useUpdateProduct(product.id);
|
|
18
|
+
const media = getMedia(product.images, product.thumbnail);
|
|
19
|
+
const next = useCallback(() => {
|
|
20
|
+
if (isPending) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
setCurr((prev2) => (prev2 + 1) % media.length);
|
|
24
|
+
}, [media, isPending]);
|
|
25
|
+
const prev = useCallback(() => {
|
|
26
|
+
if (isPending) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
setCurr((prev2) => (prev2 - 1 + media.length) % media.length);
|
|
30
|
+
}, [media, isPending]);
|
|
31
|
+
const goTo = useCallback(
|
|
32
|
+
(index) => {
|
|
33
|
+
if (isPending) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
setCurr(index);
|
|
37
|
+
},
|
|
38
|
+
[isPending]
|
|
39
|
+
);
|
|
40
|
+
const handleDownloadCurrent = () => {
|
|
41
|
+
if (isPending) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const a = document.createElement("a");
|
|
45
|
+
a.href = media[curr].url;
|
|
46
|
+
a.download = "image";
|
|
47
|
+
a.target = "_blank";
|
|
48
|
+
a.click();
|
|
49
|
+
};
|
|
50
|
+
const handleDeleteCurrent = async () => {
|
|
51
|
+
var _a;
|
|
52
|
+
const current = media[curr];
|
|
53
|
+
const res = await prompt({
|
|
54
|
+
title: "Are you sure?",
|
|
55
|
+
description: current.isThumbnail ? "This will delete the thumbnail" : "This will delete the image",
|
|
56
|
+
confirmText: "Delete",
|
|
57
|
+
cancelText: "Cancel"
|
|
58
|
+
});
|
|
59
|
+
if (!res) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const mediaToKeep = ((_a = product.images) == null ? void 0 : _a.filter((i) => i.id !== current.id).map((i) => ({ url: i.url }))) || [];
|
|
63
|
+
if (curr === media.length - 1) {
|
|
64
|
+
setCurr((prev2) => prev2 - 1);
|
|
65
|
+
}
|
|
66
|
+
await mutateAsync({
|
|
67
|
+
images: mediaToKeep,
|
|
68
|
+
thumbnail: current.isThumbnail ? "" : void 0
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const handleKeyDown = (e) => {
|
|
73
|
+
if (e.key === "ArrowRight") {
|
|
74
|
+
next();
|
|
75
|
+
} else if (e.key === "ArrowLeft") {
|
|
76
|
+
prev();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
80
|
+
return () => {
|
|
81
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
82
|
+
};
|
|
83
|
+
}, [next, prev]);
|
|
84
|
+
const noMedia = !media.length;
|
|
85
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex size-full flex-col overflow-hidden", children: [
|
|
86
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
87
|
+
/* @__PURE__ */ jsxs(
|
|
88
|
+
IconButton,
|
|
89
|
+
{
|
|
90
|
+
size: "small",
|
|
91
|
+
type: "button",
|
|
92
|
+
onClick: handleDeleteCurrent,
|
|
93
|
+
disabled: noMedia,
|
|
94
|
+
children: [
|
|
95
|
+
/* @__PURE__ */ jsx(Trash, {}),
|
|
96
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: "Delete image" })
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
),
|
|
100
|
+
/* @__PURE__ */ jsxs(
|
|
101
|
+
IconButton,
|
|
102
|
+
{
|
|
103
|
+
size: "small",
|
|
104
|
+
type: "button",
|
|
105
|
+
onClick: handleDownloadCurrent,
|
|
106
|
+
disabled: noMedia,
|
|
107
|
+
children: [
|
|
108
|
+
/* @__PURE__ */ jsx(ArrowDownTray, {}),
|
|
109
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: "Download image" })
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
),
|
|
113
|
+
/* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", asChild: true, children: /* @__PURE__ */ jsx(Link, { to: { pathname: ".", search: "view=edit" }, children: "Edit" }) })
|
|
114
|
+
] }) }),
|
|
115
|
+
/* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-col overflow-hidden", children: [
|
|
116
|
+
/* @__PURE__ */ jsx(Canvas, { curr, media }),
|
|
117
|
+
/* @__PURE__ */ jsx(
|
|
118
|
+
Preview,
|
|
119
|
+
{
|
|
120
|
+
curr,
|
|
121
|
+
media,
|
|
122
|
+
prev,
|
|
123
|
+
next,
|
|
124
|
+
goTo
|
|
125
|
+
}
|
|
126
|
+
)
|
|
127
|
+
] })
|
|
128
|
+
] });
|
|
129
|
+
};
|
|
130
|
+
const Canvas = ({ media, curr }) => {
|
|
131
|
+
if (media.length === 0) {
|
|
132
|
+
return /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle flex size-full flex-col items-center justify-center gap-y-4 pb-8 pt-6", children: [
|
|
133
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center", children: [
|
|
134
|
+
/* @__PURE__ */ jsx(
|
|
135
|
+
Text,
|
|
136
|
+
{
|
|
137
|
+
size: "small",
|
|
138
|
+
leading: "compact",
|
|
139
|
+
weight: "plus",
|
|
140
|
+
className: "text-ui-fg-subtle",
|
|
141
|
+
children: "No images"
|
|
142
|
+
}
|
|
143
|
+
),
|
|
144
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Add images to your product" })
|
|
145
|
+
] }),
|
|
146
|
+
/* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", asChild: true, children: /* @__PURE__ */ jsx(Link, { to: "?view=edit", children: "Add images" }) })
|
|
147
|
+
] });
|
|
148
|
+
}
|
|
149
|
+
return /* @__PURE__ */ jsx("div", { className: "bg-ui-bg-subtle relative size-full overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex size-full items-center justify-center p-6", children: /* @__PURE__ */ jsxs("div", { className: "relative inline-block max-h-full max-w-full", children: [
|
|
150
|
+
media[curr].isThumbnail && /* @__PURE__ */ jsx("div", { className: "absolute left-2 top-2", children: /* @__PURE__ */ jsx(Tooltip, { content: "Thumbnail", children: /* @__PURE__ */ jsx(ThumbnailBadge, {}) }) }),
|
|
151
|
+
/* @__PURE__ */ jsx(
|
|
152
|
+
"img",
|
|
153
|
+
{
|
|
154
|
+
src: media[curr].url,
|
|
155
|
+
alt: "",
|
|
156
|
+
className: "object-fit shadow-elevation-card-rest max-h-[calc(100vh-200px)] w-auto rounded-xl object-contain"
|
|
157
|
+
}
|
|
158
|
+
)
|
|
159
|
+
] }) }) });
|
|
160
|
+
};
|
|
161
|
+
const MAX_VISIBLE_ITEMS = 8;
|
|
162
|
+
const Preview = ({
|
|
163
|
+
media,
|
|
164
|
+
curr,
|
|
165
|
+
prev,
|
|
166
|
+
next,
|
|
167
|
+
goTo
|
|
168
|
+
}) => {
|
|
169
|
+
if (!media.length) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
const getVisibleItems = (media2, index) => {
|
|
173
|
+
if (media2.length <= MAX_VISIBLE_ITEMS) {
|
|
174
|
+
return media2;
|
|
175
|
+
}
|
|
176
|
+
const half = Math.floor(MAX_VISIBLE_ITEMS / 2);
|
|
177
|
+
const start = (index - half + media2.length) % media2.length;
|
|
178
|
+
const end = (start + MAX_VISIBLE_ITEMS) % media2.length;
|
|
179
|
+
if (end < start) {
|
|
180
|
+
return [...media2.slice(start), ...media2.slice(0, end)];
|
|
181
|
+
} else {
|
|
182
|
+
return media2.slice(start, end);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const visibleItems = getVisibleItems(media, curr);
|
|
186
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center justify-center gap-x-2 border-t p-3", children: [
|
|
187
|
+
/* @__PURE__ */ jsx(
|
|
188
|
+
IconButton,
|
|
189
|
+
{
|
|
190
|
+
size: "small",
|
|
191
|
+
variant: "transparent",
|
|
192
|
+
className: "text-ui-fg-muted",
|
|
193
|
+
type: "button",
|
|
194
|
+
onClick: prev,
|
|
195
|
+
children: /* @__PURE__ */ jsx(TriangleLeftMini, {})
|
|
196
|
+
}
|
|
197
|
+
),
|
|
198
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-x-2", children: visibleItems.map((item) => {
|
|
199
|
+
const isCurrentImage = item.id === media[curr].id;
|
|
200
|
+
const originalIndex = media.findIndex((i) => i.id === item.id);
|
|
201
|
+
return /* @__PURE__ */ jsx(
|
|
202
|
+
"button",
|
|
203
|
+
{
|
|
204
|
+
type: "button",
|
|
205
|
+
onClick: () => goTo(originalIndex),
|
|
206
|
+
className: clx(
|
|
207
|
+
"transition-fg size-7 overflow-hidden rounded-[4px] outline-none",
|
|
208
|
+
{
|
|
209
|
+
"shadow-borders-focus": isCurrentImage
|
|
210
|
+
}
|
|
211
|
+
),
|
|
212
|
+
children: /* @__PURE__ */ jsx("img", { src: item.url, alt: "", className: "size-full object-cover" })
|
|
213
|
+
},
|
|
214
|
+
item.id
|
|
215
|
+
);
|
|
216
|
+
}) }),
|
|
217
|
+
/* @__PURE__ */ jsx(
|
|
218
|
+
IconButton,
|
|
219
|
+
{
|
|
220
|
+
size: "small",
|
|
221
|
+
variant: "transparent",
|
|
222
|
+
className: "text-ui-fg-muted",
|
|
223
|
+
type: "button",
|
|
224
|
+
onClick: next,
|
|
225
|
+
children: /* @__PURE__ */ jsx(TriangleRightMini, {})
|
|
226
|
+
}
|
|
227
|
+
)
|
|
228
|
+
] });
|
|
229
|
+
};
|
|
230
|
+
const getMedia = (images, thumbnail) => {
|
|
231
|
+
const media = (images == null ? void 0 : images.map((image) => ({
|
|
232
|
+
id: image.id,
|
|
233
|
+
url: image.url,
|
|
234
|
+
isThumbnail: image.url === thumbnail
|
|
235
|
+
}))) || [];
|
|
236
|
+
if (thumbnail && !media.some((mediaItem) => mediaItem.isThumbnail)) {
|
|
237
|
+
media.unshift({
|
|
238
|
+
id: "thumbnail_only",
|
|
239
|
+
url: thumbnail,
|
|
240
|
+
isThumbnail: true
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
return media;
|
|
244
|
+
};
|
|
245
|
+
export {
|
|
246
|
+
ProductMediaGallery
|
|
247
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useSearchParams } from "react-router-dom";
|
|
3
|
+
import { EditProductMediaForm } from "../edit-product-media-form/edit-product-media-form.js";
|
|
4
|
+
import { ProductMediaGallery } from "../product-media-gallery/product-media-gallery.js";
|
|
5
|
+
import { ProductMediaViewContext } from "./product-media-view-context.js";
|
|
6
|
+
const getView = (searchParams) => {
|
|
7
|
+
const view = searchParams.get("view");
|
|
8
|
+
if (view === "edit") {
|
|
9
|
+
return "edit";
|
|
10
|
+
}
|
|
11
|
+
return "gallery";
|
|
12
|
+
};
|
|
13
|
+
const ProductMediaView = ({ product }) => {
|
|
14
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
15
|
+
const view = getView(searchParams);
|
|
16
|
+
const handleGoToView = (view2) => {
|
|
17
|
+
return () => {
|
|
18
|
+
setSearchParams({ view: view2 });
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
return /* @__PURE__ */ jsx(
|
|
22
|
+
ProductMediaViewContext.Provider,
|
|
23
|
+
{
|
|
24
|
+
value: {
|
|
25
|
+
goToGallery: handleGoToView(
|
|
26
|
+
"gallery"
|
|
27
|
+
/* GALLERY */
|
|
28
|
+
),
|
|
29
|
+
goToEdit: handleGoToView(
|
|
30
|
+
"edit"
|
|
31
|
+
/* EDIT */
|
|
32
|
+
)
|
|
33
|
+
},
|
|
34
|
+
children: renderView(view, product)
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
const renderView = (view, product) => {
|
|
39
|
+
switch (view) {
|
|
40
|
+
case "gallery":
|
|
41
|
+
return /* @__PURE__ */ jsx(ProductMediaGallery, { product });
|
|
42
|
+
case "edit":
|
|
43
|
+
return /* @__PURE__ */ jsx(EditProductMediaForm, { product });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
ProductMediaView
|
|
48
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { ProductMediaViewContext } from "./product-media-view-context.js";
|
|
3
|
+
const useProductMediaView = () => {
|
|
4
|
+
const context = useContext(ProductMediaViewContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
"useProductMediaView must be used within a ProductMediaViewProvider"
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
return context;
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
useProductMediaView
|
|
14
|
+
};
|