@nocobase/app-skills 0.1.0-beta.63 → 0.1.0-beta.64
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 +1 -1
- package/skills/nocobase-app-development/SKILL.md +5 -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 +102 -53
- 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 +20 -1
- package/skills/nocobase-app-development/assets/list-edit-example/client/pages/skill-projects/locales.ts +0 -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 +286 -7
- package/skills/nocobase-app-development/references/frontend/component-selection.md +1 -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 +223 -95
- 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 +58 -13
- 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 +19 -16
- 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/scripts/check-ui-components.mjs +480 -7
- package/skills/nocobase-app-plugin-development/references/ui-design.md +1 -1
package/package.json
CHANGED
|
@@ -131,6 +131,10 @@ 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
|
+
**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).
|
|
137
|
+
|
|
134
138
|
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
139
|
|
|
136
140
|
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 +146,7 @@ Read the page for the task in front of you. Do not read all of them.
|
|
|
142
146
|
| Task | Read |
|
|
143
147
|
| --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
144
148
|
| 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 |
|
|
149
|
+
| 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
150
|
| 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
151
|
| Add an API endpoint, a webhook, or a callback; authenticate and authorize it | [server routes](references/server-routes.md) |
|
|
147
152
|
| 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
|
);
|
|
@@ -111,6 +111,59 @@ export default function CustomerDetailPage() {
|
|
|
111
111
|
parent.reload();
|
|
112
112
|
},
|
|
113
113
|
};
|
|
114
|
+
// A contact's actions: the table row's menu, and the card's on a phone where it is a full-size tap target (M8.1).
|
|
115
|
+
const contactMenu = (contact: Contact, size: 'icon-sm' | 'icon') => (
|
|
116
|
+
<DropdownMenu>
|
|
117
|
+
<DropdownMenuTrigger
|
|
118
|
+
render={
|
|
119
|
+
<Button
|
|
120
|
+
variant='ghost'
|
|
121
|
+
size={size}
|
|
122
|
+
aria-label={t('customerContacts.actionsFor', {
|
|
123
|
+
name: contact.name,
|
|
124
|
+
})}
|
|
125
|
+
/>
|
|
126
|
+
}
|
|
127
|
+
>
|
|
128
|
+
<MoreHorizontal />
|
|
129
|
+
</DropdownMenuTrigger>
|
|
130
|
+
<DropdownMenuContent align='end' className='w-auto min-w-40'>
|
|
131
|
+
<DropdownMenuItem
|
|
132
|
+
render={
|
|
133
|
+
<Link
|
|
134
|
+
to={{
|
|
135
|
+
pathname: `contacts/${contact.id}/edit`,
|
|
136
|
+
search: location.search,
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
}
|
|
140
|
+
>
|
|
141
|
+
{t('customerContacts.edit')}
|
|
142
|
+
</DropdownMenuItem>
|
|
143
|
+
<DropdownMenuSeparator />
|
|
144
|
+
<DropdownMenuItem
|
|
145
|
+
variant='destructive'
|
|
146
|
+
onClick={() => {
|
|
147
|
+
void (async () => {
|
|
148
|
+
if (!lock.acquire()) return;
|
|
149
|
+
try {
|
|
150
|
+
const fresh = await api.request<{ data: Contact }>({
|
|
151
|
+
path: `${base}/contacts/${encodeURIComponent(contact.id)}`,
|
|
152
|
+
});
|
|
153
|
+
setDeleting(fresh.data);
|
|
154
|
+
} catch (failure) {
|
|
155
|
+
setError(failure);
|
|
156
|
+
} finally {
|
|
157
|
+
lock.release();
|
|
158
|
+
}
|
|
159
|
+
})();
|
|
160
|
+
}}
|
|
161
|
+
>
|
|
162
|
+
{t('customerContacts.delete')}
|
|
163
|
+
</DropdownMenuItem>
|
|
164
|
+
</DropdownMenuContent>
|
|
165
|
+
</DropdownMenu>
|
|
166
|
+
);
|
|
114
167
|
const columns: ColumnDef<Contact>[] = [
|
|
115
168
|
{
|
|
116
169
|
accessorKey: 'name',
|
|
@@ -141,58 +194,8 @@ export default function CustomerDetailPage() {
|
|
|
141
194
|
{
|
|
142
195
|
id: 'actions',
|
|
143
196
|
header: t('customerContacts.actions'),
|
|
144
|
-
cell: ({ row }: { row: { original: Contact } }) =>
|
|
145
|
-
|
|
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>
|
|
195
|
-
),
|
|
197
|
+
cell: ({ row }: { row: { original: Contact } }) =>
|
|
198
|
+
contactMenu(row.original, 'icon-sm'),
|
|
196
199
|
},
|
|
197
200
|
]
|
|
198
201
|
: []),
|
|
@@ -233,7 +236,8 @@ export default function CustomerDetailPage() {
|
|
|
233
236
|
<div className='relative'>
|
|
234
237
|
<RefreshIndicator pending={active && request.loading} />
|
|
235
238
|
<dl
|
|
236
|
-
|
|
239
|
+
// Label above value on a phone, side by side from sm up (mobile.md M5.1).
|
|
240
|
+
className='grid gap-1 text-sm sm:grid-cols-[8rem_1fr] sm:gap-x-4 sm:gap-y-3'
|
|
237
241
|
aria-busy={active && request.loading}
|
|
238
242
|
>
|
|
239
243
|
<dt className='text-muted-foreground'>
|
|
@@ -305,6 +309,51 @@ export default function CustomerDetailPage() {
|
|
|
305
309
|
loadingIdentity={contacts.path}
|
|
306
310
|
listState={contactState}
|
|
307
311
|
onRetry={contacts.reload}
|
|
312
|
+
// Related records follow the list's phone pattern (mobile.md M5.3): email and phone open the
|
|
313
|
+
// phone's mail and dialer.
|
|
314
|
+
renderCard={(row, card) => (
|
|
315
|
+
<div className='flex items-start gap-2 rounded-lg border p-4'>
|
|
316
|
+
<div className='flex min-w-0 flex-1 flex-col gap-1 text-sm'>
|
|
317
|
+
<span className='font-medium break-words'>
|
|
318
|
+
{maintain.can && writable ? (
|
|
319
|
+
<RecordLink
|
|
320
|
+
to={{
|
|
321
|
+
pathname: `contacts/${row.original.id}/edit`,
|
|
322
|
+
search: location.search,
|
|
323
|
+
}}
|
|
324
|
+
>
|
|
325
|
+
{row.original.name}
|
|
326
|
+
</RecordLink>
|
|
327
|
+
) : (
|
|
328
|
+
row.original.name
|
|
329
|
+
)}
|
|
330
|
+
</span>
|
|
331
|
+
{row.original.title ? (
|
|
332
|
+
<span className='text-muted-foreground'>
|
|
333
|
+
{row.original.title}
|
|
334
|
+
</span>
|
|
335
|
+
) : null}
|
|
336
|
+
{row.original.email ? (
|
|
337
|
+
<a
|
|
338
|
+
className='break-all underline-offset-4 hover:underline'
|
|
339
|
+
href={`mailto:${row.original.email}`}
|
|
340
|
+
>
|
|
341
|
+
{row.original.email}
|
|
342
|
+
</a>
|
|
343
|
+
) : null}
|
|
344
|
+
{row.original.phone ? (
|
|
345
|
+
<a
|
|
346
|
+
className='underline-offset-4 hover:underline'
|
|
347
|
+
href={`tel:${row.original.phone}`}
|
|
348
|
+
>
|
|
349
|
+
{row.original.phone}
|
|
350
|
+
</a>
|
|
351
|
+
) : null}
|
|
352
|
+
</div>
|
|
353
|
+
{/* The row's menu, at a phone tap size (M3.1, M8.1). */}
|
|
354
|
+
{card.actions}
|
|
355
|
+
</div>
|
|
356
|
+
)}
|
|
308
357
|
/>
|
|
309
358
|
</>
|
|
310
359
|
)
|
|
@@ -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
|
);
|