Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Tidy the seller orders and products changes

Damian Legawiec055e9dea971f
diff --git a/packages/seller-dashboard/src/components/retryable-error.tsx b/packages/seller-dashboard/src/components/retryable-error.tsx
new file mode 100644
index 0000000000..2c7bda9f36
--- /dev/null
+++ b/packages/seller-dashboard/src/components/retryable-error.tsx
@@ -0,0 +1,23 @@
+import { Button } from '@spree/dashboard-ui'
+import { useTranslation } from 'react-i18next'
+import { CenteredMessage } from './centered-message'
+
+/**
+ * Shown when a page's own query failed, in place of its content.
+ *
+ * Distinct from a "not found" message on purpose: a failed request and a
+ * missing record send the seller looking for different causes, and only one
+ * of the two is worth retrying.
+ */
+export function RetryableError({ onRetry }: { onRetry: () => void }) {
+ const { t } = useTranslation()
+
+ return (
+ <CenteredMessage>
+ {t('common.error')}{' '}
+ <Button variant="outline" onClick={onRetry}>
+ {t('common.retry')}
+ </Button>
+ </CenteredMessage>
+ )
+}
diff --git a/packages/seller-dashboard/src/pages/order.tsx b/packages/seller-dashboard/src/pages/order.tsx
index c1585a02b0..daad9b8fee 100644
--- a/packages/seller-dashboard/src/pages/order.tsx
+++ b/packages/seller-dashboard/src/pages/order.tsx
@@ -20,6 +20,7 @@ import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { sellerClient } from '../api-client'
import { CenteredMessage } from '../components/centered-message'
+import { RetryableError } from '../components/retryable-error'
/** One order, as the seller needs it to pack and post the parcel. */
export function OrderPage() {
@@ -54,18 +55,7 @@ export function OrderPage() {
})
if (isLoading) return <CenteredMessage>{t('common.loading')}</CenteredMessage>
- // A request that failed is not the same as an order that is not there —
- // reporting the latter sends the seller looking for the wrong cause.
- if (isError) {
- return (
- <CenteredMessage>
- {t('common.error')}{' '}
- <Button variant="outline" onClick={() => refetch()}>
- {t('common.retry')}
- </Button>
- </CenteredMessage>
- )
- }
+ if (isError) return <RetryableError onRetry={() => refetch()} />
if (!order) return <CenteredMessage>{t('orders.not_found')}</CenteredMessage>
async function handleCancel() {
diff --git a/packages/seller-dashboard/src/pages/product.tsx b/packages/seller-dashboard/src/pages/product.tsx
index 3fca1cdb04..4c8d26b8c1 100644
--- a/packages/seller-dashboard/src/pages/product.tsx
+++ b/packages/seller-dashboard/src/pages/product.tsx
@@ -26,6 +26,7 @@ import { useForm } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
import { sellerClient } from '../api-client'
import { CenteredMessage } from '../components/centered-message'
+import { RetryableError } from '../components/retryable-error'
const STATUSES = ['draft', 'active', 'archived'] as const
@@ -126,18 +127,7 @@ export function ProductPage({ mode }: { mode: 'new' | 'edit' }) {
}
if (mode === 'edit' && isLoading) return <CenteredMessage>{t('common.loading')}</CenteredMessage>
- // Same distinction as the order page: a failed request is not a missing
- // product, and only one of the two is worth retrying.
- if (mode === 'edit' && isError) {
- return (
- <CenteredMessage>
- {t('common.error')}{' '}
- <Button variant="outline" onClick={() => refetch()}>
- {t('common.retry')}
- </Button>
- </CenteredMessage>
- )
- }
+ if (mode === 'edit' && isError) return <RetryableError onRetry={() => refetch()} />
if (mode === 'edit' && !product)
return <CenteredMessage>{t('products.not_found')}</CenteredMessage>
diff --git a/spree/api/app/controllers/spree/api/v3/seller/products_controller.rb b/spree/api/app/controllers/spree/api/v3/seller/products_controller.rb
index ec7c2151f0..9c3c9268fb 100644
--- a/spree/api/app/controllers/spree/api/v3/seller/products_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/seller/products_controller.rb
@@ -42,15 +42,12 @@ module Spree
prices: [:amount, :compare_at_amount, :currency]
)
- default_price_currency(attrs)
- end
-
- # A price with no currency is priced in the store's, not in whatever
- # the client happened to assume. `Variant#prices=` passes the value
- # through untouched and drops base prices for currencies absent from
- # the payload, so a wrong guess does not merely add a stray price —
- # it removes the right one.
- def default_price_currency(attrs)
+ # A price the client did not name a currency for is priced in the
+ # store's. `Variant#prices=` matches base prices on the currency it
+ # is handed and drops the ones missing from the payload, so a
+ # guessed currency does not merely add a stray price — it removes
+ # the right one. Blank counts as unnamed: an empty form field would
+ # otherwise key a price on "".
return attrs if attrs[:prices].blank?
attrs[:prices] = attrs[:prices].map do |price|
diff --git a/spree/api/app/controllers/spree/api/v3/seller/resource_controller.rb b/spree/api/app/controllers/spree/api/v3/seller/resource_controller.rb
index f839240dce..43c84ef95e 100644
--- a/spree/api/app/controllers/spree/api/v3/seller/resource_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/seller/resource_controller.rb
@@ -25,6 +25,10 @@ module Spree
# so subclasses name a `seller_association` and the root scope comes
# from the seller itself. Tenancy is this fetch, not the ability:
# authorizing without it reads store-wide.
+ #
+ # Tenancy is all this roots, though — it does not judge whether a
+ # record is the seller's business. A controller reaching orders must
+ # also exclude drafts, which `current_seller_orders` does.
def scope
return super if @parent.present?