@nocobase/app-skills 0.1.0-beta.63 → 0.1.0-beta.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -2
- package/skills/nocobase-app-development/SKILL.md +7 -0
- package/skills/nocobase-app-development/assets/business-examples/onboarding/client/pages/onboarding/index.tsx +35 -11
- package/skills/nocobase-app-development/assets/business-examples/onboarding/client/pages/onboarding/wizard.tsx +7 -2
- package/skills/nocobase-app-development/assets/business-examples/onboarding/tests/client/onboarding.test.tsx +8 -0
- package/skills/nocobase-app-development/assets/business-examples/procurement/client/pages/procurement/detail.tsx +3 -2
- package/skills/nocobase-app-development/assets/business-examples/procurement/client/pages/procurement/index.tsx +32 -10
- package/skills/nocobase-app-development/assets/customer-contacts-example/client/pages/customer-contacts/batch.tsx +8 -4
- package/skills/nocobase-app-development/assets/customer-contacts-example/client/pages/customer-contacts/detail.tsx +92 -61
- package/skills/nocobase-app-development/assets/customer-contacts-example/client/pages/customer-contacts/edit.tsx +24 -15
- package/skills/nocobase-app-development/assets/customer-contacts-example/client/pages/customer-contacts/index.tsx +146 -96
- package/skills/nocobase-app-development/assets/customer-contacts-example/client/pages/customer-contacts/locales.ts +6 -0
- package/skills/nocobase-app-development/assets/customer-contacts-example/client/pages/customer-contacts/shared.tsx +1 -1
- package/skills/nocobase-app-development/assets/customer-contacts-example/tests/client/customer-contacts.test.tsx +139 -0
- package/skills/nocobase-app-development/assets/list-edit-example/client/pages/skill-projects/detail.tsx +13 -4
- package/skills/nocobase-app-development/assets/list-edit-example/client/pages/skill-projects/edit.tsx +20 -72
- package/skills/nocobase-app-development/assets/list-edit-example/client/pages/skill-projects/index.tsx +46 -18
- package/skills/nocobase-app-development/assets/list-edit-example/client/pages/skill-projects/locales.ts +2 -8
- package/skills/nocobase-app-development/assets/list-edit-example/tests/client/skill-projects-changes.test.tsx +6 -3
- package/skills/nocobase-app-development/assets/list-edit-example/tests/client/skill-projects.test.tsx +312 -20
- package/skills/nocobase-app-development/references/database-and-data.md +2 -0
- package/skills/nocobase-app-development/references/frontend/component-selection.md +3 -1
- package/skills/nocobase-app-development/references/frontend/frontend-dev.md +25 -23
- package/skills/nocobase-app-development/references/frontend/mobile.md +136 -0
- package/skills/nocobase-app-development/references/frontend/references/child-routes.md +9 -5
- package/skills/nocobase-app-development/references/frontend/references/example/create-dialog.md +2 -0
- package/skills/nocobase-app-development/references/frontend/references/example/create-page.md +8 -18
- package/skills/nocobase-app-development/references/frontend/references/example/detail-page-tabs.md +21 -3
- package/skills/nocobase-app-development/references/frontend/references/example/edit-dialog.md +2 -0
- package/skills/nocobase-app-development/references/frontend/references/example/list-page.md +187 -110
- package/skills/nocobase-app-development/references/frontend/references/example/project-dashboard.md +3 -3
- package/skills/nocobase-app-development/references/frontend/references/example/project-form.md +19 -7
- package/skills/nocobase-app-development/references/frontend/references/example/types.md +5 -0
- package/skills/nocobase-app-development/references/frontend/references/executable-list-edit.md +1 -1
- package/skills/nocobase-app-development/references/frontend/references/executable-relation-batch.md +1 -1
- package/skills/nocobase-app-development/references/frontend/references/form.md +1 -1
- package/skills/nocobase-app-development/references/frontend/references/navigation.md +12 -5
- package/skills/nocobase-app-development/references/frontend/references/overlay.md +23 -93
- package/skills/nocobase-app-development/references/frontend/references/page.md +11 -8
- package/skills/nocobase-app-development/references/frontend/references/styling.md +14 -9
- package/skills/nocobase-app-development/references/frontend/references/table.md +97 -18
- package/skills/nocobase-app-development/references/frontend/references/testing.md +8 -8
- package/skills/nocobase-app-development/references/frontend/references/ui-library.md +20 -17
- package/skills/nocobase-app-development/references/frontend/scripts/capture.md +22 -13
- package/skills/nocobase-app-development/references/frontend/scripts/capture.mjs +16 -1
- package/skills/nocobase-app-development/references/frontend/templates/design.md +10 -4
- package/skills/nocobase-app-development/references/frontend/templates/prompts.md +3 -2
- package/skills/nocobase-app-development/references/frontend/templates/run.md +2 -2
- package/skills/nocobase-app-development/references/frontend/ui-acceptance.md +14 -0
- package/skills/nocobase-app-development/references/frontend/ui-guidelines.md +21 -17
- package/skills/nocobase-app-development/references/frontend/ui-workflow.md +6 -5
- package/skills/nocobase-app-development/references/migrations.md +2 -1
- package/skills/nocobase-app-development/references/submission.md +2 -2
- package/skills/nocobase-app-development/references/system-settings.md +1 -1
- package/skills/nocobase-app-development/scripts/check-ui-components.mjs +602 -7
- package/skills/nocobase-app-plugin-development/references/ui-design.md +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/app-skills",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.65",
|
|
4
4
|
"description": "Agent Skills for developing applications and plugins, upgrading and deploying NocoBase applications.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@playwright/test": "^1.62.1",
|
|
24
24
|
"prettier": "^3.9.6",
|
|
25
|
+
"vitest": "^4.1.10",
|
|
25
26
|
"@nocobase/dev-config": "0.1.0-beta.25"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
@@ -39,6 +40,7 @@
|
|
|
39
40
|
"scripts": {
|
|
40
41
|
"format": "prettier . --write",
|
|
41
42
|
"format:check": "prettier . --check",
|
|
42
|
-
"check": "pnpm format:check"
|
|
43
|
+
"check": "pnpm format:check",
|
|
44
|
+
"test": "vitest run"
|
|
43
45
|
}
|
|
44
46
|
}
|
|
@@ -131,6 +131,12 @@ Application and plugin UI share [the UI design contract](references/frontend/des
|
|
|
131
131
|
|
|
132
132
|
For business lists, reuse the template-provided `DataTable` and companions from `#components/data-table`, backed by the supported TanStack Table v8 dependency. Use its controlled manual mode for server paging/sorting. Do not replace it with an agent-written table engine when a dependency version is incompatible; inspect and repair the dependency first. See [tables](references/frontend/references/table.md).
|
|
133
133
|
|
|
134
|
+
Every page and overlay you build or change works on a phone in the first delivery, without the user asking: decide its phone layout while designing it and verify it at phone widths before calling it done, following [the phone experience](references/frontend/mobile.md). Shrinking the desktop page, wrapping its toolbar or scrolling an ordinary table sideways does not count; ordinary lists use `DataTable`'s phone cards (`renderCard`) and its `search`, `filters` and `getColumnLabel` toolbar row, and create and edit forms sit in a `FeedbackForm` given `values={form.getValues}` and `savedValues` (the stored record, or the blank values; never the restored draft) inside the route overlay, which asks before discarding any difference on every way out, whatever changed it and with or without a saved draft.
|
|
135
|
+
|
|
136
|
+
**Table row actions are one "⋮" menu (T1.5, Must).** Every table row's actions, a single action included, render through `RowActions` from `#components/row-actions` at the end of the row: the same icon-only "⋮" trigger on every row, in every record state and on every page, business and administration lists alike, with no visible header text over the actions column and no sticky or right-pinned column. The record's state and the viewer's permissions change which items the menu holds, never how the entry looks; no item left means no menu. Never show an action as a text link, an outline button or a row of buttons because it seems frequent or primary: show a named action outside the menu (`exposed`) only when the user asked for it or a confirmed page design shows it, and pin the column only for a wide table whose actions are otherwise out of reach, recording the reason. Details: [section 8 of `table.md`](references/frontend/references/table.md#8-column-definitions-and-row-actions).
|
|
137
|
+
|
|
138
|
+
**Unsaved input is never lost silently (M7.4, Must).** Every create or edit form is a `FeedbackForm` from `#components/feedback-form` with `values={form.getValues}` and `savedValues` (the stored record as the form shows it, or the blank values of a new record; never the restored draft), rendered inside its `RouteDialog`, `RouteDrawer` or covering `RouteChildPage`; a form kept in `useState` instead of React Hook Form passes `values={() => values}` and `savedValues` the same way. That layer then asks "Discard changes?" before Cancel, ×, Esc, the backdrop, browser back and links, and the browser warns before a reload, whenever the form differs from what is saved. Keeping a draft does not replace the question, and neither does working storage: do not swap `FeedbackForm` for a plain `<form>`, do not make `dirty` or a `beforeunload` handler depend on a draft or storage state, do not render `OwnDiscardQuestion` because a draft is kept (it only declares that the file's own guard asks about its unsaved input, as the settings forms do; a guard that only blocks while a save runs asks nothing), and do not test "cancel, reopen, the input is back" as the cancel path. An unknown outcome is not a lock: after a lost response, a 5xx or a timeout, `submission.pending` stays true for the same-key retry, but only `submitting` blocks leaving. Cancel stays enabled, `beforeClose` and any guard of your own read only the save in flight (never `submission.pending`), and the `FeedbackForm`'s `values` and `savedValues` make every way out ask "Discard changes?" as before the save; "Keep editing" keeps the input for the retry, and "Discard" really leaves, with the key left in session storage so reopening offers the same retry. The [component checker](scripts/check-ui-components.mjs) rejects a plain create or edit `<form>`, a `FeedbackForm` without `values` and `savedValues` (React Hook Form or `useState`), a draft-based `dirty`, and an `OwnDiscardQuestion` whose file has no guard reading an unsaved state, and no exception marker waives these findings. Details: [unsaved changes in an overlay](references/frontend/references/overlay.md#25-beforeclose-checks-before-closing).
|
|
139
|
+
|
|
134
140
|
Use [the frontend workflow](references/frontend/ui-workflow.md) selected during feature planning, or select it before a frontend-only change. Routine pages and CRUD using established patterns take the quick workflow; complex interactions and cross-module design decisions take the full workflow with internal design and acceptance reviews. Theme changes use their own verification. Each workflow routes to the relevant [UI guidelines](references/frontend/ui-guidelines.md) and [frontend handbook](references/frontend/frontend-dev.md); none adds a default user approval round.
|
|
135
141
|
|
|
136
142
|
The handbook's "Look up by task" table routes each frontend task to the sections that cover it, and [the worked example](references/frontend/references/example.md) holds the complete files of the projects feature its rules are illustrated with. Components are shadcn/ui primitives, added with the CLI when a page first needs one: the shadcn/ui skill in `references/frontend/shadcn/` covers their API and composition rules, and [its guide in this handbook](references/frontend/references/shadcn.md) says what to read there and where this application departs from it.
|
|
@@ -142,6 +148,7 @@ Read the page for the task in front of you. Do not read all of them.
|
|
|
142
148
|
| Task | Read |
|
|
143
149
|
| --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
144
150
|
| Anything under `client/`: pages, routes, components, styling, forms, API calls, copy, frontend tests | [frontend workflow](references/frontend/ui-workflow.md), which routes to the [frontend handbook](references/frontend/frontend-dev.md), the theme reference or the worked example |
|
|
151
|
+
| How a page works on a phone: first screen, lists as cards, filters, tabs, forms, overlays, touch, phone verification | [phone experience](references/frontend/mobile.md) |
|
|
145
152
|
| Search/paginate relation choices, save associations, or batch-assign selected records | [executable relation and batch example](references/frontend/references/executable-relation-batch.md), then the installed authorization Skill |
|
|
146
153
|
| Add an API endpoint, a webhook, or a callback; authenticate and authorize it | [server routes](references/server-routes.md) |
|
|
147
154
|
| Name an endpoint, shape its response or errors, validate its input, paginate a list, document it in the API document | [HTTP API design](references/http-api.md) |
|
|
@@ -79,23 +79,26 @@ export default function OnboardingPage() {
|
|
|
79
79
|
<AlertDescription>{t('onboarding.denied')}</AlertDescription>
|
|
80
80
|
</Alert>
|
|
81
81
|
) : null}
|
|
82
|
-
|
|
82
|
+
{/* The search box and the status filter share one row on a phone too (mobile.md M4.1). */}
|
|
83
|
+
<div className='flex items-center gap-2'>
|
|
83
84
|
<Input
|
|
84
|
-
className='max-w-sm'
|
|
85
|
+
className='min-w-0 flex-1 md:max-w-sm md:flex-none'
|
|
85
86
|
aria-label={t('onboarding.search')}
|
|
86
87
|
placeholder={t('onboarding.search')}
|
|
87
88
|
value={q}
|
|
88
89
|
onChange={(e) => filter('q', e.target.value)}
|
|
89
90
|
/>
|
|
90
|
-
<
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
id
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
<div className='w-36 shrink-0 md:w-48'>
|
|
92
|
+
<Choice
|
|
93
|
+
label={t('onboarding.all')}
|
|
94
|
+
value={status}
|
|
95
|
+
onChange={(v) => filter('status', v)}
|
|
96
|
+
options={['draft', 'submitted'].map((id) => ({
|
|
97
|
+
id,
|
|
98
|
+
name: t(`onboarding.${id || 'all'}`),
|
|
99
|
+
}))}
|
|
100
|
+
/>
|
|
101
|
+
</div>
|
|
99
102
|
</div>
|
|
100
103
|
{request.error ? (
|
|
101
104
|
<Alert variant='destructive'>
|
|
@@ -117,6 +120,27 @@ export default function OnboardingPage() {
|
|
|
117
120
|
onPaginationChange={table.onPaginationChange}
|
|
118
121
|
showSelectedCount={false}
|
|
119
122
|
emptyMessage={t('onboarding.empty')}
|
|
123
|
+
// Phones show one card per person (mobile.md M3): the name and status, then the work email.
|
|
124
|
+
renderCard={(row) => (
|
|
125
|
+
<div className='flex flex-col gap-1 rounded-lg border p-4 text-sm'>
|
|
126
|
+
<div className='flex flex-wrap items-center justify-between gap-2'>
|
|
127
|
+
<RecordLink
|
|
128
|
+
to={{ pathname: row.original.id, search: location.search }}
|
|
129
|
+
className='min-w-0 break-words'
|
|
130
|
+
>
|
|
131
|
+
{row.original.fullName || t('onboarding.draft')}
|
|
132
|
+
</RecordLink>
|
|
133
|
+
<span className='text-muted-foreground'>
|
|
134
|
+
{t(`onboarding.${row.original.status}`)}
|
|
135
|
+
</span>
|
|
136
|
+
</div>
|
|
137
|
+
{row.original.workEmail ? (
|
|
138
|
+
<span className='break-all text-muted-foreground'>
|
|
139
|
+
{row.original.workEmail}
|
|
140
|
+
</span>
|
|
141
|
+
) : null}
|
|
142
|
+
</div>
|
|
143
|
+
)}
|
|
120
144
|
/>
|
|
121
145
|
<Outlet context={{ reload: request.reload }} />
|
|
122
146
|
</PageContainer>
|
|
@@ -58,6 +58,7 @@ import {
|
|
|
58
58
|
} from '#components/ui/table';
|
|
59
59
|
import { Separator } from '#components/ui/separator';
|
|
60
60
|
import { ToggleGroup, ToggleGroupItem } from '#components/ui/toggle-group';
|
|
61
|
+
import { OwnDiscardQuestion } from '#components/discard-guard';
|
|
61
62
|
import { FeedbackForm } from '#components/feedback-form';
|
|
62
63
|
import { useListData } from '#hooks/use-list-data';
|
|
63
64
|
import {
|
|
@@ -287,8 +288,9 @@ function Editor({
|
|
|
287
288
|
);
|
|
288
289
|
useNavigationGuard(() => {
|
|
289
290
|
if (navigatingAfterSaveRef.current) return true;
|
|
290
|
-
if (lockedRef.current || refreshing
|
|
291
|
-
|
|
291
|
+
if (lockedRef.current || refreshing) return false;
|
|
292
|
+
// An unknown outcome is unsaved too: leaving asks, and discarding leaves; it never locks the page.
|
|
293
|
+
if (!dirty && !submission.pending) return true;
|
|
292
294
|
if (discardRef.current) return discardRef.current.promise;
|
|
293
295
|
let resolve!: (value: boolean) => void;
|
|
294
296
|
const promise = new Promise<boolean>((done) => {
|
|
@@ -552,6 +554,9 @@ function Editor({
|
|
|
552
554
|
status={detail?.record.status}
|
|
553
555
|
description={description}
|
|
554
556
|
>
|
|
557
|
+
{/* The wizard asks its own question: its input spans steps whose fields are not all on screen, so the page's
|
|
558
|
+
layer cannot compare them, and leaving during a held submission is blocked rather than asked. */}
|
|
559
|
+
<OwnDiscardQuestion />
|
|
555
560
|
<AlertDialog
|
|
556
561
|
open={confirmDiscard}
|
|
557
562
|
onOpenChange={(open) => {
|
|
@@ -389,9 +389,17 @@ it('locks save and submit through refresh and replays an uncertain submission wi
|
|
|
389
389
|
'The previous result is uncertain. Retry the same action with the original data before editing.',
|
|
390
390
|
),
|
|
391
391
|
).toBeVisible();
|
|
392
|
+
// An unknown outcome never locks the page: leaving asks, and "Keep editing" stays for the retry.
|
|
392
393
|
await userEvent.click(
|
|
393
394
|
screen.getByRole('link', { name: 'Back to onboarding', exact: true }),
|
|
394
395
|
);
|
|
396
|
+
await screen.findByRole('alertdialog', {
|
|
397
|
+
name: 'Discard unsaved changes?',
|
|
398
|
+
});
|
|
399
|
+
await userEvent.click(screen.getByRole('button', { name: 'Keep editing' }));
|
|
400
|
+
await waitFor(() =>
|
|
401
|
+
expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument(),
|
|
402
|
+
);
|
|
395
403
|
expect(
|
|
396
404
|
screen.getByRole('button', { name: 'Submit onboarding' }),
|
|
397
405
|
).toBeEnabled();
|
|
@@ -210,8 +210,9 @@ function Editor({
|
|
|
210
210
|
title={t(detail ? 'procurement.open' : 'procurement.new')}
|
|
211
211
|
className='sm:w-3xl'
|
|
212
212
|
beforeClose={() => {
|
|
213
|
-
if (busy
|
|
214
|
-
|
|
213
|
+
if (busy) return false;
|
|
214
|
+
// An unknown outcome is unsaved too: ask, never lock the drawer open.
|
|
215
|
+
if (dirty || submission.pending) {
|
|
215
216
|
setDiscard(true);
|
|
216
217
|
return false;
|
|
217
218
|
}
|
|
@@ -79,22 +79,25 @@ export default function ProcurementPage() {
|
|
|
79
79
|
<AlertDescription>{t('procurement.denied')}</AlertDescription>
|
|
80
80
|
</Alert>
|
|
81
81
|
) : null}
|
|
82
|
-
|
|
82
|
+
{/* The search box and the status filter share one row on a phone too (mobile.md M4.1). */}
|
|
83
|
+
<div className='flex items-center gap-2'>
|
|
83
84
|
<Input
|
|
84
|
-
className='max-w-sm'
|
|
85
|
+
className='min-w-0 flex-1 md:max-w-sm md:flex-none'
|
|
85
86
|
aria-label={t('procurement.search')}
|
|
86
87
|
placeholder={t('procurement.search')}
|
|
87
88
|
value={q}
|
|
88
89
|
onChange={(e) => filter('q', e.target.value)}
|
|
89
90
|
/>
|
|
90
|
-
<
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
<div className='w-36 shrink-0 md:w-48'>
|
|
92
|
+
<Choice
|
|
93
|
+
label={t('procurement.all')}
|
|
94
|
+
value={status}
|
|
95
|
+
onChange={(v) => filter('status', v)}
|
|
96
|
+
options={['', 'draft', 'submitted', 'rejected', 'approved'].map(
|
|
97
|
+
(id) => ({ id, name: t(`procurement.${id || 'all'}`) }),
|
|
98
|
+
)}
|
|
99
|
+
/>
|
|
100
|
+
</div>
|
|
98
101
|
</div>
|
|
99
102
|
{request.error ? (
|
|
100
103
|
<Alert variant='destructive'>
|
|
@@ -116,6 +119,25 @@ export default function ProcurementPage() {
|
|
|
116
119
|
onPaginationChange={table.onPaginationChange}
|
|
117
120
|
showSelectedCount={false}
|
|
118
121
|
emptyMessage={t('procurement.empty')}
|
|
122
|
+
// Phones show one card per request (mobile.md M3): title and status first, the total on the right.
|
|
123
|
+
renderCard={(row) => (
|
|
124
|
+
<div className='flex items-start justify-between gap-3 rounded-lg border p-4 text-sm'>
|
|
125
|
+
<div className='flex min-w-0 flex-col gap-1'>
|
|
126
|
+
<RecordLink
|
|
127
|
+
to={{ pathname: row.original.id, search: location.search }}
|
|
128
|
+
className='break-words'
|
|
129
|
+
>
|
|
130
|
+
{row.original.title || t('procurement.draft')}
|
|
131
|
+
</RecordLink>
|
|
132
|
+
<span className='text-muted-foreground'>
|
|
133
|
+
{t(`procurement.${row.original.status}`)}
|
|
134
|
+
</span>
|
|
135
|
+
</div>
|
|
136
|
+
<span className='shrink-0 tabular-nums'>
|
|
137
|
+
{(row.original.totalMinor / 100).toFixed(2)}
|
|
138
|
+
</span>
|
|
139
|
+
</div>
|
|
140
|
+
)}
|
|
119
141
|
/>
|
|
120
142
|
<Outlet context={{ reload: request.reload }} />
|
|
121
143
|
</PageContainer>
|
|
@@ -2,6 +2,7 @@ import { useApiClient } from '@nocobase/app-client';
|
|
|
2
2
|
import { useTranslation } from '@nocobase/i18n/client';
|
|
3
3
|
import { useId, useState } from 'react';
|
|
4
4
|
import { useOutletContext } from 'react-router';
|
|
5
|
+
import { FeedbackForm } from '#components/feedback-form';
|
|
5
6
|
import { RouteDialog } from '#components/route-dialog';
|
|
6
7
|
import { useRouteOverlay } from '#components/use-route-overlay';
|
|
7
8
|
import { Button } from '#components/ui/button';
|
|
@@ -111,11 +112,14 @@ export default function CustomerBatchPage() {
|
|
|
111
112
|
) : !ids.length ? (
|
|
112
113
|
<p>{t('customerContacts.noSelection')}</p>
|
|
113
114
|
) : (
|
|
114
|
-
<
|
|
115
|
+
<FeedbackForm
|
|
115
116
|
id={formId}
|
|
116
|
-
|
|
117
|
+
// The new value is unsaved input; choosing which field to change is not.
|
|
118
|
+
values={() => ({ status, ownerId })}
|
|
119
|
+
savedValues={{ status: 'active', ownerId: '' }}
|
|
120
|
+
onSubmit={async (e) => {
|
|
117
121
|
e.preventDefault();
|
|
118
|
-
|
|
122
|
+
await submit();
|
|
119
123
|
}}
|
|
120
124
|
className='flex flex-col gap-4'
|
|
121
125
|
>
|
|
@@ -152,7 +156,7 @@ export default function CustomerBatchPage() {
|
|
|
152
156
|
onValidityChange={setValidOwner}
|
|
153
157
|
/>
|
|
154
158
|
)}
|
|
155
|
-
</
|
|
159
|
+
</FeedbackForm>
|
|
156
160
|
)}
|
|
157
161
|
</RouteDialog>
|
|
158
162
|
);
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
useParams,
|
|
14
14
|
} from 'react-router';
|
|
15
15
|
import type { ColumnDef } from '@tanstack/react-table';
|
|
16
|
-
import { MoreHorizontal } from 'lucide-react';
|
|
17
16
|
import { RouteChildPage } from '#components/route-child-page';
|
|
18
17
|
import { BackButton } from '#components/back-button';
|
|
19
18
|
import { PageContainer } from '#components/page-container';
|
|
@@ -22,15 +21,9 @@ import { LongText } from '#components/long-text';
|
|
|
22
21
|
import { DataTable } from '#components/data-table';
|
|
23
22
|
import { RefreshIndicator } from '#components/loading';
|
|
24
23
|
import { RecordLink } from '#components/record-link';
|
|
24
|
+
import { RowActions } from '#components/row-actions';
|
|
25
25
|
import { StatusBadge } from '#components/status-badge';
|
|
26
26
|
import { Button } from '#components/ui/button';
|
|
27
|
-
import {
|
|
28
|
-
DropdownMenu,
|
|
29
|
-
DropdownMenuTrigger,
|
|
30
|
-
DropdownMenuContent,
|
|
31
|
-
DropdownMenuItem,
|
|
32
|
-
DropdownMenuSeparator,
|
|
33
|
-
} from '#components/ui/dropdown-menu';
|
|
34
27
|
import {
|
|
35
28
|
AlertDialog,
|
|
36
29
|
AlertDialogContent,
|
|
@@ -111,6 +104,46 @@ export default function CustomerDetailPage() {
|
|
|
111
104
|
parent.reload();
|
|
112
105
|
},
|
|
113
106
|
};
|
|
107
|
+
// A contact's actions: the table row's "⋮" menu, which DataTable also hands to the contact's phone card.
|
|
108
|
+
const contactMenu = (contact: Contact) => (
|
|
109
|
+
<RowActions
|
|
110
|
+
label={t('customerContacts.actionsFor', { name: contact.name })}
|
|
111
|
+
actions={[
|
|
112
|
+
{
|
|
113
|
+
key: 'edit',
|
|
114
|
+
label: t('customerContacts.edit'),
|
|
115
|
+
render: (
|
|
116
|
+
<Link
|
|
117
|
+
to={{
|
|
118
|
+
pathname: `contacts/${contact.id}/edit`,
|
|
119
|
+
search: location.search,
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
122
|
+
),
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
key: 'delete',
|
|
126
|
+
label: t('customerContacts.delete'),
|
|
127
|
+
destructive: true,
|
|
128
|
+
onClick: () => {
|
|
129
|
+
void (async () => {
|
|
130
|
+
if (!lock.acquire()) return;
|
|
131
|
+
try {
|
|
132
|
+
const fresh = await api.request<{ data: Contact }>({
|
|
133
|
+
path: `${base}/contacts/${encodeURIComponent(contact.id)}`,
|
|
134
|
+
});
|
|
135
|
+
setDeleting(fresh.data);
|
|
136
|
+
} catch (failure) {
|
|
137
|
+
setError(failure);
|
|
138
|
+
} finally {
|
|
139
|
+
lock.release();
|
|
140
|
+
}
|
|
141
|
+
})();
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
]}
|
|
145
|
+
/>
|
|
146
|
+
);
|
|
114
147
|
const columns: ColumnDef<Contact>[] = [
|
|
115
148
|
{
|
|
116
149
|
accessorKey: 'name',
|
|
@@ -140,59 +173,11 @@ export default function CustomerDetailPage() {
|
|
|
140
173
|
? [
|
|
141
174
|
{
|
|
142
175
|
id: 'actions',
|
|
143
|
-
header:
|
|
144
|
-
|
|
145
|
-
<DropdownMenu>
|
|
146
|
-
<DropdownMenuTrigger
|
|
147
|
-
render={
|
|
148
|
-
<Button
|
|
149
|
-
variant='ghost'
|
|
150
|
-
size='icon-sm'
|
|
151
|
-
aria-label={t('customerContacts.actionsFor', {
|
|
152
|
-
name: row.original.name,
|
|
153
|
-
})}
|
|
154
|
-
/>
|
|
155
|
-
}
|
|
156
|
-
>
|
|
157
|
-
<MoreHorizontal />
|
|
158
|
-
</DropdownMenuTrigger>
|
|
159
|
-
<DropdownMenuContent align='end' className='w-auto min-w-40'>
|
|
160
|
-
<DropdownMenuItem
|
|
161
|
-
render={
|
|
162
|
-
<Link
|
|
163
|
-
to={{
|
|
164
|
-
pathname: `contacts/${row.original.id}/edit`,
|
|
165
|
-
search: location.search,
|
|
166
|
-
}}
|
|
167
|
-
/>
|
|
168
|
-
}
|
|
169
|
-
>
|
|
170
|
-
{t('customerContacts.edit')}
|
|
171
|
-
</DropdownMenuItem>
|
|
172
|
-
<DropdownMenuSeparator />
|
|
173
|
-
<DropdownMenuItem
|
|
174
|
-
variant='destructive'
|
|
175
|
-
onClick={() => {
|
|
176
|
-
void (async () => {
|
|
177
|
-
if (!lock.acquire()) return;
|
|
178
|
-
try {
|
|
179
|
-
const fresh = await api.request<{ data: Contact }>({
|
|
180
|
-
path: `${base}/contacts/${encodeURIComponent(row.original.id)}`,
|
|
181
|
-
});
|
|
182
|
-
setDeleting(fresh.data);
|
|
183
|
-
} catch (failure) {
|
|
184
|
-
setError(failure);
|
|
185
|
-
} finally {
|
|
186
|
-
lock.release();
|
|
187
|
-
}
|
|
188
|
-
})();
|
|
189
|
-
}}
|
|
190
|
-
>
|
|
191
|
-
{t('customerContacts.delete')}
|
|
192
|
-
</DropdownMenuItem>
|
|
193
|
-
</DropdownMenuContent>
|
|
194
|
-
</DropdownMenu>
|
|
176
|
+
header: () => (
|
|
177
|
+
<span className='sr-only'>{t('customerContacts.actions')}</span>
|
|
195
178
|
),
|
|
179
|
+
cell: ({ row }: { row: { original: Contact } }) =>
|
|
180
|
+
contactMenu(row.original),
|
|
196
181
|
},
|
|
197
182
|
]
|
|
198
183
|
: []),
|
|
@@ -233,7 +218,8 @@ export default function CustomerDetailPage() {
|
|
|
233
218
|
<div className='relative'>
|
|
234
219
|
<RefreshIndicator pending={active && request.loading} />
|
|
235
220
|
<dl
|
|
236
|
-
|
|
221
|
+
// Label above value on a phone, side by side from sm up (mobile.md M5.1).
|
|
222
|
+
className='grid gap-1 text-sm sm:grid-cols-[8rem_1fr] sm:gap-x-4 sm:gap-y-3'
|
|
237
223
|
aria-busy={active && request.loading}
|
|
238
224
|
>
|
|
239
225
|
<dt className='text-muted-foreground'>
|
|
@@ -305,6 +291,51 @@ export default function CustomerDetailPage() {
|
|
|
305
291
|
loadingIdentity={contacts.path}
|
|
306
292
|
listState={contactState}
|
|
307
293
|
onRetry={contacts.reload}
|
|
294
|
+
// Related records follow the list's phone pattern (mobile.md M5.3): email and phone open the
|
|
295
|
+
// phone's mail and dialer.
|
|
296
|
+
renderCard={(row, card) => (
|
|
297
|
+
<div className='flex items-start gap-2 rounded-lg border p-4'>
|
|
298
|
+
<div className='flex min-w-0 flex-1 flex-col gap-1 text-sm'>
|
|
299
|
+
<span className='font-medium break-words'>
|
|
300
|
+
{maintain.can && writable ? (
|
|
301
|
+
<RecordLink
|
|
302
|
+
to={{
|
|
303
|
+
pathname: `contacts/${row.original.id}/edit`,
|
|
304
|
+
search: location.search,
|
|
305
|
+
}}
|
|
306
|
+
>
|
|
307
|
+
{row.original.name}
|
|
308
|
+
</RecordLink>
|
|
309
|
+
) : (
|
|
310
|
+
row.original.name
|
|
311
|
+
)}
|
|
312
|
+
</span>
|
|
313
|
+
{row.original.title ? (
|
|
314
|
+
<span className='text-muted-foreground'>
|
|
315
|
+
{row.original.title}
|
|
316
|
+
</span>
|
|
317
|
+
) : null}
|
|
318
|
+
{row.original.email ? (
|
|
319
|
+
<a
|
|
320
|
+
className='break-all underline-offset-4 hover:underline'
|
|
321
|
+
href={`mailto:${row.original.email}`}
|
|
322
|
+
>
|
|
323
|
+
{row.original.email}
|
|
324
|
+
</a>
|
|
325
|
+
) : null}
|
|
326
|
+
{row.original.phone ? (
|
|
327
|
+
<a
|
|
328
|
+
className='underline-offset-4 hover:underline'
|
|
329
|
+
href={`tel:${row.original.phone}`}
|
|
330
|
+
>
|
|
331
|
+
{row.original.phone}
|
|
332
|
+
</a>
|
|
333
|
+
) : null}
|
|
334
|
+
</div>
|
|
335
|
+
{/* The row's menu, at a phone tap size (M3.1, M8.1). */}
|
|
336
|
+
{card.actions}
|
|
337
|
+
</div>
|
|
338
|
+
)}
|
|
308
339
|
/>
|
|
309
340
|
</>
|
|
310
341
|
)
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
useParams,
|
|
9
9
|
} from 'react-router';
|
|
10
10
|
import { useForm, useWatch } from 'react-hook-form';
|
|
11
|
+
import { FeedbackForm } from '#components/feedback-form';
|
|
11
12
|
import { RouteDialog } from '#components/route-dialog';
|
|
12
13
|
import { useRouteOverlay } from '#components/use-route-overlay';
|
|
13
14
|
import { Button } from '#components/ui/button';
|
|
@@ -86,17 +87,20 @@ function Editor({
|
|
|
86
87
|
const initialCustomer = kind === 'customer' ? (row as Customer) : undefined;
|
|
87
88
|
const initialContact =
|
|
88
89
|
kind === 'contact' ? (row as Contact | undefined) : undefined;
|
|
90
|
+
// What is saved: the record as the form shows it, or the blank values of a new one. The dialog compares the form
|
|
91
|
+
// with it before every way out and asks "Discard changes?" when they differ (mobile.md M7.4).
|
|
92
|
+
const savedValues = {
|
|
93
|
+
name: row?.name ?? '',
|
|
94
|
+
notes: initialCustomer?.notes ?? '',
|
|
95
|
+
status: initialCustomer?.status ?? 'active',
|
|
96
|
+
ownerId: initialCustomer?.ownerId ?? '',
|
|
97
|
+
customerId: initialContact?.customerId ?? customerId,
|
|
98
|
+
email: initialContact?.email ?? '',
|
|
99
|
+
phone: initialContact?.phone ?? '',
|
|
100
|
+
title: initialContact?.title ?? '',
|
|
101
|
+
};
|
|
89
102
|
const form = useForm({
|
|
90
|
-
values:
|
|
91
|
-
name: row?.name ?? '',
|
|
92
|
-
notes: initialCustomer?.notes ?? '',
|
|
93
|
-
status: initialCustomer?.status ?? 'active',
|
|
94
|
-
ownerId: initialCustomer?.ownerId ?? '',
|
|
95
|
-
customerId: initialContact?.customerId ?? customerId,
|
|
96
|
-
email: initialContact?.email ?? '',
|
|
97
|
-
phone: initialContact?.phone ?? '',
|
|
98
|
-
title: initialContact?.title ?? '',
|
|
99
|
-
},
|
|
103
|
+
values: savedValues,
|
|
100
104
|
mode: 'onSubmit',
|
|
101
105
|
reValidateMode: 'onChange',
|
|
102
106
|
shouldFocusError: false,
|
|
@@ -224,6 +228,10 @@ function Editor({
|
|
|
224
228
|
aria-required={name === 'name'}
|
|
225
229
|
aria-invalid={Boolean(form.formState.errors[name])}
|
|
226
230
|
aria-describedby={`${formId}-${name}-error`}
|
|
231
|
+
// The phone's email or number keyboard (mobile.md M6.2); validation stays the form's own.
|
|
232
|
+
inputMode={
|
|
233
|
+
name === 'email' ? 'email' : name === 'phone' ? 'tel' : undefined
|
|
234
|
+
}
|
|
227
235
|
{...form.register(name, {
|
|
228
236
|
...(name === 'name'
|
|
229
237
|
? {
|
|
@@ -293,12 +301,13 @@ function Editor({
|
|
|
293
301
|
{!ready ? (
|
|
294
302
|
<ReadFeedback error={read.error} retry={read.reload} />
|
|
295
303
|
) : (
|
|
296
|
-
<
|
|
304
|
+
<FeedbackForm
|
|
297
305
|
id={formId}
|
|
298
|
-
|
|
299
|
-
|
|
306
|
+
values={form.getValues}
|
|
307
|
+
savedValues={savedValues}
|
|
308
|
+
onSubmit={async (e) => {
|
|
300
309
|
e.preventDefault();
|
|
301
|
-
|
|
310
|
+
await submit();
|
|
302
311
|
}}
|
|
303
312
|
className='flex flex-col gap-4'
|
|
304
313
|
>
|
|
@@ -398,7 +407,7 @@ function Editor({
|
|
|
398
407
|
</FieldError>
|
|
399
408
|
</div>
|
|
400
409
|
) : null}
|
|
401
|
-
</
|
|
410
|
+
</FeedbackForm>
|
|
402
411
|
)}
|
|
403
412
|
</RouteDialog>
|
|
404
413
|
);
|