Files
CRM_Montzar/docs/superpowers/specs/2026-11-29-person-picker-design.md
T
Mahdi 33c95d72a8 feat: add invoice builder with line detail, address, and person picker.
Enrich invoice line items and previews, migrate several CRM surfaces to Ant, and wire shared money/picker helpers.
2026-11-30 14:34:47 +03:30

102 lines
4.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# PersonPicker — Design Spec
**Date:** 2026-11-29
**Status:** Approved in conversation (layout A, scope 2, create-via-modal)
## Problem
«افزودن شخص جدید» alongside person select is duplicated and visually awkward (link button under select). Activity and Deal copy the same search + modal logic; Invoice uses a different label and navigates away instead of creating inline.
## Goals
1. One Ant Design Vue component for person select + create.
2. Cleaner UX: create action lives in the select dropdown footer.
3. Create always opens embedded `PersonFormView` in a modal; after save, select that person without leaving the parent form.
4. Wire into Activity form, Deal form, and Invoice form. Treasury stays out of scope.
## Non-goals
- Refactoring `TreasuryPartySelect` (multi-kind party: person/company/user/other).
- Migrating unrelated form chrome or legacy `Ui*` kits beyond what this component needs for its own modal.
- Shared company picker.
## Approach
**Full `PersonPicker` component** that owns:
- `a-select` with server search (`GET /people?q=&limit=30`, 300ms debounce)
- Dropdown footer: divider + link button (`UserAddOutlined` + configurable label)
- Modal with embedded `PersonFormView`
- Optional seed list so parents can keep already-loaded people visible
Parents keep only `v-model` (person id) and optional side effects on `created` / `change`.
## API
**File:** `apps/web/src/components/PersonPicker.vue`
| Prop / model | Type | Default | Notes |
|---|---|---|---|
| `modelValue` (`v-model`) | `string` | `''` | Selected person id |
| `placeholder` | `string` | `'جستجو و انتخاب شخص'` | |
| `allowClear` | `boolean` | `true` | |
| `disabled` | `boolean` | `false` | |
| `addLabel` | `string` | `'افزودن شخص جدید'` | Invoice may pass `'افزودن مشتری جدید'` |
| `seedPeople` | `PersonDto[]` | `[]` | Initial / remembered options |
| `modalNest` | `boolean` | `false` | Forward `nest` to modal when parent is already nested |
| Emit | Payload | When |
|---|---|---|
| `update:modelValue` | `string` | Selection cleared or changed |
| `change` | `PersonDto \| null` | Resolved person object when known; `null` on clear |
| `created` | `PersonDto` | After successful create in modal (also selects that person) |
## UI / design rules
- Ant-only controls; no raw HTML buttons/inputs; no new scoped look CSS.
- No manual `size` on Ant controls (theme `controlHeight: 36`).
- Dropdown footer: `a-divider` + `a-button type="link"` with icon; stop mousedown so select does not steal focus/close incorrectly (same pattern as `TreasuryPartySelect`).
- Modal: prefer `a-modal` if the surrounding page is Ant-migrated and does not already depend on `UiModal` for this flow; if nesting/`UiModal` is required for Activity’s existing nest behavior, match current Activity/Deal nesting so z-index/stacking does not regress.
- Pass `:initial-query` from the current search string into `PersonFormView` when opening create.
## Parent integration
### ActivityFormView
- Replace select + link + person-search watchers + create modal with `<PersonPicker v-model="personId" :seed-people="people" @change="…" @created="…" />`.
- On `change`/`created`, call existing `rememberPerson` / deal-link side effects as today.
- Remove duplicated `personQuery` / `personResults` / `newPersonOpen` / modal block when fully owned by the picker (seed via `people` ref still updated from `change`).
### DealFormView
- Same as Activity.
- On `created` / person pick: keep `contactKind = 'person'` and company auto-fill from `person.company` (existing `pickPerson` behavior).
### InvoiceFormView
- Replace select + `RouterLink` «افزودن مشتری جدید» with `PersonPicker` (`add-label` optional).
- Switch from client-only filter over loaded `people` to server search inside the picker; pass current `people` as `seedPeople`.
- On create/select, ensure parent `people` list still has the chosen person for any labels/downstream logic.
## Behavior details
- Empty query: show seed / remembered options (not a forced empty list).
- Clear: emit `''` and `change(null)`.
- Create cancel: close modal only.
- Create save: close modal, merge person into internal options, set `modelValue`, emit `created` then selection updates.
- Loading: select `loading` while search in flight.
- Errors: failed search → empty options for that query (silent or message consistent with Activity today).
## Governance
- Shared component under `apps/web/src/components/` (not `components/ui`).
- Touch only the three views listed for replacement; no drive-by refactors.
- Ant strict rules: no new chrome CSS, no `size` props.
## Success criteria
- One shared component used in Activity, Deal, Invoice.
- No standalone «افزودن شخص جدید» link under the select in those three views.
- Create stays in-modal; Invoice no longer navigates away to create.
- `npm run build -w @mento/web` passes.