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.

Changed Getting Started from a nav entry to a sidebar checklist (#15010)

Damian Legawiec9f0550e81e0a
diff --git a/.changeset/dashboard-getting-started-widget.md b/.changeset/dashboard-getting-started-widget.md
new file mode 100644
index 0000000000..2c671d17de
--- /dev/null
+++ b/.changeset/dashboard-getting-started-widget.md
@@ -0,0 +1,8 @@
+---
+"@spree/dashboard": patch
+"@spree/dashboard-core": patch
+"@spree/dashboard-ui": patch
+"@spree/seller-dashboard": patch
+---
+
+Store setup moved from a Getting Started nav entry to a checklist card above the account menu in the admin dashboard. It shows overall progress and every step, marks the next one to take, and each step goes straight to where it is done: a settings page, or the address and storefront dialogs opened in place. The card can be minimized to its header, and stays that way until expanded again. Like the old entry, it disappears once setup is done or for staff who cannot change the store. The Getting Started page and the seller panel's onboarding page use the same step icons, now exported from `@spree/dashboard-ui` as `StepIcon` and `StepProgressRing`. `AppShell` gains a `sidebarWidget` prop for cards pinned above the account menu.
diff --git a/packages/dashboard-core/src/components/app-shell.tsx b/packages/dashboard-core/src/components/app-shell.tsx
index 5f2e26f8f5..1261842d3b 100644
--- a/packages/dashboard-core/src/components/app-shell.tsx
+++ b/packages/dashboard-core/src/components/app-shell.tsx
@@ -32,6 +32,7 @@ export function AppShell({
uiLocales,
onEditProfile,
notifications,
+ sidebarWidget,
children,
}: {
/** Prefix for the nav links. Defaults to the route's `storeId`. */
@@ -49,6 +50,8 @@ export function AppShell({
* notifications bell. The seller panel passes none.
*/
notifications?: ReactNode
+ /** A card pinned above the account menu, such as the store setup checklist. */
+ sidebarWidget?: ReactNode
children: ReactNode
}) {
// The settings area brings a full-width nav of its own, and two stacked
@@ -90,6 +93,7 @@ export function AppShell({
uiLocales={uiLocales}
onEditProfile={onEditProfile}
notifications={notifications}
+ widget={sidebarWidget}
/>
{/* The sheet is exactly as tall as the viewport and scrolls internally,
rather than growing with the page and letting the document scroll.
diff --git a/packages/dashboard-core/src/components/app-sidebar.tsx b/packages/dashboard-core/src/components/app-sidebar.tsx
index 8891ed5f86..3567332bf4 100644
--- a/packages/dashboard-core/src/components/app-sidebar.tsx
+++ b/packages/dashboard-core/src/components/app-sidebar.tsx
@@ -130,6 +130,7 @@ export function AppSidebar({
uiLocales,
onEditProfile,
notifications,
+ widget,
...props
}: ComponentProps<typeof Sidebar> & {
/**
@@ -145,6 +146,8 @@ export function AppSidebar({
onEditProfile?: () => void
/** Shown beside the account menu, such as a notifications bell. */
notifications?: ReactNode
+ /** A card pinned above the account menu. */
+ widget?: ReactNode
}) {
const { i18n } = useTranslation()
const { storeId } = useParams({ strict: false }) as { storeId?: string }
@@ -175,7 +178,7 @@ export function AppSidebar({
shell's shape steady and say the difference honestly.
Keyed on `isLoading` alone, not on an empty list: entries without a
- `subject` (Home, Getting Started) skip the permission filter, so the
+ `subject` (Home) skip the permission filter, so the
list is never actually empty and a length check would never fire. */}
{isLoading ? (
<NavSkeleton />
@@ -186,6 +189,8 @@ export function AppSidebar({
alone below a screen of empty space, so on a phone it follows
the list. */}
{isMobile && <NavBottom items={bottomItems} className="mb-2" />}
+ {/* The footer is hidden on a phone, so the widget follows the list. */}
+ {isMobile && widget && <div className="px-2 pb-2">{widget}</div>}
</>
)}
</SidebarContent>
@@ -193,6 +198,7 @@ export function AppSidebar({
list fades out above it rather than scrolling it away. */}
{!isLoading && !isMobile && <NavBottom items={bottomItems} className="py-2" />}
<SidebarFooter className="hidden md:flex">
+ {widget}
{/* In icon mode the rail is too narrow for a row, so the control
stacks above the avatar. */}
<div
diff --git a/packages/dashboard-ui/src/index.ts b/packages/dashboard-ui/src/index.ts
index 93542b1501..5d3fdda5ab 100644
--- a/packages/dashboard-ui/src/index.ts
+++ b/packages/dashboard-ui/src/index.ts
@@ -86,6 +86,7 @@ export * from './spree/row-actions'
export * from './spree/row-click-bridge'
export * from './spree/search-input'
export * from './spree/secret-input'
+export * from './spree/step-icon'
export * from './spree/storefront-visible-switch'
export * from './spree/tag-list'
export * from './spree/tax-identifiers-card'
diff --git a/packages/dashboard-ui/src/spree/step-icon.tsx b/packages/dashboard-ui/src/spree/step-icon.tsx
new file mode 100644
index 0000000000..6820c98526
--- /dev/null
+++ b/packages/dashboard-ui/src/spree/step-icon.tsx
@@ -0,0 +1,74 @@
+import { cn } from '../lib/utils'
+
+const R = 6.5
+const CIRCUMFERENCE = 2 * Math.PI * R
+
+/** Progress through a checklist as a ring that fills green. */
+export function StepProgressRing({
+ value,
+ max,
+ className,
+}: {
+ value: number
+ max: number
+ className?: string
+}) {
+ return (
+ <svg viewBox="0 0 16 16" className={cn('size-4 shrink-0 -rotate-90', className)} aria-hidden>
+ <circle cx="8" cy="8" r={R} fill="none" strokeWidth="1.5" className="stroke-border" />
+ <circle
+ cx="8"
+ cy="8"
+ r={R}
+ fill="none"
+ strokeWidth="1.5"
+ strokeLinecap="round"
+ strokeDasharray={CIRCUMFERENCE}
+ strokeDashoffset={CIRCUMFERENCE * (1 - value / (max || 1))}
+ className="stroke-success"
+ />
+ </svg>
+ )
+}
+
+export type StepStatus = 'done' | 'in_progress' | 'todo'
+
+/**
+ * A checklist step's state: a green check once done, a dashed blue ring while
+ * it is started but waiting on someone else (such as a review), and a plain
+ * ring before it is started.
+ */
+export function StepIcon({ status, className }: { status: StepStatus; className?: string }) {
+ const classes = cn('size-4 shrink-0', className)
+
+ if (status === 'done') {
+ return (
+ <svg viewBox="0 0 16 16" className={classes} aria-hidden>
+ <circle cx="8" cy="8" r="7.5" className="fill-success" />
+ <path
+ d="M5 8.2 7 10.2 11 6"
+ fill="none"
+ stroke="white"
+ strokeWidth="1.75"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ />
+ </svg>
+ )
+ }
+
+ return (
+ <svg viewBox="0 0 16 16" className={classes} aria-hidden>
+ <circle
+ cx="8"
+ cy="8"
+ r={R}
+ fill="none"
+ strokeWidth="1.5"
+ strokeLinecap="round"
+ strokeDasharray={status === 'in_progress' ? '2.5 2.6' : undefined}
+ className={status === 'in_progress' ? 'stroke-blue-500' : 'stroke-border'}
+ />
+ </svg>
+ )
+}
diff --git a/packages/dashboard-ui/src/ui/field.tsx b/packages/dashboard-ui/src/ui/field.tsx
index 02a2d1a506..150b6cf850 100644
--- a/packages/dashboard-ui/src/ui/field.tsx
+++ b/packages/dashboard-ui/src/ui/field.tsx
@@ -94,7 +94,7 @@ function FieldLabel({ className, ...props }: React.ComponentProps<typeof Label>)
<Label
data-slot="field-label"
className={cn(
- 'group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50 has-data-checked:border-blue-500/30 has-data-checked:bg-blue-500/5 has-[>[data-slot=field]]:rounded-lg has-[>[data-slot=field]]:border *:data-[slot=field]:p-2.5 dark:has-data-checked:border-blue-500/20 dark:has-data-checked:bg-blue-500/10',
+ 'group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50 has-data-checked:border-blue-100 has-data-checked:bg-blue-50 has-[>[data-slot=field]]:rounded-lg has-[>[data-slot=field]]:border *:data-[slot=field]:p-2.5 dark:has-data-checked:border-blue-500/20 dark:has-data-checked:bg-blue-500/10',
// Card-shaped labels (the ones wrapping a whole `Field`) are clickable
// targets, so they need the affordance a bare text label doesn't:
// a pointer and a hover tint. Scoped by `has-[>[data-slot=field]]` so
diff --git a/packages/dashboard/e2e/getting-started.spec.ts b/packages/dashboard/e2e/getting-started.spec.ts
index bd529fe81f..261412feb6 100644
--- a/packages/dashboard/e2e/getting-started.spec.ts
+++ b/packages/dashboard/e2e/getting-started.spec.ts
@@ -24,4 +24,54 @@ test.describe('getting started', () => {
timeout: 15_000,
})
})
+
+ test('sidebar checklist goes straight to each step and minimizes', async ({ page }) => {
+ const creds = await login(page)
+ await page.goto(`/${creds.store_id}/orders`)
+
+ const checklist = page.getByRole('navigation', { name: /^getting started$/i })
+ const header = checklist.getByRole('button', { name: /^getting started/i })
+ await expect(header).toHaveAttribute('aria-expanded', 'true', { timeout: 15_000 })
+
+ // Steps done in place open their dialog over the current page.
+ await checklist.getByRole('button', { name: /set up storefront/i }).click()
+ await expect(page.getByRole('heading', { name: /connect your storefront/i })).toBeVisible()
+ await page.keyboard.press('Escape')
+ await expect(page.getByRole('heading', { name: /connect your storefront/i })).toBeHidden()
+
+ // Minimizing survives a reload, and the header brings the steps back.
+ await header.click()
+ await expect(checklist.getByRole('listitem')).toHaveCount(0)
+ await page.reload()
+ await expect(header).toHaveAttribute('aria-expanded', 'false', { timeout: 15_000 })
+ await header.click()
+
+ // Other steps link to the page where they are done.
+ await checklist.getByRole('link', { name: /set up taxes collection/i }).click()
+ await expect(page).toHaveURL(new RegExp(`/${creds.store_id}/settings/taxes/rates(\\?|$)`))
+ await expect(page.getByRole('button', { name: /add tax rate/i })).toBeVisible({
+ timeout: 15_000,
+ })
+ })
+ test('sidebar checklist is gone once every step is done', async ({ page }) => {
+ // Finishing every step for real would change the shared store other specs
+ // read, so the store payload reports them done instead.
+ const storeUrl = /\/api\/v3\/admin\/store(\?|$)/
+ await page.route(storeUrl, async (route) => {
+ if (route.request().method() !== 'GET') return route.fallback()
+ const response = await route.fetch()
+ const store = await response.json()
+ store.setup_tasks = store.setup_tasks.map((task: object) => ({ ...task, done: true }))
+ await route.fulfill({ response, json: store })
+ })
+
+ const creds = await login(page)
+ const storeLoaded = page.waitForResponse(storeUrl)
+ await page.goto(`/${creds.store_id}/orders`)
+ await storeLoaded
+
+ await expect(page.getByRole('heading', { name: /^orders$/i })).toBeVisible({ timeout: 15_000 })
+ await expect(page.getByRole('link', { name: /^home$/i })).toBeVisible()
+ await expect(page.getByRole('navigation', { name: /^getting started$/i })).toHaveCount(0)
+ })
})
diff --git a/packages/dashboard/e2e/profile.spec.ts b/packages/dashboard/e2e/profile.spec.ts
index 878b3f8810..7083ba88ff 100644
--- a/packages/dashboard/e2e/profile.spec.ts
+++ b/packages/dashboard/e2e/profile.spec.ts
@@ -54,12 +54,12 @@ test.describe('profile', () => {
// Whole UI re-renders in Polish: the nav "Products" → "Produkty" (proves
// table/nav labels resolved at boot, not just live-subscribed components).
- await expect(page.getByRole('link', { name: /produkty/i })).toBeVisible({ timeout: 15_000 })
+ await expect(page.getByRole('link', { name: /^produkty$/i })).toBeVisible({ timeout: 15_000 })
// Survives a reload (locale persisted in localStorage + bundle loaded eagerly
// at boot).
await page.reload()
- await expect(page.getByRole('link', { name: /produkty/i })).toBeVisible({ timeout: 15_000 })
+ await expect(page.getByRole('link', { name: /^produkty$/i })).toBeVisible({ timeout: 15_000 })
// Table-driven pages also translate: the Customers list column headers are
// resolved from `i18n.t()` at module load, so they only render in Polish if
@@ -91,13 +91,13 @@ test.describe('profile', () => {
await page.getByRole('button', { name: /user menu/i }).click()
await page.getByRole('combobox', { name: /^language$/i }).selectOption({ label: 'Polski' })
- await expect(page.getByRole('link', { name: /produkty/i })).toBeVisible({ timeout: 15_000 })
+ await expect(page.getByRole('link', { name: /^produkty$/i })).toBeVisible({ timeout: 15_000 })
// The switch is saved to the account (PATCH /me), so it has to survive a
// reload rather than be reverted by the auth provider. Reloading is also
// what proves the save landed: nothing else here waits on that request.
await page.reload()
- await expect(page.getByRole('link', { name: /produkty/i })).toBeVisible({ timeout: 15_000 })
+ await expect(page.getByRole('link', { name: /^produkty$/i })).toBeVisible({ timeout: 15_000 })
// Reset to English via the top-bar menu (the picker is now "Język"), and
// confirm that save landed too — later specs in this serial run expect
diff --git a/packages/dashboard/e2e/store-settings.spec.ts b/packages/dashboard/e2e/store-settings.spec.ts
index 9d50de5f63..eeafa27c8a 100644
--- a/packages/dashboard/e2e/store-settings.spec.ts
+++ b/packages/dashboard/e2e/store-settings.spec.ts
@@ -114,7 +114,7 @@ test.describe('store settings — general', () => {
await expect(page.getByText('Standardy i formaty', { exact: true })).toBeVisible({
timeout: 15_000,
})
- await expect(page.getByRole('link', { name: /produkty/i })).toBeVisible()
+ await expect(page.getByRole('link', { name: /^produkty$/i })).toBeVisible()
// The crux: survives a reload. The switch must have been adopted as the
// admin's own `selected_locale` (PATCH /me), not just written to
@@ -306,7 +306,8 @@ test.describe('store settings — general', () => {
await expect(page.getByRole('menuitem', { name: /^view store$/i })).toHaveCount(0)
await page.keyboard.press('Escape')
- const step = page.getByRole('button', { name: /set up storefront/i })
+ // Scoped to the page: the sidebar checklist offers the same step.
+ const step = page.getByRole('main').getByRole('button', { name: /set up storefront/i })
if ((await step.getAttribute('aria-expanded')) !== 'true') await step.click()
await page.getByRole('button', { name: /^connect storefront$/i }).click()
await expect(page.getByLabel(/^storefront url$/i)).toHaveValue('')
diff --git a/packages/dashboard/src/components/spree/getting-started-nav-badge.tsx b/packages/dashboard/src/components/spree/getting-started-nav-badge.tsx
deleted file mode 100644
index 97005249f1..0000000000
--- a/packages/dashboard/src/components/spree/getting-started-nav-badge.tsx
+++ /dev/null
@@ -1,19 +0,0 @@
-import { useStore } from '@spree/dashboard-core'
-import { SidebarMenuBadge } from '@spree/dashboard-ui'
-
-// Progress counter next to the Getting Started nav entry, mirroring the
-// legacy admin's "n/m" badge. Hidden once every task is done.
-export function GettingStartedNavBadge() {
- const { store } = useStore()
- const tasks = store?.setup_tasks ?? []
- const done = tasks.filter((task) => task.done).length
-
- if (tasks.length === 0 || done === tasks.length) return null
-
- return (
- <SidebarMenuBadge>
- <span>{done}</span>
- <span className="opacity-50">/{tasks.length}</span>
- </SidebarMenuBadge>
- )
-}
diff --git a/packages/dashboard/src/components/spree/getting-started-widget.tsx b/packages/dashboard/src/components/spree/getting-started-widget.tsx
new file mode 100644
index 0000000000..f510cfe518
--- /dev/null
+++ b/packages/dashboard/src/components/spree/getting-started-widget.tsx
@@ -0,0 +1,172 @@
+import type { Store } from '@spree/admin-sdk'
+import { Subject, usePermissions, useStore } from '@spree/dashboard-core'
+import { cn, StepIcon, StepProgressRing, useSidebar } from '@spree/dashboard-ui'
+import { ChevronDownIcon } from '@spree/dashboard-ui/icons'
+import { Link, useNavigate } from '@tanstack/react-router'
+import { type ReactNode, useCallback, useEffect, useState } from 'react'
+import { useTranslation } from 'react-i18next'
+import { StoreAddressDialog, usePrimaryStockLocation } from './setup-tasks/store-address-task'
+import { SETUP_TASK_LINKS, setupTaskCopy } from './setup-tasks/types'
+import { StorefrontConnectSheet } from './storefront-connect-sheet'
+
+// Steps the checklist finishes in place rather than on another page.
+const IN_PLACE_TASKS = new Set(['setup_address', 'setup_storefront'])
+
+const MINIMIZED_KEY = 'spree-setup-checklist-minimized'
+
+function readMinimized(): boolean {
+ try {
+ return window.localStorage.getItem(MINIMIZED_KEY) === '1'
+ } catch {
+ return false
+ }
+}
+
+function writeMinimized(minimized: boolean) {
+ try {
+ if (minimized) window.localStorage.setItem(MINIMIZED_KEY, '1')
+ else window.localStorage.removeItem(MINIMIZED_KEY)
+ } catch {
+ // Storage blocked: the checklist opens expanded on the next visit.
+ }
+}
+
+// Store setup checklist pinned above the account menu. Each step goes straight
+// to where it is done — a settings page, or a dialog opened in place. It
+// replaces the old Getting Started nav entry, so it disappears the same way:
+// once every task is done, or for staff who cannot update the store.
+export function GettingStartedWidget() {
+ const { t } = useTranslation()
+ const { store, storeId } = useStore()
+ const { permissions } = usePermissions()
+ const { state, isMobile, setOpenMobile } = useSidebar()
+ const [minimized, setMinimized] = useState(readMinimized)
+ const [openTask, setOpenTask] = useState<string | null>(null)
+ const closeTask = useCallback(() => setOpenTask(null), [])
+
+ const tasks = (store as Store | null)?.setup_tasks ?? []
+ const done = tasks.filter((task) => task.done).length
+ const current = tasks.find((task) => !task.done)?.name
+ const collapsed = !isMobile && state === 'collapsed'
+
+ if (!store || !current || collapsed || !permissions.can('update', Subject.Store)) {
+ return null
+ }
+
+ // On a phone the card sits in the drawer, which a link should close. Dialogs
+ // opened in place keep it open: they are mounted inside it.
+ const closeDrawer = () => {
+ if (isMobile) setOpenMobile(false)
+ }
+
+ const toggle = () => {
+ setMinimized(!minimized)
+ writeMinimized(!minimized)
+ }
+
+ return (
+ <nav
+ aria-label={t('admin.pages.getting_started.title')}
+ className="mb-1 overflow-hidden rounded-xl border bg-card text-sm shadow-xs"
+ >
+ <button
+ type="button"
+ onClick={toggle}
+ aria-expanded={!minimized}
+ className={cn(
+ 'flex w-full items-center gap-2.5 px-3 py-2.5 text-muted-foreground hover:text-foreground',
+ !minimized && 'border-b',
+ )}
+ >
+ <StepProgressRing value={done} max={tasks.length} />
+ <span className="flex-1 truncate text-start font-medium">
+ {t('admin.pages.getting_started.title')}
+ </span>
+ <span className="tabular-nums">
+ {done}/{tasks.length}
+ </span>
+ <ChevronDownIcon
+ className={cn('size-4 shrink-0 transition-transform', minimized && 'rotate-180')}
+ />
+ </button>
+ {!minimized && (
+ <ul className="py-1">
+ {tasks.map((task) => {
+ const link = Object.hasOwn(SETUP_TASK_LINKS, task.name)
+ ? SETUP_TASK_LINKS[task.name]
+ : undefined
+ const row = (
+ <>
+ <StepIcon status={task.done ? 'done' : 'todo'} />
+ <span className="truncate">{setupTaskCopy(t, task.name, 'title')}</span>
+ </>
+ )
+ const className = cn(
+ 'flex w-full items-center gap-2.5 px-3 py-1.5 text-start hover:bg-accent',
+ task.done ? 'text-foreground' : 'text-foreground/80',
+ )
+
+ let control: ReactNode
+ if (link) {
+ control = (
+ <Link to={link} params={{ storeId }} className={className} onClick={closeDrawer}>
+ {row}
+ </Link>
+ )
+ } else if (IN_PLACE_TASKS.has(task.name)) {
+ control = (
+ <button type="button" onClick={() => setOpenTask(task.name)} className={className}>
+ {row}
+ </button>
+ )
+ } else {
+ // Extension tasks bring their own card body on the Getting
+ // Started page, so they open there.
+ control = (
+ <Link
+ to="/$storeId/getting-started"
+ params={{ storeId }}
+ search={{ task: task.name }}
+ className={className}
+ onClick={closeDrawer}
+ >
+ {row}
+ </Link>
+ )
+ }
+
+ return <li key={task.name}>{control}</li>
+ })}
+ </ul>
+ )}
+
+ {openTask === 'setup_address' && <AddressStep onClose={closeTask} />}
+ <StorefrontConnectSheet
+ store={store as Store}
+ open={openTask === 'setup_storefront'}
+ onOpenChange={(open) => setOpenTask(open ? 'setup_storefront' : null)}
+ />
+ </nav>
+ )
+}
+
+function AddressStep({ onClose }: { onClose: () => void }) {
+ const { storeId } = useStore()
+ const navigate = useNavigate()
+ const { location, isLoading } = usePrimaryStockLocation()
+ const missing = !isLoading && !location
+
+ // Without a location to write to, the Getting Started page explains why.
+ useEffect(() => {
+ if (!missing) return
+ navigate({
+ to: '/$storeId/getting-started',
+ params: { storeId },
+ search: { task: 'setup_address' },
+ })
+ onClose()
+ }, [missing, navigate, onClose, storeId])
+
+ if (!location) return null
+ return <StoreAddressDialog location={location} onClose={onClose} />
+}
diff --git a/packages/dashboard/src/components/spree/setup-tasks/store-address-task.tsx b/packages/dashboard/src/components/spree/setup-tasks/store-address-task.tsx
index 349f5ee45e..a767016532 100644
--- a/packages/dashboard/src/components/spree/setup-tasks/store-address-task.tsx
+++ b/packages/dashboard/src/components/spree/setup-tasks/store-address-task.tsx
@@ -1,3 +1,4 @@
+import type { StockLocation } from '@spree/admin-sdk'
import {
AddressFormDialog,
adminClient,
@@ -31,47 +32,8 @@ import type { SetupTaskSlotContext } from './types'
*/
export function StoreAddressTask({ task }: SetupTaskSlotContext) {
const { t } = useTranslation()
- const queryClient = useQueryClient()
const [editing, setEditing] = useState(false)
- const update = useUpdateStockLocationById()
-
- // Two filtered requests rather than one page filtered in the browser, to
- // match `Store#primary_location` exactly: a location that accepts returns
- // wins outright, and only then default and name decide. The list also holds
- // every seller's warehouse on a marketplace, so the operator's own
- // returns-enabled row can sit well past any page we could fetch — and
- // editing the wrong one means an address their parcels never come back to.
- //
- // The list endpoint cannot express the preference in one call: it orders by
- // default then name, and its `sort` param collapses to a single key.
- const firstParty = { seller_id_null: true, active_eq: true, limit: 1 }
- const {
- data: takesReturns,
- isFetching: fetchingReturns,
- isError: returnsFailed,
- } = useQuery({
- queryKey: useResourceKey('stock-locations', { firstParty: true, returns: true }),
- queryFn: () => adminClient.stockLocations.list({ ...firstParty, returns_enabled_eq: true }),
- })
- const hasReturnsLocation = (takesReturns?.data.length ?? 0) > 0
- const {
- data: anyActive,
- isFetching: fetchingAny,
- isError: anyFailed,
- } = useQuery({
- queryKey: useResourceKey('stock-locations', { firstParty: true }),
- queryFn: () => adminClient.stockLocations.list(firstParty),
- enabled: !!takesReturns && !hasReturnsLocation,
- })
-
- // `isFetching`, not `isLoading`: a disabled query stays pending forever, so
- // the fallback request would hold the skeleton open once the first one hit.
- const isLoading = fetchingReturns || fetchingAny
- const location = takesReturns?.data[0] ?? anyActive?.data[0]
- // A failed lookup must not read as "you have no warehouse" — that would
- // send the merchant off to create a second one they do not need.
- const failed = returnsFailed || anyFailed
-
+ const { location, isLoading, failed } = usePrimaryStockLocation()
const hasAddress = Boolean(location?.address1)
return (
@@ -101,25 +63,86 @@ export function StoreAddressTask({ task }: SetupTaskSlotContext) {
)}
{editing && location && (
- <AddressFormDialog
- title={t('admin.pages.getting_started.tasks.setup_address.title')}
- address={stockLocationToEditableAddress(location)}
- open
- business
- onOpenChange={setEditing}
- onSave={async (values) => {
- await update.mutateAsync({
- id: location.id,
- params: editableAddressToStockLocationParams(values),
- })
- // The checklist reads this address off the store payload, so the
- // tick and the nav badge only move once the store is re-read.
- await queryClient.invalidateQueries({ queryKey: [STORE_QUERY_RESOURCE] })
- setEditing(false)
- }}
- isPending={update.isPending}
- />
+ <StoreAddressDialog location={location} onClose={() => setEditing(false)} />
)}
</>
)
}
+
+/**
+ * The location the store's address lives on.
+ *
+ * Two filtered requests rather than one page filtered in the browser, to
+ * match `Store#primary_location` exactly: a location that accepts returns
+ * wins outright, and only then default and name decide. The list also holds
+ * every seller's warehouse on a marketplace, so the operator's own
+ * returns-enabled row can sit well past any page we could fetch — and
+ * editing the wrong one means an address their parcels never come back to.
+ *
+ * The list endpoint cannot express the preference in one call: it orders by
+ * default then name, and its `sort` param collapses to a single key.
+ */
+export function usePrimaryStockLocation() {
+ const firstParty = { seller_id_null: true, active_eq: true, limit: 1 }
+ const {
+ data: takesReturns,
+ isFetching: fetchingReturns,
+ isError: returnsFailed,
+ } = useQuery({
+ queryKey: useResourceKey('stock-locations', { firstParty: true, returns: true }),
+ queryFn: () => adminClient.stockLocations.list({ ...firstParty, returns_enabled_eq: true }),
+ })
+ const hasReturnsLocation = (takesReturns?.data.length ?? 0) > 0
+ const {
+ data: anyActive,
+ isFetching: fetchingAny,
+ isError: anyFailed,
+ } = useQuery({
+ queryKey: useResourceKey('stock-locations', { firstParty: true }),
+ queryFn: () => adminClient.stockLocations.list(firstParty),
+ enabled: !!takesReturns && !hasReturnsLocation,
+ })
+
+ return {
+ location: takesReturns?.data[0] ?? anyActive?.data[0],
+ // `isFetching`, not `isLoading`: a disabled query stays pending forever, so
+ // the fallback request would hold the skeleton open once the first one hit.
+ isLoading: fetchingReturns || fetchingAny,
+ // A failed lookup must not read as "you have no warehouse" — that would
+ // send the merchant off to create a second one they do not need.
+ failed: returnsFailed || anyFailed,
+ }
+}
+
+export function StoreAddressDialog({
+ location,
+ onClose,
+}: {
+ location: StockLocation
+ onClose: () => void
+}) {
+ const { t } = useTranslation()
+ const queryClient = useQueryClient()
+ const update = useUpdateStockLocationById()
+
+ return (
+ <AddressFormDialog
+ title={t('admin.pages.getting_started.tasks.setup_address.title')}
+ address={stockLocationToEditableAddress(location)}
+ open
+ business
+ onOpenChange={(open) => !open && onClose()}
+ onSave={async (values) => {
+ await update.mutateAsync({
+ id: location.id,
+ params: editableAddressToStockLocationParams(values),
+ })
+ // The checklist reads this address off the store payload, so its tick
+ // only moves once the store is re-read.
+ await queryClient.invalidateQueries({ queryKey: [STORE_QUERY_RESOURCE] })
+ onClose()
+ }}
+ isPending={update.isPending}
+ />
+ )
+}
diff --git a/packages/dashboard/src/components/spree/setup-tasks/types.ts b/packages/dashboard/src/components/spree/setup-tasks/types.ts
index 3f13fc1598..767846b2bb 100644
--- a/packages/dashboard/src/components/spree/setup-tasks/types.ts
+++ b/packages/dashboard/src/components/spree/setup-tasks/types.ts
@@ -1,4 +1,5 @@
import type { SetupTask, Store } from '@spree/admin-sdk'
+import type { TFunction } from 'i18next'
/**
* Slot name for a Getting Started task's card body. Register a component
@@ -8,9 +9,39 @@ import type { SetupTask, Store } from '@spree/admin-sdk'
*/
export const setupTaskSlot = (taskName: string) => `getting-started.task.${taskName}`
+/**
+ * Where each built-in task whose default card body (copy + CTA button)
+ * suffices is done. Tasks needing real UI register a slot component under
+ * `getting-started.task.<name>` instead — see setup-tasks/register.ts.
+ */
+export const SETUP_TASK_LINKS: Record<string, string> = {
+ setup_payment_method: '/$storeId/settings/payment-methods',
+ add_products: '/$storeId/products',
+ set_customer_support_email: '/$storeId/settings/emails',
+ setup_taxes_collection: '/$storeId/settings/taxes/rates',
+}
+
/** Context every setup-task slot component receives. */
export interface SetupTaskSlotContext {
task: SetupTask
store: Store
storeId: string
}
+
+/**
+ * A task's title, description or CTA. Extension tasks without registered copy
+ * fall back to a humanized name for the title and render no description/CTA.
+ * Going through defaultValue keeps the lookup inside i18next, so copy
+ * registered later (e.g. by a plugin locale bundle) wins without a code change.
+ */
+export function setupTaskCopy(
+ t: TFunction,
+ taskName: string,
+ facet: 'title' | 'description' | 'cta',
+): string | null {
+ const humanized = taskName.replace(/_/g, ' ').replace(/^./, (c) => c.toUpperCase())
+ const fallback = facet === 'title' ? humanized : ''
+ return (
+ t(`admin.pages.getting_started.tasks.${taskName}.${facet}`, { defaultValue: fallback }) || null
+ )
+}
diff --git a/packages/dashboard/src/components/spree/storefront-connect-sheet.tsx b/packages/dashboard/src/components/spree/storefront-connect-sheet.tsx
index 76619dcaed..734308653b 100644
--- a/packages/dashboard/src/components/spree/storefront-connect-sheet.tsx
+++ b/packages/dashboard/src/components/spree/storefront-connect-sheet.tsx
@@ -1,4 +1,5 @@
import type { Store } from '@spree/admin-sdk'
+import { useStore } from '@spree/dashboard-core'
import {
Button,
CopyToClipboardButton,
@@ -14,6 +15,7 @@ import {
toastManager,
} from '@spree/dashboard-ui'
import { EyeIcon, EyeOffIcon } from '@spree/dashboard-ui/icons'
+import { useRouter } from '@tanstack/react-router'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useStorefrontPublishableKey } from '../../hooks/use-api-keys'
@@ -25,8 +27,13 @@ const STOREFRONT_DOCS_URL = 'https://spreecommerce.org/docs/developer/storefront
// Mirrors Spree::Admin::StorefrontHelper#vercel_deploy_url: clone the official
// Next.js storefront with the store's credentials prefilled, and come back to
-// the Getting Started page after a successful deploy.
-function vercelDeployUrl(store: Store, token: string, envDescription: string): string {
+// `returnUrl` after a successful deploy.
+function vercelDeployUrl(
+ store: Store,
+ token: string,
+ envDescription: string,
+ returnUrl: string,
+): string {
const params = new URLSearchParams({
'repository-url': STOREFRONT_REPOSITORY_URL,
'project-name': `${store.code}-storefront`,
@@ -38,7 +45,7 @@ function vercelDeployUrl(store: Store, token: string, envDescription: string): s
}),
envDescription,
envLink: `${STOREFRONT_REPOSITORY_URL}#readme`,
- 'redirect-url': window.location.origin + window.location.pathname,
+ 'redirect-url': returnUrl,
})
return `https://vercel.com/new/clone?${params.toString()}`
}
@@ -82,7 +89,18 @@ export function StorefrontConnectSheet({
initialUrl,
}: StorefrontConnectSheetProps) {
const { t } = useTranslation()
+ const { storeId } = useStore()
+ const router = useRouter()
const [url, setUrl] = useState(() => initialUrl ?? store.storefront_url ?? '')
+ // The sheet also opens from the sidebar checklist on any page, but only the
+ // Getting Started page picks up Vercel's callback and reopens it.
+ const returnUrl =
+ window.location.origin +
+ router.buildLocation({
+ to: '/$storeId/getting-started',
+ params: { storeId },
+ search: { task: 'setup_storefront' },
+ }).publicHref
const [showKey, setShowKey] = useState(false)
const {
@@ -208,6 +226,7 @@ export function StorefrontConnectSheet({
store,
token,
t('admin.pages.getting_started.storefront_sheet.env_description'),
+ returnUrl,
)
: undefined
}
diff --git a/packages/dashboard/src/nav/default.ts b/packages/dashboard/src/nav/default.ts
index 0dcbdf9fd5..3348d23a86 100644
--- a/packages/dashboard/src/nav/default.ts
+++ b/packages/dashboard/src/nav/default.ts
@@ -1,4 +1,3 @@
-import type { Store } from '@spree/admin-sdk'
// Entries use `labelKey` rather than a resolved `label` so the sidebar
// re-renders on language change — see app-sidebar.tsx for resolution.
import { hasVisibleSettingsEntries, nav, Subject } from '@spree/dashboard-core'
@@ -8,7 +7,6 @@ import {
GiftIcon,
HomeIcon,
InboxIcon,
- MapIcon,
PackageIcon,
SettingsIcon,
StoreIcon,
@@ -16,24 +14,8 @@ import {
UsersIcon,
WarehouseIcon,
} from '@spree/dashboard-ui/icons'
-import { GettingStartedNavBadge } from '../components/spree/getting-started-nav-badge'
import { navCounterBadge } from '../components/spree/nav-counter-badge'
-nav.add({
- key: 'getting-started',
- labelKey: 'admin.nav.getting_started',
- path: '/getting-started',
- icon: MapIcon,
- position: 50,
- subject: Subject.Store,
- // Store setup is settings work — every staffer can READ the store (shell
- // data), so gate on the authority the tasks actually need.
- action: 'update',
- // Legacy-admin parity: the entry disappears once every setup task is done.
- if: ({ store }) => !!(store as Store | null)?.setup_tasks?.some((task) => !task.done),
- badge: GettingStartedNavBadge,
-})
-
nav.add({
key: 'home',
labelKey: 'admin.nav.home',
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId.tsx
index 97caa708b6..d5c262b473 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId.tsx
@@ -8,6 +8,7 @@ import {
import { createFileRoute, Outlet, useRouterState } from '@tanstack/react-router'
import { useState } from 'react'
import { CommandPalette } from '../../components/spree/command-palette/command-palette'
+import { GettingStartedWidget } from '../../components/spree/getting-started-widget'
import { Notifications } from '../../components/spree/notifications'
import { PluginRoutePage, usePluginRouteClaim } from '../../components/spree/plugin-route-page'
import { ProfileDialog } from '../../components/spree/profile-dialog'
@@ -67,6 +68,7 @@ function StoreShell({ storeId, inSettings }: { storeId: string; inSettings: bool
uiLocales={UI_LOCALES}
onEditProfile={() => setProfileOpen(true)}
notifications={<Notifications />}
+ sidebarWidget={<GettingStartedWidget />}
>
<ProfileDialog open={profileOpen} onOpenChange={setProfileOpen} />
{/* A plugin page more specific than the matched route (`/sellers/shopify`
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/getting-started.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/getting-started.tsx
index b115011d2e..233c2366a1 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/getting-started.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/getting-started.tsx
@@ -10,30 +10,41 @@ import {
Progress,
ProgressValue,
Skeleton,
+ StepIcon,
} from '@spree/dashboard-ui'
-import { CheckCircle2Icon, CircleIcon } from '@spree/dashboard-ui/icons'
import { createFileRoute, Link } from '@tanstack/react-router'
+import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import '../../../components/spree/setup-tasks/register'
-import { setupTaskSlot } from '../../../components/spree/setup-tasks/types'
-
-// Settings deep-links for the tasks whose default card body (copy + CTA
-// button) suffices. Tasks needing real UI register a slot component under
-// `getting-started.task.<name>` instead — see setup-tasks/register.ts.
-const TASK_LINKS: Record<string, string> = {
- setup_payment_method: '/$storeId/settings/payment-methods',
- add_products: '/$storeId/products',
- set_customer_support_email: '/$storeId/settings/emails',
- setup_taxes_collection: '/$storeId/settings/taxes/rates',
-}
+import {
+ SETUP_TASK_LINKS,
+ setupTaskCopy,
+ setupTaskSlot,
+} from '../../../components/spree/setup-tasks/types'
export const Route = createFileRoute('/_authenticated/$storeId/getting-started')({
+ // `task` opens that step. Other params pass through: the storefront step
+ // reads Vercel's `deployment-url` callback param.
+ validateSearch: (
+ search: Record<string, unknown>,
+ ): { task?: string } & Record<string, unknown> => ({
+ ...search,
+ task: typeof search.task === 'string' ? search.task : undefined,
+ }),
component: GettingStartedPage,
})
function GettingStartedPage() {
const { t } = useTranslation()
const { store, storeId } = useStore()
+ const { task: requested } = Route.useSearch()
+ const [open, setOpen] = useState<string[] | null>(null)
+ // A click in the sidebar while already on this page opens the new step.
+ const [seen, setSeen] = useState(requested)
+ if (seen !== requested) {
+ setSeen(requested)
+ setOpen(null)
+ }
if (!store) {
return (
@@ -48,19 +59,11 @@ function GettingStartedPage() {
const tasks = store.setup_tasks ?? []
const doneCount = tasks.filter((task) => task.done).length
const firstPending = tasks.find((task) => !task.done)?.name
+ // A stale or mistyped `?task=` falls back to the first unfinished step.
+ const opening = tasks.some((task) => task.name === requested) ? requested : firstPending
- const taskCopy = (task: SetupTask, facet: 'title' | 'description' | 'cta') => {
- // Extension tasks without registered copy fall back to a humanized name
- // for the title and render no description/CTA. Going through defaultValue
- // keeps the lookup inside i18next, so copy registered later (e.g. by a
- // plugin locale bundle) wins without a code change.
- const humanized = task.name.replace(/_/g, ' ').replace(/^./, (c) => c.toUpperCase())
- const fallback = facet === 'title' ? humanized : ''
- return (
- t(`admin.pages.getting_started.tasks.${task.name}.${facet}`, { defaultValue: fallback }) ||
- null
- )
- }
+ const taskCopy = (task: SetupTask, facet: 'title' | 'description' | 'cta') =>
+ setupTaskCopy(t, task.name, facet)
return (
<div className="flex flex-col gap-6">
@@ -82,22 +85,22 @@ function GettingStartedPage() {
{/* One card holding every step, rather than a card each: this is a single
checklist read top to bottom, and five separate frames made it read as
- five unrelated things. Opens on the first unfinished step. */}
+ five unrelated things. Opens on the requested step, or else the first
+ unfinished one. */}
<Card className="overflow-hidden py-0">
- <Accordion defaultValue={firstPending ? [firstPending] : []}>
+ <Accordion
+ value={open ?? (opening ? [opening] : [])}
+ onValueChange={(value) => setOpen(value as string[])}
+ >
{tasks.map((task) => {
- const link = TASK_LINKS[task.name]
+ const link = SETUP_TASK_LINKS[task.name]
const description = taskCopy(task, 'description')
const cta = taskCopy(task, 'cta')
return (
<AccordionItem key={task.name} value={task.name}>
<AccordionTrigger>
- {task.done ? (
- <CheckCircle2Icon className="size-5 shrink-0 text-success" />
- ) : (
- <CircleIcon className="size-5 shrink-0 text-muted-foreground" />
- )}
+ <StepIcon status={task.done ? 'done' : 'todo'} className="size-5" />
{/* Muted once done, so a glance down the list separates what
is left from what is finished without reading the icons. */}
<span className={task.done ? 'text-muted-foreground' : undefined}>
diff --git a/packages/seller-dashboard/src/pages/onboarding.tsx b/packages/seller-dashboard/src/pages/onboarding.tsx
index 6307bddff7..f82e81fd47 100644
--- a/packages/seller-dashboard/src/pages/onboarding.tsx
+++ b/packages/seller-dashboard/src/pages/onboarding.tsx
@@ -24,15 +24,13 @@ import {
Progress,
ScrollArea,
StatusBadge as SharedStatusBadge,
+ StepIcon,
Textarea,
toastManager,
} from '@spree/dashboard-ui'
import {
- CheckCircle2Icon,
ChevronRightIcon,
CircleAlertIcon,
- CircleIcon,
- ClockIcon,
ExternalLinkIcon,
XCircleIcon,
} from '@spree/dashboard-ui/icons'
@@ -517,17 +515,14 @@ function panelRoute(kind: string): string | undefined {
}
}
+// The operator's setup checklist icons, plus a submission sent back.
function StatusIcon({ status }: { status: string }) {
- if (status === 'complete') {
- return <CheckCircle2Icon className="size-5 shrink-0 text-success" />
- }
- if (status === 'pending') {
- return <ClockIcon className="size-5 shrink-0 text-warning" />
- }
+ if (status === 'complete') return <StepIcon status="done" className="size-5" />
+ if (status === 'pending') return <StepIcon status="in_progress" className="size-5" />
if (status === 'rejected') {
return <XCircleIcon className="size-5 shrink-0 text-destructive" />
}
- return <CircleIcon className="size-5 shrink-0 text-muted-foreground" />
+ return <StepIcon status="todo" className="size-5" />
}
function StatusBadge({ status }: { status: string }) {