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.

code review fixes

Damian Legawiecc8f9a278aefa
diff --git a/packages/admin-sdk/src/admin-client.ts b/packages/admin-sdk/src/admin-client.ts
index 48e8f3a731..257bf9b16f 100644
--- a/packages/admin-sdk/src/admin-client.ts
+++ b/packages/admin-sdk/src/admin-client.ts
@@ -344,11 +344,7 @@ export class AdminClient {
* Returns just the safe-to-render context (store, role, inviter, invitee_exists)
* so the SPA acceptance page can decide between sign-in and signup forms.
*/
- lookupInvitation: (
- id: string,
- token: string,
- options?: RequestOptions,
- ): Promise<Invitation> =>
+ lookupInvitation: (id: string, token: string, options?: RequestOptions): Promise<Invitation> =>
this.request<Invitation>('GET', `/auth/invitations/${id}/lookup`, {
...options,
params: { token },
diff --git a/packages/admin/src/components/spree/preferences-form.tsx b/packages/admin/src/components/spree/preferences-form.tsx
index d6a0a4c21a..dede26a453 100644
--- a/packages/admin/src/components/spree/preferences-form.tsx
+++ b/packages/admin/src/components/spree/preferences-form.tsx
@@ -116,7 +116,7 @@ export function PreferenceField({
return (
<Field>
<FieldLabel htmlFor={id}>{displayLabel}</FieldLabel>
- <CurrencySelect id={id} value={(value as string) || ''} onChange={onChange} />
+ <CurrencySelect id={id} value={(value as string) ?? ''} onChange={onChange} />
</Field>
)
}
diff --git a/packages/admin/src/routes/_authenticated/$storeId/customers/$customerId.tsx b/packages/admin/src/routes/_authenticated/$storeId/customers/$customerId.tsx
index 5b64744039..44da8ad574 100644
--- a/packages/admin/src/routes/_authenticated/$storeId/customers/$customerId.tsx
+++ b/packages/admin/src/routes/_authenticated/$storeId/customers/$customerId.tsx
@@ -78,6 +78,7 @@ import {
} from '@/hooks/use-customers'
import { useStoreCreditCategories } from '@/hooks/use-store-credit-categories'
import { mapSpreeErrorsToForm } from '@/lib/form-errors'
+import { useStore } from '@/providers/store-provider'
import { type CustomerProfileFormValues, customerProfileFormSchema } from '@/schemas/customer'
import {
type EditStoreCreditFormValues,
@@ -1208,10 +1209,14 @@ function IssueStoreCreditDialog({
onOpenChange: (open: boolean) => void
}) {
const { t } = useTranslation()
+ // Seed `currency` with the store default so the merchant doesn't have to
+ // pick one explicitly — `CurrencySelect` displays it but no longer commits
+ // it via onChange, so the form value needs to start populated.
+ const { defaultCurrency } = useStore()
const form = useForm<IssueStoreCreditFormValues>({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
resolver: zodResolver(issueStoreCreditFormSchema) as any,
- defaultValues: { amount: '', currency: '', category_id: '', memo: '' },
+ defaultValues: { amount: '', currency: defaultCurrency, category_id: '', memo: '' },
})
const { errors } = form.formState
@@ -1221,9 +1226,9 @@ function IssueStoreCreditDialog({
// is presented (otherwise stale "Issue $20" values linger across opens).
useEffect(() => {
if (open) {
- form.reset({ amount: '', currency: '', category_id: '', memo: '' })
+ form.reset({ amount: '', currency: defaultCurrency, category_id: '', memo: '' })
}
- }, [open, form])
+ }, [open, form, defaultCurrency])
async function onSubmit(values: IssueStoreCreditFormValues) {
try {
diff --git a/packages/admin/src/routes/_authenticated/$storeId/promotions/gift-cards.tsx b/packages/admin/src/routes/_authenticated/$storeId/promotions/gift-cards.tsx
index 242d188b26..5af609736c 100644
--- a/packages/admin/src/routes/_authenticated/$storeId/promotions/gift-cards.tsx
+++ b/packages/admin/src/routes/_authenticated/$storeId/promotions/gift-cards.tsx
@@ -314,7 +314,7 @@ function EditGiftCardSheet({
</p>
)}
<EditGiftCardFormFields form={form} readOnly={!editable} />
- {giftCard && <GiftCardUsageSummary giftCard={giftCard} />}
+ <GiftCardUsageSummary giftCard={giftCard} />
</div>
<SheetFooter>
<Can I="destroy" a={Subject.GiftCard}>
diff --git a/packages/admin/src/routes/_authenticated/$storeId/settings/payment-methods.tsx b/packages/admin/src/routes/_authenticated/$storeId/settings/payment-methods.tsx
index f0f15f4a07..6e9aac7f28 100644
--- a/packages/admin/src/routes/_authenticated/$storeId/settings/payment-methods.tsx
+++ b/packages/admin/src/routes/_authenticated/$storeId/settings/payment-methods.tsx
@@ -33,6 +33,7 @@ import {
} from '@/hooks/use-payment-methods'
import { mapSpreeErrorsToForm } from '@/lib/form-errors'
import { Subject } from '@/lib/permissions'
+import { useStore } from '@/providers/store-provider'
import {
PAYMENT_METHOD_BASE_DEFAULTS,
PAYMENT_METHOD_CREATE_DEFAULTS,
@@ -120,6 +121,10 @@ function CreatePaymentMethodSheet({
const createMutation = useCreatePaymentMethod()
const { data: typesResponse, isLoading: loadingTypes } = usePaymentMethodTypes()
const providerTypes = useMemo(() => typesResponse?.data ?? [], [typesResponse])
+ // Seed `currency`-typed preferences with the store default so the merchant
+ // sees and submits a real value — `CurrencySelect` only displays the
+ // fallback now (it no longer commits via onChange).
+ const { defaultCurrency } = useStore()
const form = useForm<PaymentMethodFormValues>({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -136,7 +141,7 @@ function CreatePaymentMethodSheet({
function handleProviderTypeChange(next: string) {
const nextSchema = providerTypes.find((t) => t.type === next)?.preference_schema ?? []
- setPreferences(defaultPreferences(nextSchema))
+ setPreferences(defaultPreferences(nextSchema, { currency: defaultCurrency }))
}
async function onSubmit(values: PaymentMethodFormValues) {