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.

Fix the sidebar counts, prefill the claim refund, add a missing label

Damian Legawiec9c0ac4a8e54f
diff --git a/packages/admin-sdk/src/types/generated/ClaimLineItem.ts b/packages/admin-sdk/src/types/generated/ClaimLineItem.ts
index 4afc81c6f0..36d81291b3 100644
--- a/packages/admin-sdk/src/types/generated/ClaimLineItem.ts
+++ b/packages/admin-sdk/src/types/generated/ClaimLineItem.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 81b68cced02eb8309f4ad17459cfd240
+// Typelizer digest 290f02925bf811cf2cfecb15fbf5a956
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Variant} from '@/types'
@@ -9,6 +9,7 @@ interface ClaimLineItem {
send_replacement: boolean;
description: string | null;
refund_amount: string;
+ paid_amount: string;
display_refund_amount: string;
variant_id: string | null;
replacement_variant_id: string | null;
diff --git a/packages/dashboard-core/src/locales/ar.json b/packages/dashboard-core/src/locales/ar.json
index cf3365e637..be4b3813bc 100644
--- a/packages/dashboard-core/src/locales/ar.json
+++ b/packages/dashboard-core/src/locales/ar.json
@@ -352,6 +352,9 @@
},
"permalink": {
"label": "الرابط الدائم"
+ },
+ "number": {
+ "label": "الرقم"
}
},
"components": {
diff --git a/packages/dashboard-core/src/locales/de.json b/packages/dashboard-core/src/locales/de.json
index e565df3ff9..5dd067c6e7 100644
--- a/packages/dashboard-core/src/locales/de.json
+++ b/packages/dashboard-core/src/locales/de.json
@@ -352,6 +352,9 @@
},
"permalink": {
"label": "Permalink"
+ },
+ "number": {
+ "label": "Nummer"
}
},
"components": {
diff --git a/packages/dashboard-core/src/locales/en.json b/packages/dashboard-core/src/locales/en.json
index c83f0c7469..8b49f1698c 100644
--- a/packages/dashboard-core/src/locales/en.json
+++ b/packages/dashboard-core/src/locales/en.json
@@ -352,6 +352,9 @@
},
"permalink": {
"label": "Permalink"
+ },
+ "number": {
+ "label": "Number"
}
},
"components": {
diff --git a/packages/dashboard-core/src/locales/fr.json b/packages/dashboard-core/src/locales/fr.json
index 85b65adbb9..e90cacfa1f 100644
--- a/packages/dashboard-core/src/locales/fr.json
+++ b/packages/dashboard-core/src/locales/fr.json
@@ -352,6 +352,9 @@
},
"permalink": {
"label": "Lien permanent"
+ },
+ "number": {
+ "label": "Numéro"
}
},
"components": {
diff --git a/packages/dashboard-core/src/locales/pl.json b/packages/dashboard-core/src/locales/pl.json
index 146385f573..f0b363143f 100644
--- a/packages/dashboard-core/src/locales/pl.json
+++ b/packages/dashboard-core/src/locales/pl.json
@@ -352,6 +352,9 @@
},
"permalink": {
"label": "Odnośnik"
+ },
+ "number": {
+ "label": "Numer"
}
},
"components": {
diff --git a/packages/dashboard-core/src/locales/zh-CN.json b/packages/dashboard-core/src/locales/zh-CN.json
index 469a14ed08..e672e46944 100644
--- a/packages/dashboard-core/src/locales/zh-CN.json
+++ b/packages/dashboard-core/src/locales/zh-CN.json
@@ -352,6 +352,9 @@
},
"permalink": {
"label": "固定链接"
+ },
+ "number": {
+ "label": "编号"
}
},
"components": {
diff --git a/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsx b/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsx
index 81cbed4fd1..88dca3061d 100644
--- a/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsx
+++ b/packages/dashboard/src/components/spree/post-sale-create-dialogs.tsx
@@ -431,7 +431,16 @@ export function ResolveClaimDialog({
const [refundMethod, setRefundMethod] = useState<'original_payment' | 'store_credit'>(
'store_credit',
)
- const [amount, setAmount] = useState(claim.refund_total)
+ // A claim opened without per-item amounts has a refund_total of zero, and
+ // the workflow refuses to refund nothing — offer what the customer paid for
+ // the claimed items instead, which is also the ceiling it enforces.
+ const [amount, setAmount] = useState(() => {
+ const recorded = Number(claim.refund_total)
+ if (Number.isFinite(recorded) && recorded > 0) return claim.refund_total
+
+ const paid = lines.reduce((sum, line) => sum + Number(line.paid_amount ?? 0), 0)
+ return paid > 0 ? paid.toFixed(2) : claim.refund_total
+ })
const [replacing, setReplacing] = useState<Record<string, boolean>>(() =>
Object.fromEntries(lines.map((line) => [line.id, line.send_replacement])),
)
diff --git a/packages/dashboard/src/components/spree/post-sale-nav-badges.tsx b/packages/dashboard/src/components/spree/post-sale-nav-badges.tsx
index f74a63d59c..ddf0c9ce50 100644
--- a/packages/dashboard/src/components/spree/post-sale-nav-badges.tsx
+++ b/packages/dashboard/src/components/spree/post-sale-nav-badges.tsx
@@ -3,18 +3,22 @@ import { Badge } from '@spree/dashboard-ui'
import { useQuery } from '@tanstack/react-query'
/**
- * How many records are waiting on the merchant. Asks for a single row and
- * reads the total off the pagination meta, so the sidebar never pulls a full
- * page it does not render.
+ * How many records still need the merchant to do something. Asks for a single
+ * row and reads the total off the pagination meta, so the sidebar never pulls
+ * a full page it does not render.
+ *
+ * Ransack predicates go at the top level — `transformListParams` wraps every
+ * key it does not recognise in `q[...]`, so nesting them under `q` produces
+ * `q[q]` and the filter is silently ignored.
*/
function usePendingCount(
resourceKey: string,
- status: string,
+ statuses: string[],
list: (params: Record<string, unknown>) => Promise<{ meta?: { count?: number } }>,
) {
const { data } = useQuery({
queryKey: useResourceKey(`${resourceKey}-pending`),
- queryFn: () => list({ limit: 1, q: { status_eq: status } }),
+ queryFn: () => list({ limit: 1, status_in: statuses }),
// The sidebar is always mounted; without this it would refetch on every
// navigation.
staleTime: 60_000,
@@ -33,18 +37,30 @@ function CountBadge({ count }: { count: number }) {
)
}
-/** Returns a customer has opened and nobody has approved yet. */
+// Everything still in flight, not just the first step: an approved return
+// still needs receiving and refunding, so it is as much outstanding work as
+// one nobody has looked at. Terminal statuses — refunded, fulfilled,
+// resolved, denied, canceled — are done and drop out of the count.
+const RETURNS_IN_PROGRESS = ['requested', 'approved', 'received']
+const EXCHANGES_IN_PROGRESS = ['requested', 'approved', 'received']
+const CLAIMS_IN_PROGRESS = ['open', 'approved']
+
export function ReturnsNavBadge() {
- return <CountBadge count={usePendingCount('returns', 'requested', adminClient.returns.list)} />
+ return (
+ <CountBadge count={usePendingCount('returns', RETURNS_IN_PROGRESS, adminClient.returns.list)} />
+ )
}
export function ExchangesNavBadge() {
return (
- <CountBadge count={usePendingCount('exchanges', 'requested', adminClient.exchanges.list)} />
+ <CountBadge
+ count={usePendingCount('exchanges', EXCHANGES_IN_PROGRESS, adminClient.exchanges.list)}
+ />
)
}
-/** Claims start as `open` rather than `requested`. */
export function ClaimsNavBadge() {
- return <CountBadge count={usePendingCount('claims', 'open', adminClient.claims.list)} />
+ return (
+ <CountBadge count={usePendingCount('claims', CLAIMS_IN_PROGRESS, adminClient.claims.list)} />
+ )
}
diff --git a/packages/sdk/src/types/generated/ClaimLineItem.ts b/packages/sdk/src/types/generated/ClaimLineItem.ts
index 78a876b852..025b844e72 100644
--- a/packages/sdk/src/types/generated/ClaimLineItem.ts
+++ b/packages/sdk/src/types/generated/ClaimLineItem.ts
@@ -1,4 +1,4 @@
-// Typelizer digest dd52086ce2dae45c2ac6b13cb7e055cd
+// Typelizer digest f35f7fc79f41f512821ba3ea89e38351
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Variant} from '@/types'
@@ -9,6 +9,7 @@ interface ClaimLineItem {
send_replacement: boolean;
description: string | null;
refund_amount: string;
+ paid_amount: string;
display_refund_amount: string;
variant_id: string | null;
replacement_variant_id: string | null;
diff --git a/packages/sdk/src/zod/generated/ClaimLineItem.ts b/packages/sdk/src/zod/generated/ClaimLineItem.ts
index b3cdac158a..3809d5f646 100644
--- a/packages/sdk/src/zod/generated/ClaimLineItem.ts
+++ b/packages/sdk/src/zod/generated/ClaimLineItem.ts
@@ -8,6 +8,7 @@ export const ClaimLineItemSchema = z.object({
send_replacement: z.boolean(),
description: z.string().nullable(),
refund_amount: z.string(),
+ paid_amount: z.string(),
display_refund_amount: z.string(),
variant_id: z.string().nullable(),
replacement_variant_id: z.string().nullable(),
diff --git a/spree/api/app/serializers/spree/api/v3/claim_line_item_serializer.rb b/spree/api/app/serializers/spree/api/v3/claim_line_item_serializer.rb
index 44a56195ea..36dab99945 100644
--- a/spree/api/app/serializers/spree/api/v3/claim_line_item_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/claim_line_item_serializer.rb
@@ -8,6 +8,7 @@ module Spree
send_replacement: :boolean,
refund_amount: :string,
display_refund_amount: :string,
+ paid_amount: :string,
description: [:string, nullable: true],
variant_id: [:string, nullable: true],
replacement_variant_id: [:string, nullable: true],
@@ -19,6 +20,13 @@ module Spree
line.refund_amount.to_s
end
+ # What the customer actually paid for these units — the ceiling the
+ # resolve workflow enforces, and what the dashboard offers when the
+ # claim carries no explicit amount.
+ attribute :paid_amount do |line|
+ line.paid_amount.to_s
+ end
+
attribute :display_refund_amount do |line|
line.display_refund_amount.to_s
end