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.

Name the company on its address form, and offer a new site as both defaults

Damian Legawiec8eef6a5833e1
diff --git a/packages/dashboard-core/src/components/address-form-dialog.tsx b/packages/dashboard-core/src/components/address-form-dialog.tsx
index db0bc95347..4b0efc3433 100644
--- a/packages/dashboard-core/src/components/address-form-dialog.tsx
+++ b/packages/dashboard-core/src/components/address-form-dialog.tsx
@@ -399,40 +399,42 @@ export function AddressFormDialog({
{showDefaultFlags && (
<>
<Field>
- <div className="flex items-start justify-between gap-4">
- <FieldLabel htmlFor="addr-default-billing" className="cursor-pointer">
- {t('admin.fields.address.is_default_billing.label')}
- </FieldLabel>
- <Controller
- name="is_default_billing"
- control={form.control}
- render={({ field }) => (
+ <Controller
+ name="is_default_billing"
+ control={form.control}
+ render={({ field }) => (
+ <label
+ htmlFor="addr-default-billing"
+ className="flex cursor-pointer items-center gap-2 text-sm"
+ >
<Checkbox
id="addr-default-billing"
checked={!!field.value}
onCheckedChange={field.onChange}
/>
- )}
- />
- </div>
+ {t('admin.fields.address.is_default_billing.label')}
+ </label>
+ )}
+ />
</Field>
<Field>
- <div className="flex items-start justify-between gap-4">
- <FieldLabel htmlFor="addr-default-shipping" className="cursor-pointer">
- {t('admin.fields.address.is_default_shipping.label')}
- </FieldLabel>
- <Controller
- name="is_default_shipping"
- control={form.control}
- render={({ field }) => (
+ <Controller
+ name="is_default_shipping"
+ control={form.control}
+ render={({ field }) => (
+ <label
+ htmlFor="addr-default-shipping"
+ className="flex cursor-pointer items-center gap-2 text-sm"
+ >
<Checkbox
id="addr-default-shipping"
checked={!!field.value}
onCheckedChange={field.onChange}
/>
- )}
- />
- </div>
+ {t('admin.fields.address.is_default_shipping.label')}
+ </label>
+ )}
+ />
</Field>
</>
)}
diff --git a/packages/dashboard/src/components/spree/address-fieldset.tsx b/packages/dashboard/src/components/spree/address-fieldset.tsx
index 73d89bbfcd..98329df5ee 100644
--- a/packages/dashboard/src/components/spree/address-fieldset.tsx
+++ b/packages/dashboard/src/components/spree/address-fieldset.tsx
@@ -1,5 +1,5 @@
import { CountryCombobox, StateCombobox, useCountryStates } from '@spree/dashboard-core'
-import { Field, FieldError, FieldLabel, Input } from '@spree/dashboard-ui'
+import { Field, FieldDescription, FieldError, FieldLabel, Input } from '@spree/dashboard-ui'
import {
Controller,
type FieldValues,
@@ -32,6 +32,8 @@ export function AddressFieldset<TValues extends FieldValues>({
form,
prefix,
legend,
+ companyName,
+ withLabel = false,
}: {
form: UseFormReturn<TValues>
/**
@@ -40,6 +42,17 @@ export function AddressFieldset<TValues extends FieldValues>({
*/
prefix?: Path<TValues>
legend?: string
+ /**
+ * The business this address belongs to, shown read-only above the contact
+ * name. Pass it where the owner already answers the question — a company
+ * node names itself, so there is nothing for the merchant to type.
+ */
+ companyName?: string
+ /**
+ * Renders the address-book label field. Only a form whose address is a book
+ * entry wants it; an order's or a seller's address has nothing to file.
+ */
+ withLabel?: boolean
}) {
const { t } = useTranslation()
// Paths are composed as strings and cast once here: RHF cannot infer that
@@ -59,10 +72,42 @@ export function AddressFieldset<TValues extends FieldValues>({
return block?.[field]
}
+ // A form that is *only* an address needs no grouping chrome — the sheet
+ // heading already says what these fields are. The border and legend are for
+ // a form carrying several addresses at once.
+ const Wrapper = legend ? 'fieldset' : 'div'
+
return (
- <fieldset className="flex flex-col gap-4 rounded-md border p-4">
+ <Wrapper
+ className={legend ? 'flex flex-col gap-4 rounded-md border p-4' : 'flex flex-col gap-4'}
+ >
{legend && <legend className="px-1 font-medium text-sm">{legend}</legend>}
+ {withLabel && (
+ <Field>
+ <FieldLabel htmlFor={`${prefix ?? 'address'}-label`}>
+ {t('admin.fields.company_address.label.label')}
+ </FieldLabel>
+ <Input
+ id={`${prefix ?? 'address'}-label`}
+ placeholder={t('admin.fields.company_address.label.placeholder')}
+ {...form.register(path('label'))}
+ />
+ <FieldDescription>{t('admin.fields.company_address.label.help')}</FieldDescription>
+ <FieldError errors={[errorFor('label')]} />
+ </Field>
+ )}
+
+ {companyName && (
+ <Field>
+ <FieldLabel htmlFor={`${prefix ?? 'address'}-company`}>
+ {t('admin.fields.company.label')}
+ </FieldLabel>
+ <Input id={`${prefix ?? 'address'}-company`} value={companyName} disabled readOnly />
+ <FieldDescription>{t('admin.fields.company.help')}</FieldDescription>
+ </Field>
+ )}
+
<div className="grid gap-4 sm:grid-cols-2">
<Field>
<FieldLabel htmlFor={`${prefix ?? 'address'}-first-name`}>
@@ -179,6 +224,6 @@ export function AddressFieldset<TValues extends FieldValues>({
<Input id={`${prefix ?? 'address'}-phone`} {...form.register(path('phone'))} />
<FieldError errors={[errorFor('phone')]} />
</Field>
- </fieldset>
+ </Wrapper>
)
}
diff --git a/packages/dashboard/src/components/spree/company-address-sheet.tsx b/packages/dashboard/src/components/spree/company-address-sheet.tsx
index 7fd22a91e2..11a092cdc0 100644
--- a/packages/dashboard/src/components/spree/company-address-sheet.tsx
+++ b/packages/dashboard/src/components/spree/company-address-sheet.tsx
@@ -4,12 +4,7 @@ import { mapSpreeErrorsToForm } from '@spree/dashboard-core'
import {
Button,
Checkbox,
- Field,
- FieldDescription,
- FieldError,
FieldGroup,
- FieldLabel,
- Input,
Sheet,
SheetContent,
SheetDescription,
@@ -30,17 +25,18 @@ import {
import { AddressFieldset } from './address-fieldset'
/**
- * Creates an entry in a company node's address book, or edits one. The entry
- * owns its address row outright; promoting it to a default demotes the prior
- * default of the same kind.
+ * Creates an entry in a company node's address book, or edits one. The node
+ * owns the address outright, and points at one entry per kind as its default.
*/
export function CompanyAddressSheet({
companyId,
+ companyName,
entry,
open,
onOpenChange,
}: {
companyId: string
+ companyName: string
entry?: Address
open: boolean
onOpenChange: (open: boolean) => void
@@ -115,22 +111,7 @@ export function CompanyAddressSheet({
</p>
)}
- <Field>
- <FieldLabel htmlFor="company-address-label">
- {t('admin.fields.company_address.label.label')}
- </FieldLabel>
- <Input
- id="company-address-label"
- autoFocus
- placeholder={t('admin.fields.company_address.label.placeholder')}
- aria-invalid={!!errors.label || undefined}
- {...form.register('label')}
- />
- <FieldDescription>{t('admin.fields.company_address.label.help')}</FieldDescription>
- <FieldError errors={[errors.label]} />
- </Field>
-
- <AddressFieldset form={form} legend={t('admin.company_addresses.address_legend')} />
+ <AddressFieldset form={form} companyName={companyName} withLabel />
<Controller
control={form.control}
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index bec903a0fa..934160464c 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -447,7 +447,7 @@
"message": "ستتم إزالة {{label}} من دفتر العناوين. لا يمكن التراجع عن هذا.",
"title": "حذف هذا العنوان؟"
},
- "sheet_description": "موقع شحن أو فوترة مسمى لهذه العقدة. افتراضي واحد على الأكثر من كل نوع؛ ترقية عنوان تلغي الافتراضي السابق.",
+ "sheet_description": "موقع شحن أو فوترة مُسمّى لهذه العقدة. تشير العقدة إلى عنوان افتراضي واحد لكل نوع.",
"title": "دفتر العناوين"
},
"company_invitations": {
@@ -1018,10 +1018,12 @@
"help": "مرجعك الخاص لهذه الشركة، فريد داخل المتجر.",
"placeholder": "ACME-001"
},
+ "help": "مأخوذ من الشركة التي ينتمي إليها هذا العنوان.",
"kind": {
"help": "الشركة كيان قانوني يمكنه حمل تسجيلات ضريبية. القسم يستخدم تسجيلات كيانه القانوني.",
"label": "النوع"
},
+ "label": "الشركة",
"name": {
"placeholder": "Acme Industries"
}
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index cf5af2723d..3c58a435ff 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -441,7 +441,7 @@
"message": "{{label}} wird aus dem Adressbuch entfernt. Dies kann nicht rückgängig gemacht werden.",
"title": "Diese Adresse löschen?"
},
- "sheet_description": "Ein benannter Liefer- oder Rechnungsstandort dieses Knotens. Höchstens ein Standard je Art; ein neuer Standard löst den vorherigen ab.",
+ "sheet_description": "Ein benannter Liefer- oder Rechnungsstandort für diesen Knoten. Der Knoten verweist je Art auf eine Standardadresse.",
"title": "Adressbuch"
},
"company_invitations": {
@@ -1001,10 +1001,12 @@
"help": "Ihre eigene Referenz für diese Firma, eindeutig innerhalb des Shops.",
"placeholder": "ACME-001"
},
+ "help": "Wird vom Unternehmen übernommen, zu dem diese Adresse gehört.",
"kind": {
"help": "Ein Unternehmen ist eine juristische Einheit mit eigenen Steuerregistrierungen. Eine Abteilung nutzt die ihrer juristischen Einheit.",
"label": "Art"
},
+ "label": "Unternehmen",
"name": {
"placeholder": "Acme Industries"
}
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 2e80c90d19..54c2be1d51 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -441,7 +441,7 @@
"message": "{{label}} will be removed from the address book. This cannot be undone.",
"title": "Delete this address?"
},
- "sheet_description": "A labeled ship-to or bill-to site for this node. At most one default of each kind; promoting an entry demotes the previous default.",
+ "sheet_description": "A labeled ship-to or bill-to site for this node. The node points at one address per kind as its default.",
"title": "Address book"
},
"company_invitations": {
@@ -1001,10 +1001,12 @@
"help": "Your own reference for this business, unique within the store.",
"placeholder": "ACME-001"
},
+ "help": "Taken from the company this address belongs to.",
"kind": {
"help": "A company is a legal entity that can hold tax registrations. A division borrows its legal entity’s.",
"label": "Kind"
},
+ "label": "Company",
"name": {
"placeholder": "Acme Industries"
}
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index 87c5429725..6825daa574 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -441,7 +441,7 @@
"message": "{{label}} sera retirée du carnet d’adresses. Cette action est irréversible.",
"title": "Supprimer cette adresse ?"
},
- "sheet_description": "Un site de livraison ou de facturation nommé pour ce nœud. Au plus un défaut de chaque type ; en promouvoir un rétrograde le précédent.",
+ "sheet_description": "Un site de livraison ou de facturation nommé pour ce nœud. Le nœud désigne une adresse par défaut de chaque type.",
"title": "Carnet d’adresses"
},
"company_invitations": {
@@ -1001,10 +1001,12 @@
"help": "Votre propre référence pour cette entreprise, unique dans la boutique.",
"placeholder": "ACME-001"
},
+ "help": "Repris de l'entreprise à laquelle appartient cette adresse.",
"kind": {
"help": "Une entreprise est une entité juridique pouvant détenir des immatriculations fiscales. Une division utilise celles de son entité juridique.",
"label": "Type"
},
+ "label": "Entreprise",
"name": {
"placeholder": "Acme Industries"
}
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index e19b167c1a..058ff1d7ef 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -451,7 +451,7 @@
"message": "{{label}} zostanie usunięty z książki adresowej. Tej operacji nie można cofnąć.",
"title": "Usunąć ten adres?"
},
- "sheet_description": "Nazwany adres dostawy lub rozliczeń tego węzła. Najwyżej jeden domyślny każdego rodzaju; nowy domyślny zastępuje poprzedni.",
+ "sheet_description": "Nazwana lokalizacja dostawy lub rozliczeń dla tego węzła. Węzeł wskazuje jeden adres domyślny każdego rodzaju.",
"title": "Książka adresowa"
},
"company_invitations": {
@@ -1019,10 +1019,12 @@
"help": "Twój własny identyfikator tej firmy, unikalny w sklepie.",
"placeholder": "ACME-001"
},
+ "help": "Pobrane z firmy, do której należy ten adres.",
"kind": {
"help": "Firma to podmiot prawny mogący posiadać rejestracje podatkowe. Oddział korzysta z rejestracji swojego podmiotu prawnego.",
"label": "Rodzaj"
},
+ "label": "Firma",
"name": {
"placeholder": "Acme Industries"
}
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index fdf6b4274f..00684a1ea9 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -439,7 +439,7 @@
"message": "{{label}} 将从地址簿中移除。此操作无法撤销。",
"title": "删除该地址?"
},
- "sheet_description": "该节点的具名收货或账单地址。每种默认地址至多一个;设置新的默认地址会替换之前的。",
+ "sheet_description": "此节点的命名收货或账单地点。每个节点为每种类型指定一个默认地址。",
"title": "地址簿"
},
"company_invitations": {
@@ -996,10 +996,12 @@
"help": "您为该企业设定的编号,在本店内唯一。",
"placeholder": "ACME-001"
},
+ "help": "取自此地址所属的公司。",
"kind": {
"help": "公司是可持有税务登记的法律实体。部门使用其法律实体的登记。",
"label": "类型"
},
+ "label": "公司",
"name": {
"placeholder": "Acme Industries"
}
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/companies/$companyId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/companies/$companyId.tsx
index bbbe89fe42..32d547f107 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/companies/$companyId.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/companies/$companyId.tsx
@@ -568,24 +568,27 @@ function AddressBookCard({ company, canEdit }: { company: Company; canEdit: bool
<AddressBlock address={entry} />
</div>
{canEdit && (
- <span className="flex shrink-0 gap-1">
- <Button
- variant="ghost"
- size="icon-xs"
- onClick={() => setEditing(entry)}
- aria-label={t('admin.actions.edit')}
- >
- <PencilIcon className="size-4" />
- </Button>
- <Button
- variant="ghost"
- size="icon-xs"
- onClick={() => handleRemove(entry)}
- aria-label={t('admin.actions.delete')}
- >
- <TrashIcon className="size-4" />
- </Button>
- </span>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost" size="icon-xs" className="shrink-0">
+ <EllipsisVerticalIcon className="size-4" />
+ <span className="sr-only">{t('admin.actions.actions_menu')}</span>
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuItem onClick={() => setEditing(entry)}>
+ <PencilIcon className="size-4" />
+ {t('admin.actions.edit')}
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ className="text-destructive focus:text-destructive"
+ onClick={() => handleRemove(entry)}
+ >
+ <TrashIcon className="size-4" />
+ {t('admin.actions.delete')}
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
)}
</div>
))}
@@ -596,6 +599,7 @@ function AddressBookCard({ company, canEdit }: { company: Company; canEdit: bool
{editing && (
<CompanyAddressSheet
companyId={company.id}
+ companyName={company.name}
entry={editing === 'new' ? undefined : editing}
open
onOpenChange={(open) => !open && setEditing(null)}
diff --git a/packages/dashboard/src/schemas/company.ts b/packages/dashboard/src/schemas/company.ts
index 5afddd5590..433763d97e 100644
--- a/packages/dashboard/src/schemas/company.ts
+++ b/packages/dashboard/src/schemas/company.ts
@@ -59,10 +59,13 @@ export const companyAddressFormSchema = addressFieldsSchema.extend({
export type CompanyAddressFormValues = z.infer<typeof companyAddressFormSchema>
+// A new entry is offered as both defaults: the node points at one address per
+// kind, so the common case — the first site a node gets — is the answer to
+// both, and there is no previous default for it to displace.
export const COMPANY_ADDRESS_DEFAULTS: CompanyAddressFormValues = {
label: '',
- default_billing: false,
- default_shipping: false,
+ default_billing: true,
+ default_shipping: true,
first_name: '',
last_name: '',
company: '',