@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,353 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,247 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
};
|