@open-mercato/core 0.6.6-develop.6386.1.391a1afb9e → 0.6.6-develop.6388.1.b9b9f5e778
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/.turbo/turbo-build.log +1 -1
- package/dist/modules/customers/api/deals/map/route.js +433 -0
- package/dist/modules/customers/api/deals/map/route.js.map +7 -0
- package/dist/modules/customers/backend/customers/companies/create/page.js +2 -0
- package/dist/modules/customers/backend/customers/companies/create/page.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/map/components/DealsLocationPanel.js +159 -0
- package/dist/modules/customers/backend/customers/deals/map/components/DealsLocationPanel.js.map +7 -0
- package/dist/modules/customers/backend/customers/deals/map/components/DealsMapCanvas.js +26 -0
- package/dist/modules/customers/backend/customers/deals/map/components/DealsMapCanvas.js.map +7 -0
- package/dist/modules/customers/backend/customers/deals/map/components/DealsMapCanvasImpl.js +321 -0
- package/dist/modules/customers/backend/customers/deals/map/components/DealsMapCanvasImpl.js.map +7 -0
- package/dist/modules/customers/backend/customers/deals/map/components/DealsMapView.js +533 -0
- package/dist/modules/customers/backend/customers/deals/map/components/DealsMapView.js.map +7 -0
- package/dist/modules/customers/backend/customers/deals/map/page.js +55 -0
- package/dist/modules/customers/backend/customers/deals/map/page.js.map +7 -0
- package/dist/modules/customers/backend/customers/deals/map/page.meta.js +38 -0
- package/dist/modules/customers/backend/customers/deals/map/page.meta.js.map +7 -0
- package/dist/modules/customers/backend/customers/deals/pipeline/components/DealCard.js +38 -47
- package/dist/modules/customers/backend/customers/deals/pipeline/components/DealCard.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/pipeline/components/FilterBarRow.js +3 -3
- package/dist/modules/customers/backend/customers/deals/pipeline/components/FilterBarRow.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/pipeline/components/ViewTabsRow.js +22 -1
- package/dist/modules/customers/backend/customers/deals/pipeline/components/ViewTabsRow.js.map +2 -2
- package/dist/modules/customers/backend/customers/people/create/page.js +2 -0
- package/dist/modules/customers/backend/customers/people/create/page.js.map +2 -2
- package/dist/modules/customers/components/AddressEditor.js +34 -2
- package/dist/modules/customers/components/AddressEditor.js.map +2 -2
- package/dist/modules/customers/components/AddressTiles.js +43 -3
- package/dist/modules/customers/components/AddressTiles.js.map +2 -2
- package/dist/modules/customers/components/detail/AddressesSection.js +4 -1
- package/dist/modules/customers/components/detail/AddressesSection.js.map +2 -2
- package/dist/modules/customers/components/formConfig.js +10 -0
- package/dist/modules/customers/components/formConfig.js.map +2 -2
- package/dist/modules/customers/data/validators.js +3 -2
- package/dist/modules/customers/data/validators.js.map +2 -2
- package/dist/modules/customers/lib/dealsMapLocation.js +75 -0
- package/dist/modules/customers/lib/dealsMapLocation.js.map +7 -0
- package/package.json +11 -7
- package/src/modules/customers/api/deals/map/route.ts +549 -0
- package/src/modules/customers/backend/customers/companies/create/page.tsx +2 -0
- package/src/modules/customers/backend/customers/deals/map/components/DealsLocationPanel.tsx +213 -0
- package/src/modules/customers/backend/customers/deals/map/components/DealsMapCanvas.tsx +79 -0
- package/src/modules/customers/backend/customers/deals/map/components/DealsMapCanvasImpl.tsx +407 -0
- package/src/modules/customers/backend/customers/deals/map/components/DealsMapView.tsx +667 -0
- package/src/modules/customers/backend/customers/deals/map/page.meta.ts +36 -0
- package/src/modules/customers/backend/customers/deals/map/page.tsx +77 -0
- package/src/modules/customers/backend/customers/deals/pipeline/components/DealCard.tsx +57 -42
- package/src/modules/customers/backend/customers/deals/pipeline/components/FilterBarRow.tsx +3 -3
- package/src/modules/customers/backend/customers/deals/pipeline/components/ViewTabsRow.tsx +22 -1
- package/src/modules/customers/backend/customers/people/create/page.tsx +2 -0
- package/src/modules/customers/components/AddressEditor.tsx +35 -0
- package/src/modules/customers/components/AddressTiles.tsx +51 -1
- package/src/modules/customers/components/detail/AddressesSection.tsx +3 -0
- package/src/modules/customers/components/formConfig.tsx +10 -0
- package/src/modules/customers/data/validators.ts +13 -2
- package/src/modules/customers/i18n/de.json +24 -0
- package/src/modules/customers/i18n/en.json +24 -0
- package/src/modules/customers/i18n/es.json +24 -0
- package/src/modules/customers/i18n/pl.json +24 -0
- package/src/modules/customers/lib/dealsMapLocation.ts +125 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import Link from 'next/link'
|
|
5
|
+
import { Page, PageBody } from '@open-mercato/ui/backend/Page'
|
|
6
|
+
import {
|
|
7
|
+
Breadcrumb,
|
|
8
|
+
BreadcrumbItem,
|
|
9
|
+
BreadcrumbLink,
|
|
10
|
+
BreadcrumbList,
|
|
11
|
+
BreadcrumbPage,
|
|
12
|
+
BreadcrumbSeparator,
|
|
13
|
+
} from '@open-mercato/ui/primitives/breadcrumb'
|
|
14
|
+
import { SearchInput } from '@open-mercato/ui/primitives/search-input'
|
|
15
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
16
|
+
import { translateWithFallback } from '@open-mercato/shared/lib/i18n/translate'
|
|
17
|
+
import { ViewTabsRow } from '../pipeline/components/ViewTabsRow'
|
|
18
|
+
import { DealsMapView } from './components/DealsMapView'
|
|
19
|
+
|
|
20
|
+
export default function DealsMapPage(): React.ReactElement {
|
|
21
|
+
const t = useT()
|
|
22
|
+
const [search, setSearch] = React.useState('')
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Page>
|
|
26
|
+
<PageBody>
|
|
27
|
+
<div className="flex flex-col gap-2">
|
|
28
|
+
<Breadcrumb>
|
|
29
|
+
<BreadcrumbList>
|
|
30
|
+
<BreadcrumbItem>
|
|
31
|
+
<BreadcrumbLink asChild>
|
|
32
|
+
<Link href="/backend">
|
|
33
|
+
{translateWithFallback(t, 'customers.deals.kanban.breadcrumb.dashboard', 'Dashboard')}
|
|
34
|
+
</Link>
|
|
35
|
+
</BreadcrumbLink>
|
|
36
|
+
</BreadcrumbItem>
|
|
37
|
+
<BreadcrumbSeparator />
|
|
38
|
+
<BreadcrumbItem>
|
|
39
|
+
<BreadcrumbLink asChild>
|
|
40
|
+
<Link href="/backend/customers/deals">
|
|
41
|
+
{translateWithFallback(t, 'customers.deals.kanban.breadcrumb.deals', 'Deals')}
|
|
42
|
+
</Link>
|
|
43
|
+
</BreadcrumbLink>
|
|
44
|
+
</BreadcrumbItem>
|
|
45
|
+
<BreadcrumbSeparator />
|
|
46
|
+
<BreadcrumbItem>
|
|
47
|
+
<BreadcrumbPage>
|
|
48
|
+
{translateWithFallback(t, 'customers.nav.deals.map', 'Deals Map')}
|
|
49
|
+
</BreadcrumbPage>
|
|
50
|
+
</BreadcrumbItem>
|
|
51
|
+
</BreadcrumbList>
|
|
52
|
+
</Breadcrumb>
|
|
53
|
+
|
|
54
|
+
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
|
55
|
+
<h1 className="text-xl font-semibold leading-tight text-foreground sm:text-2xl">
|
|
56
|
+
{translateWithFallback(t, 'customers.nav.deals.map', 'Deals Map')}
|
|
57
|
+
</h1>
|
|
58
|
+
<SearchInput
|
|
59
|
+
value={search}
|
|
60
|
+
onChange={setSearch}
|
|
61
|
+
placeholder={translateWithFallback(
|
|
62
|
+
t,
|
|
63
|
+
'customers.deals.kanban.search.placeholder',
|
|
64
|
+
'Search deals…',
|
|
65
|
+
)}
|
|
66
|
+
className="w-64"
|
|
67
|
+
/>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<ViewTabsRow active="map" className="mt-4" />
|
|
72
|
+
|
|
73
|
+
<DealsMapView search={search} />
|
|
74
|
+
</PageBody>
|
|
75
|
+
</Page>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
@@ -4,8 +4,9 @@ import * as React from 'react'
|
|
|
4
4
|
import { useDraggable } from '@dnd-kit/core'
|
|
5
5
|
import { AlertTriangle, Building2, Calendar, Clock, Mail, Phone, StickyNote } from 'lucide-react'
|
|
6
6
|
import { Avatar } from '@open-mercato/ui/primitives/avatar'
|
|
7
|
-
import { Button } from '@open-mercato/ui/primitives/button'
|
|
8
7
|
import { Checkbox } from '@open-mercato/ui/primitives/checkbox'
|
|
8
|
+
import { IconButton } from '@open-mercato/ui/primitives/icon-button'
|
|
9
|
+
import { SimpleTooltip } from '@open-mercato/ui/primitives/tooltip'
|
|
9
10
|
import type { RowActionItem } from '@open-mercato/ui/backend/RowActions'
|
|
10
11
|
import { DealCardMenu } from './DealCardMenu'
|
|
11
12
|
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
@@ -369,62 +370,76 @@ function DealCardImpl({
|
|
|
369
370
|
// is what restores drag-and-drop. Without it the (invisible) Call/Email/Note row sits in
|
|
370
371
|
// the middle of the card and intercepts every pointer-down, so dnd-kit never gets the
|
|
371
372
|
// gesture and the card snaps back to the source lane.
|
|
372
|
-
className="flex items-center gap-
|
|
373
|
+
className="flex items-center justify-center gap-2 opacity-0 pointer-events-none transition-opacity group-hover:opacity-100 group-hover:pointer-events-auto focus-within:opacity-100 focus-within:pointer-events-auto [@media(hover:none)]:opacity-100 [@media(hover:none)]:pointer-events-auto"
|
|
373
374
|
onClick={(event) => event.stopPropagation()}
|
|
374
375
|
onPointerDown={stopPointerDown}
|
|
375
376
|
>
|
|
376
377
|
{(() => {
|
|
377
378
|
const disabled = !deal.primaryCompany
|
|
378
|
-
const
|
|
379
|
+
const disabledTooltip = disabled
|
|
379
380
|
? translateWithFallback(
|
|
380
381
|
t,
|
|
381
382
|
'customers.deals.kanban.card.action.disabledNoCompany',
|
|
382
383
|
'Link a company to this deal before logging activities.',
|
|
383
384
|
)
|
|
384
385
|
: undefined
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
type="button"
|
|
393
|
-
onClick={handleActionClick('call')}
|
|
394
|
-
disabled={disabled}
|
|
395
|
-
title={disabledTitle}
|
|
396
|
-
aria-disabled={disabled || undefined}
|
|
397
|
-
className={baseClass}
|
|
398
|
-
>
|
|
399
|
-
<Phone className="size-3.5 shrink-0" aria-hidden="true" />
|
|
400
|
-
<span>{translateWithFallback(t, 'customers.deals.kanban.card.action.call', 'Call')}</span>
|
|
401
|
-
</Button>
|
|
402
|
-
<Button
|
|
403
|
-
variant="ghost"
|
|
404
|
-
size="sm"
|
|
405
|
-
type="button"
|
|
406
|
-
onClick={handleActionClick('email')}
|
|
407
|
-
disabled={disabled}
|
|
408
|
-
title={disabledTitle}
|
|
409
|
-
aria-disabled={disabled || undefined}
|
|
410
|
-
className={baseClass}
|
|
411
|
-
>
|
|
412
|
-
<Mail className="size-3.5 shrink-0" aria-hidden="true" />
|
|
413
|
-
<span>{translateWithFallback(t, 'customers.deals.kanban.card.action.email', 'Email')}</span>
|
|
414
|
-
</Button>
|
|
415
|
-
<Button
|
|
386
|
+
const renderActionButton = (
|
|
387
|
+
type: 'call' | 'email' | 'note',
|
|
388
|
+
label: string,
|
|
389
|
+
icon: React.ReactNode,
|
|
390
|
+
) => {
|
|
391
|
+
const button = (
|
|
392
|
+
<IconButton
|
|
416
393
|
variant="ghost"
|
|
417
|
-
size="
|
|
418
|
-
type
|
|
419
|
-
onClick={handleActionClick('note')}
|
|
394
|
+
size="default"
|
|
395
|
+
onClick={handleActionClick(type)}
|
|
420
396
|
disabled={disabled}
|
|
421
|
-
title={disabledTitle}
|
|
422
397
|
aria-disabled={disabled || undefined}
|
|
423
|
-
|
|
398
|
+
aria-label={label}
|
|
399
|
+
className="shrink-0 text-muted-foreground hover:text-foreground"
|
|
424
400
|
>
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
401
|
+
{icon}
|
|
402
|
+
</IconButton>
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
if (!disabled) {
|
|
406
|
+
return (
|
|
407
|
+
<SimpleTooltip key={type} content={label} size="sm">
|
|
408
|
+
{button}
|
|
409
|
+
</SimpleTooltip>
|
|
410
|
+
)
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return (
|
|
414
|
+
<SimpleTooltip key={type} content={disabledTooltip} size="sm">
|
|
415
|
+
<span
|
|
416
|
+
className="inline-flex shrink-0 rounded-md focus-visible:outline-none focus-visible:shadow-focus"
|
|
417
|
+
tabIndex={0}
|
|
418
|
+
aria-label={`${label}: ${disabledTooltip}`}
|
|
419
|
+
>
|
|
420
|
+
{button}
|
|
421
|
+
</span>
|
|
422
|
+
</SimpleTooltip>
|
|
423
|
+
)
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return (
|
|
427
|
+
<>
|
|
428
|
+
{renderActionButton(
|
|
429
|
+
'call',
|
|
430
|
+
translateWithFallback(t, 'customers.deals.kanban.card.action.call', 'Call'),
|
|
431
|
+
<Phone className="size-5" aria-hidden="true" />,
|
|
432
|
+
)}
|
|
433
|
+
{renderActionButton(
|
|
434
|
+
'email',
|
|
435
|
+
translateWithFallback(t, 'customers.deals.kanban.card.action.email', 'Email'),
|
|
436
|
+
<Mail className="size-5" aria-hidden="true" />,
|
|
437
|
+
)}
|
|
438
|
+
{renderActionButton(
|
|
439
|
+
'note',
|
|
440
|
+
translateWithFallback(t, 'customers.deals.kanban.card.action.note', 'Note'),
|
|
441
|
+
<StickyNote className="size-5" aria-hidden="true" />,
|
|
442
|
+
)}
|
|
428
443
|
</>
|
|
429
444
|
)
|
|
430
445
|
})()}
|
|
@@ -33,9 +33,9 @@ export function FilterBarRow({
|
|
|
33
33
|
// That picker is not wired up in this slice (it would need AdvancedFilterPanel integration),
|
|
34
34
|
// so the affordance is intentionally omitted instead of shipping a "coming next" toast.
|
|
35
35
|
return (
|
|
36
|
-
<div className="flex flex-
|
|
36
|
+
<div className="flex flex-col gap-2 rounded-lg bg-muted/40 px-3.5 py-3 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between sm:gap-y-2">
|
|
37
37
|
<div className="flex flex-wrap items-center gap-2">
|
|
38
|
-
<span className="text-overline font-bold uppercase leading-normal text-muted-foreground">
|
|
38
|
+
<span className="text-overline w-full font-bold uppercase leading-normal text-muted-foreground sm:w-auto">
|
|
39
39
|
{translateWithFallback(t, 'customers.deals.kanban.filter.label', 'Filter')}:
|
|
40
40
|
</span>
|
|
41
41
|
{leadingChips}
|
|
@@ -54,7 +54,7 @@ export function FilterBarRow({
|
|
|
54
54
|
/>
|
|
55
55
|
))}
|
|
56
56
|
</div>
|
|
57
|
-
<div className="ml-auto">{sortNode}</div>
|
|
57
|
+
<div className="sm:ml-auto">{sortNode}</div>
|
|
58
58
|
</div>
|
|
59
59
|
)
|
|
60
60
|
}
|
|
@@ -5,7 +5,7 @@ import Link from 'next/link'
|
|
|
5
5
|
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
6
6
|
import { translateWithFallback } from '@open-mercato/shared/lib/i18n/translate'
|
|
7
7
|
|
|
8
|
-
export type KanbanView = 'kanban' | 'list'
|
|
8
|
+
export type KanbanView = 'kanban' | 'list' | 'map'
|
|
9
9
|
|
|
10
10
|
type ViewTabsRowProps = {
|
|
11
11
|
active: KanbanView
|
|
@@ -14,12 +14,14 @@ type ViewTabsRowProps = {
|
|
|
14
14
|
|
|
15
15
|
const VIEW_KANBAN_HREF = '/backend/customers/deals/pipeline'
|
|
16
16
|
const VIEW_LIST_HREF = '/backend/customers/deals'
|
|
17
|
+
const VIEW_MAP_HREF = '/backend/customers/deals/map'
|
|
17
18
|
|
|
18
19
|
export function ViewTabsRow({ active, className }: ViewTabsRowProps): React.ReactElement {
|
|
19
20
|
const t = useT()
|
|
20
21
|
const labels = {
|
|
21
22
|
kanban: translateWithFallback(t, 'customers.deals.kanban.view.kanban', 'Kanban'),
|
|
22
23
|
list: translateWithFallback(t, 'customers.deals.kanban.view.list', 'List'),
|
|
24
|
+
map: translateWithFallback(t, 'customers.deals.kanban.view.map', 'Map'),
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
const baseTab =
|
|
@@ -34,6 +36,7 @@ export function ViewTabsRow({ active, className }: ViewTabsRowProps): React.Reac
|
|
|
34
36
|
// navigate back to /pipeline.
|
|
35
37
|
const isKanbanActive = active === 'kanban'
|
|
36
38
|
const isListActive = active === 'list'
|
|
39
|
+
const isMapActive = active === 'map'
|
|
37
40
|
|
|
38
41
|
return (
|
|
39
42
|
<div
|
|
@@ -77,6 +80,24 @@ export function ViewTabsRow({ active, className }: ViewTabsRowProps): React.Reac
|
|
|
77
80
|
{labels.list}
|
|
78
81
|
</Link>
|
|
79
82
|
)}
|
|
83
|
+
{isMapActive ? (
|
|
84
|
+
<span
|
|
85
|
+
role="tab"
|
|
86
|
+
aria-selected={true}
|
|
87
|
+
className={`${baseTab} ${activeTab}`}
|
|
88
|
+
>
|
|
89
|
+
{labels.map}
|
|
90
|
+
</span>
|
|
91
|
+
) : (
|
|
92
|
+
<Link
|
|
93
|
+
href={VIEW_MAP_HREF}
|
|
94
|
+
role="tab"
|
|
95
|
+
aria-selected={false}
|
|
96
|
+
className={`${baseTab} ${inactiveTab}`}
|
|
97
|
+
>
|
|
98
|
+
{labels.map}
|
|
99
|
+
</Link>
|
|
100
|
+
)}
|
|
80
101
|
</div>
|
|
81
102
|
)
|
|
82
103
|
}
|
|
@@ -110,6 +110,8 @@ export default function CreatePersonPage() {
|
|
|
110
110
|
if (postalCode !== undefined) body.postalCode = postalCode
|
|
111
111
|
const country = normalize(entry.country)
|
|
112
112
|
if (country !== undefined) body.country = country.toUpperCase()
|
|
113
|
+
if (typeof entry.latitude === 'number') body.latitude = entry.latitude
|
|
114
|
+
if (typeof entry.longitude === 'number') body.longitude = entry.longitude
|
|
113
115
|
try {
|
|
114
116
|
await createCrud('customers/addresses', body)
|
|
115
117
|
} catch (addressErr) {
|
|
@@ -41,6 +41,8 @@ export type AddressEditorDraft = {
|
|
|
41
41
|
region: string
|
|
42
42
|
postalCode: string
|
|
43
43
|
country: string
|
|
44
|
+
latitude?: string
|
|
45
|
+
longitude?: string
|
|
44
46
|
isPrimary: boolean
|
|
45
47
|
}
|
|
46
48
|
|
|
@@ -56,6 +58,8 @@ export type AddressEditorField =
|
|
|
56
58
|
| 'region'
|
|
57
59
|
| 'postalCode'
|
|
58
60
|
| 'country'
|
|
61
|
+
| 'latitude'
|
|
62
|
+
| 'longitude'
|
|
59
63
|
| 'isPrimary'
|
|
60
64
|
|
|
61
65
|
type AddressEditorProps = {
|
|
@@ -67,6 +71,7 @@ type AddressEditorProps = {
|
|
|
67
71
|
errors?: Partial<Record<AddressEditorField, string>>
|
|
68
72
|
hidePrimaryToggle?: boolean
|
|
69
73
|
showFormatHint?: boolean
|
|
74
|
+
showCoordinateFields?: boolean
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
export function AddressEditor({
|
|
@@ -78,6 +83,7 @@ export function AddressEditor({
|
|
|
78
83
|
errors = {},
|
|
79
84
|
hidePrimaryToggle = false,
|
|
80
85
|
showFormatHint = true,
|
|
86
|
+
showCoordinateFields = false,
|
|
81
87
|
}: AddressEditorProps) {
|
|
82
88
|
const pathname = usePathname()
|
|
83
89
|
const searchParams = useSearchParams()
|
|
@@ -108,6 +114,9 @@ export function AddressEditor({
|
|
|
108
114
|
region: value.region ?? '',
|
|
109
115
|
postalCode: value.postalCode ?? '',
|
|
110
116
|
country: value.country ?? '',
|
|
117
|
+
...(showCoordinateFields
|
|
118
|
+
? { latitude: value.latitude ?? '', longitude: value.longitude ?? '' }
|
|
119
|
+
: {}),
|
|
111
120
|
isPrimary: value.isPrimary ?? false,
|
|
112
121
|
}
|
|
113
122
|
|
|
@@ -437,6 +446,32 @@ export function AddressEditor({
|
|
|
437
446
|
</DialogContent>
|
|
438
447
|
</Dialog>
|
|
439
448
|
{errors.country ? <p className="text-xs text-destructive">{errors.country}</p> : null}
|
|
449
|
+
{showCoordinateFields ? (
|
|
450
|
+
<>
|
|
451
|
+
<Input
|
|
452
|
+
className={inputClass('latitude')}
|
|
453
|
+
placeholder={t('customers.people.detail.addresses.fields.latitude', 'Latitude')}
|
|
454
|
+
aria-label={t('customers.people.detail.addresses.fields.latitude', 'Latitude')}
|
|
455
|
+
inputMode="decimal"
|
|
456
|
+
value={current.latitude ?? ''}
|
|
457
|
+
onChange={(evt) => update('latitude', evt.target.value)}
|
|
458
|
+
disabled={disabled}
|
|
459
|
+
aria-invalid={errors.latitude ? 'true' : undefined}
|
|
460
|
+
/>
|
|
461
|
+
{errors.latitude ? <p className="text-xs text-destructive">{errors.latitude}</p> : null}
|
|
462
|
+
<Input
|
|
463
|
+
className={inputClass('longitude')}
|
|
464
|
+
placeholder={t('customers.people.detail.addresses.fields.longitude', 'Longitude')}
|
|
465
|
+
aria-label={t('customers.people.detail.addresses.fields.longitude', 'Longitude')}
|
|
466
|
+
inputMode="decimal"
|
|
467
|
+
value={current.longitude ?? ''}
|
|
468
|
+
onChange={(evt) => update('longitude', evt.target.value)}
|
|
469
|
+
disabled={disabled}
|
|
470
|
+
aria-invalid={errors.longitude ? 'true' : undefined}
|
|
471
|
+
/>
|
|
472
|
+
{errors.longitude ? <p className="text-xs text-destructive">{errors.longitude}</p> : null}
|
|
473
|
+
</>
|
|
474
|
+
) : null}
|
|
440
475
|
</div>
|
|
441
476
|
{!hidePrimaryToggle ? (
|
|
442
477
|
<label className="inline-flex items-center gap-2 text-sm">
|
|
@@ -8,6 +8,7 @@ import { TabEmptyState } from '@open-mercato/ui/backend/detail'
|
|
|
8
8
|
import { apiCall } from '@open-mercato/ui/backend/utils/apiCall'
|
|
9
9
|
import { useOrganizationScopeVersion } from '@open-mercato/shared/lib/frontend/useOrganizationScope'
|
|
10
10
|
import { AddressView, formatAddressJson, formatAddressString, type AddressFormatStrategy } from '../utils/addressFormat'
|
|
11
|
+
import { normalizeCoordinateInput, validateCoordinateInput } from '@open-mercato/shared/lib/location/coordinates'
|
|
11
12
|
import AddressEditor from './AddressEditor'
|
|
12
13
|
import { useAddressTypes } from './detail/hooks/useAddressTypes'
|
|
13
14
|
import {
|
|
@@ -40,6 +41,8 @@ export type CustomerAddressInput = {
|
|
|
40
41
|
region?: string
|
|
41
42
|
postalCode?: string
|
|
42
43
|
country?: string
|
|
44
|
+
latitude?: number | null
|
|
45
|
+
longitude?: number | null
|
|
43
46
|
isPrimary?: boolean
|
|
44
47
|
}
|
|
45
48
|
|
|
@@ -47,6 +50,8 @@ export type CustomerAddressValue = CustomerAddressInput & {
|
|
|
47
50
|
id: string
|
|
48
51
|
purpose?: string | null
|
|
49
52
|
companyName?: string | null
|
|
53
|
+
latitude?: number | null
|
|
54
|
+
longitude?: number | null
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
type CustomerAddressTilesProps = {
|
|
@@ -62,6 +67,7 @@ type CustomerAddressTilesProps = {
|
|
|
62
67
|
onAddActionChange?: (action: { openCreateForm: () => void; addDisabled: boolean } | null) => void
|
|
63
68
|
emptyStateTitle?: string
|
|
64
69
|
emptyStateActionLabel?: string
|
|
70
|
+
showCoordinateFields?: boolean
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
type DraftAddressState = {
|
|
@@ -76,6 +82,8 @@ type DraftAddressState = {
|
|
|
76
82
|
region: string
|
|
77
83
|
postalCode: string
|
|
78
84
|
country: string
|
|
85
|
+
latitude: string
|
|
86
|
+
longitude: string
|
|
79
87
|
isPrimary: boolean
|
|
80
88
|
}
|
|
81
89
|
|
|
@@ -102,6 +110,8 @@ const defaultDraft: DraftAddressState = {
|
|
|
102
110
|
region: '',
|
|
103
111
|
postalCode: '',
|
|
104
112
|
country: '',
|
|
113
|
+
latitude: '',
|
|
114
|
+
longitude: '',
|
|
105
115
|
isPrimary: false,
|
|
106
116
|
}
|
|
107
117
|
|
|
@@ -117,6 +127,8 @@ const serverFieldMap: Record<string, DraftFieldKey> = {
|
|
|
117
127
|
region: 'region',
|
|
118
128
|
postalCode: 'postalCode',
|
|
119
129
|
country: 'country',
|
|
130
|
+
latitude: 'latitude',
|
|
131
|
+
longitude: 'longitude',
|
|
120
132
|
isPrimary: 'isPrimary',
|
|
121
133
|
}
|
|
122
134
|
|
|
@@ -173,6 +185,7 @@ export function CustomerAddressTiles({
|
|
|
173
185
|
onAddActionChange,
|
|
174
186
|
emptyStateTitle,
|
|
175
187
|
emptyStateActionLabel,
|
|
188
|
+
showCoordinateFields = false,
|
|
176
189
|
}: CustomerAddressTilesProps) {
|
|
177
190
|
const scopeVersion = useOrganizationScopeVersion()
|
|
178
191
|
const queryClient = useQueryClient()
|
|
@@ -201,6 +214,8 @@ export function CustomerAddressTiles({
|
|
|
201
214
|
region: t('customers.people.detail.addresses.fields.region'),
|
|
202
215
|
postalCode: t('customers.people.detail.addresses.fields.postalCode'),
|
|
203
216
|
country: t('customers.people.detail.addresses.fields.country'),
|
|
217
|
+
latitude: t('customers.people.detail.addresses.fields.latitude', 'Latitude'),
|
|
218
|
+
longitude: t('customers.people.detail.addresses.fields.longitude', 'Longitude'),
|
|
204
219
|
isPrimary: t('customers.people.detail.addresses.fields.primary'),
|
|
205
220
|
}),
|
|
206
221
|
[t]
|
|
@@ -281,6 +296,8 @@ export function CustomerAddressTiles({
|
|
|
281
296
|
region: address.region ?? '',
|
|
282
297
|
postalCode: address.postalCode ?? '',
|
|
283
298
|
country: address.country ? address.country.toUpperCase() : '',
|
|
299
|
+
latitude: address.latitude != null ? String(address.latitude) : '',
|
|
300
|
+
longitude: address.longitude != null ? String(address.longitude) : '',
|
|
284
301
|
isPrimary: address.isPrimary ?? false,
|
|
285
302
|
})
|
|
286
303
|
setFieldErrors({})
|
|
@@ -309,6 +326,29 @@ export function CustomerAddressTiles({
|
|
|
309
326
|
return
|
|
310
327
|
}
|
|
311
328
|
|
|
329
|
+
const coordinateErrors: Partial<Record<DraftFieldKey, string>> = {}
|
|
330
|
+
for (const key of ['latitude', 'longitude'] as const) {
|
|
331
|
+
const result = validateCoordinateInput(key, draft[key])
|
|
332
|
+
if (result.status === 'invalid') {
|
|
333
|
+
coordinateErrors[key] = t(
|
|
334
|
+
'customers.people.detail.addresses.validation.invalid',
|
|
335
|
+
undefined,
|
|
336
|
+
{ field: fieldLabels[key] }
|
|
337
|
+
)
|
|
338
|
+
} else if (result.status === 'outOfRange') {
|
|
339
|
+
coordinateErrors[key] = t(
|
|
340
|
+
'customers.people.detail.addresses.validation.coordinateRange',
|
|
341
|
+
undefined,
|
|
342
|
+
{ field: fieldLabels[key], min: result.min, max: result.max }
|
|
343
|
+
)
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (Object.keys(coordinateErrors).length) {
|
|
347
|
+
setFieldErrors((prev) => ({ ...prev, ...coordinateErrors }))
|
|
348
|
+
setGeneralError(Object.values(coordinateErrors)[0] ?? null)
|
|
349
|
+
return
|
|
350
|
+
}
|
|
351
|
+
|
|
312
352
|
const payload: CustomerAddressInput = {
|
|
313
353
|
addressLine1: trimmedLine1,
|
|
314
354
|
isPrimary: draft.isPrimary,
|
|
@@ -334,6 +374,14 @@ export function CustomerAddressTiles({
|
|
|
334
374
|
if (postal !== undefined) payload.postalCode = postal
|
|
335
375
|
const country = normalizeOptional(draft.country)
|
|
336
376
|
if (country !== undefined) payload.country = country.toUpperCase()
|
|
377
|
+
// On edit, an emptied coordinate must be sent as `null` to clear the stored value; omitting it
|
|
378
|
+
// makes the partial-update handler keep the old coordinate. On create there is nothing to clear.
|
|
379
|
+
const latitude = normalizeCoordinateInput(draft.latitude)
|
|
380
|
+
if (latitude !== undefined) payload.latitude = latitude
|
|
381
|
+
else if (editingId) payload.latitude = null
|
|
382
|
+
const longitude = normalizeCoordinateInput(draft.longitude)
|
|
383
|
+
if (longitude !== undefined) payload.longitude = longitude
|
|
384
|
+
else if (editingId) payload.longitude = null
|
|
337
385
|
|
|
338
386
|
setSaving(true)
|
|
339
387
|
setGeneralError(null)
|
|
@@ -450,7 +498,7 @@ export function CustomerAddressTiles({
|
|
|
450
498
|
<AddressEditor
|
|
451
499
|
value={draft}
|
|
452
500
|
onChange={(next) => {
|
|
453
|
-
setDraft(next)
|
|
501
|
+
setDraft({ ...next, latitude: next.latitude ?? '', longitude: next.longitude ?? '' })
|
|
454
502
|
if (Object.keys(fieldErrors).length) {
|
|
455
503
|
const nextErrors = { ...fieldErrors }
|
|
456
504
|
;(Object.keys(nextErrors) as DraftFieldKey[]).forEach((key) => {
|
|
@@ -467,6 +515,7 @@ export function CustomerAddressTiles({
|
|
|
467
515
|
disabled={disableActions}
|
|
468
516
|
errors={fieldErrors}
|
|
469
517
|
showFormatHint={!formatLoading}
|
|
518
|
+
showCoordinateFields={showCoordinateFields}
|
|
470
519
|
/>
|
|
471
520
|
{generalError ? <p className="text-xs text-status-error-text">{generalError}</p> : null}
|
|
472
521
|
<div className="flex flex-wrap justify-end gap-2">
|
|
@@ -502,6 +551,7 @@ export function CustomerAddressTiles({
|
|
|
502
551
|
handleSave,
|
|
503
552
|
generalError,
|
|
504
553
|
saving,
|
|
554
|
+
showCoordinateFields,
|
|
505
555
|
t,
|
|
506
556
|
]
|
|
507
557
|
)
|
|
@@ -95,6 +95,8 @@ export function AddressesSection({
|
|
|
95
95
|
? record.postalCode
|
|
96
96
|
: null,
|
|
97
97
|
country: typeof record.country === 'string' ? record.country : null,
|
|
98
|
+
latitude: typeof record.latitude === 'number' && Number.isFinite(record.latitude) ? record.latitude : null,
|
|
99
|
+
longitude: typeof record.longitude === 'number' && Number.isFinite(record.longitude) ? record.longitude : null,
|
|
98
100
|
isPrimary:
|
|
99
101
|
typeof record.is_primary === 'boolean'
|
|
100
102
|
? record.is_primary
|
|
@@ -242,6 +244,7 @@ export function AddressesSection({
|
|
|
242
244
|
dataAdapter={dataAdapter}
|
|
243
245
|
addressTypesAdapter={addressTypesAdapter}
|
|
244
246
|
loadFormat={loadFormat}
|
|
247
|
+
showCoordinateFields
|
|
245
248
|
/>
|
|
246
249
|
)
|
|
247
250
|
}
|
|
@@ -955,6 +955,7 @@ export const createPersonFormFields = (t: Translator): CrudField[] => {
|
|
|
955
955
|
t={t}
|
|
956
956
|
emptyLabel={t('customers.people.detail.empty.addresses')}
|
|
957
957
|
gridClassName="grid gap-4 min-[480px]:grid-cols-1 xl:grid-cols-2"
|
|
958
|
+
showCoordinateFields
|
|
958
959
|
onCreate={async (payload: CustomerAddressInput) => {
|
|
959
960
|
const nextId =
|
|
960
961
|
typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function'
|
|
@@ -973,6 +974,8 @@ export const createPersonFormFields = (t: Translator): CrudField[] => {
|
|
|
973
974
|
region: payload.region ?? undefined,
|
|
974
975
|
postalCode: payload.postalCode ?? undefined,
|
|
975
976
|
country: payload.country ?? undefined,
|
|
977
|
+
latitude: payload.latitude ?? undefined,
|
|
978
|
+
longitude: payload.longitude ?? undefined,
|
|
976
979
|
isPrimary: payload.isPrimary ?? false,
|
|
977
980
|
}
|
|
978
981
|
const current = Array.isArray(addresses) ? addresses : []
|
|
@@ -1001,6 +1004,8 @@ export const createPersonFormFields = (t: Translator): CrudField[] => {
|
|
|
1001
1004
|
region: payload.region ?? null,
|
|
1002
1005
|
postalCode: payload.postalCode ?? null,
|
|
1003
1006
|
country: payload.country ?? null,
|
|
1007
|
+
latitude: payload.latitude ?? null,
|
|
1008
|
+
longitude: payload.longitude ?? null,
|
|
1004
1009
|
isPrimary: payload.isPrimary ?? false,
|
|
1005
1010
|
}
|
|
1006
1011
|
})
|
|
@@ -1316,6 +1321,7 @@ export const createCompanyFormFields = (t: Translator): CrudField[] => {
|
|
|
1316
1321
|
t={t}
|
|
1317
1322
|
emptyLabel={t('customers.companies.detail.empty.addresses')}
|
|
1318
1323
|
gridClassName="grid gap-4 min-[480px]:grid-cols-1 xl:grid-cols-2"
|
|
1324
|
+
showCoordinateFields
|
|
1319
1325
|
onCreate={async (payload: CustomerAddressInput) => {
|
|
1320
1326
|
const nextId =
|
|
1321
1327
|
typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function'
|
|
@@ -1334,6 +1340,8 @@ export const createCompanyFormFields = (t: Translator): CrudField[] => {
|
|
|
1334
1340
|
region: payload.region ?? undefined,
|
|
1335
1341
|
postalCode: payload.postalCode ?? undefined,
|
|
1336
1342
|
country: payload.country ?? undefined,
|
|
1343
|
+
latitude: payload.latitude ?? undefined,
|
|
1344
|
+
longitude: payload.longitude ?? undefined,
|
|
1337
1345
|
isPrimary: payload.isPrimary ?? false,
|
|
1338
1346
|
}
|
|
1339
1347
|
const current = Array.isArray(addresses) ? addresses : []
|
|
@@ -1362,6 +1370,8 @@ export const createCompanyFormFields = (t: Translator): CrudField[] => {
|
|
|
1362
1370
|
region: payload.region ?? null,
|
|
1363
1371
|
postalCode: payload.postalCode ?? null,
|
|
1364
1372
|
country: payload.country ?? null,
|
|
1373
|
+
latitude: payload.latitude ?? null,
|
|
1374
|
+
longitude: payload.longitude ?? null,
|
|
1365
1375
|
isPrimary: payload.isPrimary ?? false,
|
|
1366
1376
|
}
|
|
1367
1377
|
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
import { isValidPhoneNumber } from '@open-mercato/shared/lib/phone'
|
|
3
|
+
import { COORDINATE_RANGES } from '@open-mercato/shared/lib/location/coordinates'
|
|
3
4
|
import { dictionaryEntrySortModeSchema } from '@open-mercato/core/modules/dictionaries/lib/entrySort'
|
|
4
5
|
|
|
5
6
|
const uuid = () => z.string().uuid()
|
|
@@ -264,8 +265,18 @@ export const addressCreateSchema = scopedSchema.extend({
|
|
|
264
265
|
region: z.string().max(150).optional(),
|
|
265
266
|
postalCode: z.string().max(30).optional(),
|
|
266
267
|
country: z.string().max(150).optional(),
|
|
267
|
-
latitude: z.coerce
|
|
268
|
-
|
|
268
|
+
latitude: z.coerce
|
|
269
|
+
.number()
|
|
270
|
+
.min(COORDINATE_RANGES.latitude.min)
|
|
271
|
+
.max(COORDINATE_RANGES.latitude.max)
|
|
272
|
+
.nullable()
|
|
273
|
+
.optional(),
|
|
274
|
+
longitude: z.coerce
|
|
275
|
+
.number()
|
|
276
|
+
.min(COORDINATE_RANGES.longitude.min)
|
|
277
|
+
.max(COORDINATE_RANGES.longitude.max)
|
|
278
|
+
.nullable()
|
|
279
|
+
.optional(),
|
|
269
280
|
isPrimary: z.boolean().optional(),
|
|
270
281
|
})
|
|
271
282
|
|