@tuturuuu/ui 0.11.1 → 0.13.0
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/CHANGELOG.md +23 -0
- package/package.json +5 -5
- package/src/components/ui/calendar-app/components/habits-panel.tsx +5 -2
- package/src/components/ui/calendar-app/components/priority-view.tsx +15 -7
- package/src/components/ui/calendar-app/components/scheduling-dialog.tsx +7 -3
- package/src/components/ui/calendar-app/components/task-scheduler-panel.tsx +7 -3
- package/src/components/ui/calendar-app/components/time-tracker/index.tsx +14 -9
- package/src/components/ui/custom/settings/task-settings.tsx +6 -2
- package/src/components/ui/custom/tables/data-table.tsx +58 -8
- package/src/components/ui/storefront/bundle-selection-dialog.tsx +249 -0
- package/src/components/ui/storefront/cart-summary-parts.tsx +28 -8
- package/src/components/ui/storefront/listing-card.tsx +6 -3
- package/src/components/ui/storefront/storefront-surface.test.tsx +134 -1
- package/src/components/ui/storefront/storefront-surface.tsx +66 -7
- package/src/components/ui/storefront/types.ts +15 -0
- package/src/components/ui/storefront/utils.ts +164 -2
- package/src/components/ui/tu-do/boards/boardId/kanban/dnd/use-kanban-dnd.test.ts +63 -1
- package/src/components/ui/tu-do/boards/boardId/kanban/dnd/use-kanban-dnd.ts +3 -6
- package/src/components/ui/tu-do/boards/boardId/task-card/task-card-open-options.test.ts +11 -1
- package/src/components/ui/tu-do/boards/boardId/task-card/task-card-open-options.ts +7 -3
- package/src/components/ui/tu-do/boards/boardId/task-card/task-card-resource-context.test.ts +113 -0
- package/src/components/ui/tu-do/boards/boardId/task-card/task-card-resource-context.ts +50 -0
- package/src/components/ui/tu-do/boards/boardId/task-card/task-card.tsx +65 -18
- package/src/components/ui/tu-do/boards/boardId/timeline-board.tsx +1 -1
- package/src/components/ui/tu-do/cycles/task-cycles-client.tsx +23 -14
- package/src/components/ui/tu-do/estimates/use-task-estimates.ts +9 -4
- package/src/components/ui/tu-do/habits/client.tsx +4 -1
- package/src/components/ui/tu-do/my-tasks/__tests__/use-task-context-actions.test.ts +6 -3
- package/src/components/ui/tu-do/my-tasks/task-list-with-completion.tsx +19 -11
- package/src/components/ui/tu-do/my-tasks/use-my-tasks-query.ts +15 -6
- package/src/components/ui/tu-do/my-tasks/use-my-tasks-state.ts +18 -13
- package/src/components/ui/tu-do/my-tasks/use-task-context-actions.ts +17 -10
- package/src/components/ui/tu-do/shared/fade-setting-initializer.tsx +3 -1
- package/src/components/ui/tu-do/shared/list-view.tsx +1 -1
- package/src/components/ui/tu-do/shared/task-edit-dialog/components/quick-settings-popover.tsx +6 -2
- package/src/components/ui/tu-do/shared/task-edit-dialog/hooks/__tests__/use-update-shared-task.test.ts +9 -5
- package/src/components/ui/tu-do/shared/task-edit-dialog/hooks/task-api.ts +13 -8
- package/src/components/ui/tu-do/shared/task-edit-dialog/hooks/use-task-overrides.ts +21 -9
- package/src/components/ui/tu-do/shared/task-edit-dialog/hooks/use-update-shared-task.ts +10 -5
- package/src/components/ui/tu-do/shared/task-edit-dialog.tsx +4 -2
- package/src/components/ui/tu-do/shared/task-estimation-picker.tsx +5 -2
- package/src/components/ui/tu-do/shared/task-row-actions-menu.tsx +1 -1
- package/src/hooks/__tests__/use-task-actions.test.tsx +51 -0
- package/src/hooks/task-actions-personal-external.ts +2 -3
- package/src/hooks/use-board-actions.ts +27 -17
- package/src/hooks/use-calendar.tsx +7 -3
- package/src/hooks/use-settings-dialog-shortcut.ts +51 -0
- package/src/lib/task-personal-external.ts +49 -0
- package/src/lib/tasks-app-url.ts +85 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.13.0](https://github.com/tutur3u/platform/compare/ui-v0.12.0...ui-v0.13.0) (2026-07-05)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **satellite:** open settings on Cmd/Ctrl+, in satellite apps ([841f425](https://github.com/tutur3u/platform/commit/841f42557dd49eb31fd797900b1ec6ade6642dba))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **tasks:** harden satellite task route hydration ([9d51a38](https://github.com/tutur3u/platform/commit/9d51a38ad948ebb398bec794f082f2bbf8d466cc))
|
|
14
|
+
* **tasks:** keep personal board moves on workspace route ([60e29b0](https://github.com/tutur3u/platform/commit/60e29b093314b3b185f3f63a69042a665644ed3d))
|
|
15
|
+
* **tasks:** keep personal moves off placement API ([d8c41d7](https://github.com/tutur3u/platform/commit/d8c41d790f5edbe637b9ce71bbd5040b7fddbfa5))
|
|
16
|
+
* **tasks:** restore satellite resource access ([ec5e0a8](https://github.com/tutur3u/platform/commit/ec5e0a8d75398047e0151ae2ac3cd9a25a4fd675))
|
|
17
|
+
* **tasks:** route native personal task moves normally ([5bbba3c](https://github.com/tutur3u/platform/commit/5bbba3c3f193e722cc87cdfe2eb2734f61442cd0))
|
|
18
|
+
|
|
19
|
+
## [0.12.0](https://github.com/tutur3u/platform/compare/ui-v0.11.1...ui-v0.12.0) (2026-07-03)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* **inventory:** add revenue share and category bundles ([20b2e1e](https://github.com/tutur3u/platform/commit/20b2e1e5302d1db275766b7b4b92d9bdf69de04a))
|
|
25
|
+
|
|
3
26
|
## [0.11.1](https://github.com/tutur3u/platform/compare/ui-v0.11.0...ui-v0.11.1) (2026-07-02)
|
|
4
27
|
|
|
5
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuturuuu/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -85,12 +85,12 @@
|
|
|
85
85
|
"@tiptap/react": "3.27.1",
|
|
86
86
|
"@tiptap/starter-kit": "3.27.1",
|
|
87
87
|
"@tuturuuu/ai": "0.2.2",
|
|
88
|
-
"@tuturuuu/apis": "0.7.
|
|
88
|
+
"@tuturuuu/apis": "0.7.1",
|
|
89
89
|
"@tuturuuu/hooks": "0.0.2",
|
|
90
90
|
"@tuturuuu/icons": "0.0.6",
|
|
91
|
-
"@tuturuuu/internal-api": "0.
|
|
91
|
+
"@tuturuuu/internal-api": "0.14.1",
|
|
92
92
|
"@tuturuuu/supabase": "0.4.0",
|
|
93
|
-
"@tuturuuu/utils": "0.
|
|
93
|
+
"@tuturuuu/utils": "0.13.0",
|
|
94
94
|
"@types/debug": "^4.1.13",
|
|
95
95
|
"browser-image-compression": "^2.0.2",
|
|
96
96
|
"class-variance-authority": "^0.7.1",
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
"@tanstack/react-table": "^8.21.3",
|
|
150
150
|
"@testing-library/jest-dom": "^6.9.1",
|
|
151
151
|
"@testing-library/react": "^16.3.2",
|
|
152
|
-
"@tuturuuu/types": "0.
|
|
152
|
+
"@tuturuuu/types": "0.14.0",
|
|
153
153
|
"@tuturuuu/typescript-config": "0.1.1",
|
|
154
154
|
"@types/html2canvas": "^1.0.0",
|
|
155
155
|
"@types/lodash": "^4.17.24",
|
|
@@ -15,6 +15,7 @@ import { getRecurrenceDescription } from '@tuturuuu/types/primitives/Habit';
|
|
|
15
15
|
import { cn } from '@tuturuuu/utils/format';
|
|
16
16
|
import Link from 'next/link';
|
|
17
17
|
import { useState } from 'react';
|
|
18
|
+
import { getTaskApiUrl, getTasksAppUrl } from '../../../../lib/tasks-app-url';
|
|
18
19
|
import { Badge } from '../../badge';
|
|
19
20
|
import { Button } from '../../button';
|
|
20
21
|
import { Card, CardContent } from '../../card';
|
|
@@ -65,7 +66,9 @@ export function HabitsPanel({ wsId }: HabitsPanelProps) {
|
|
|
65
66
|
} = useQuery({
|
|
66
67
|
queryKey: ['habits', wsId],
|
|
67
68
|
queryFn: async () => {
|
|
68
|
-
const response = await fetch(
|
|
69
|
+
const response = await fetch(
|
|
70
|
+
getTaskApiUrl(`/api/v1/workspaces/${wsId}/habits`)
|
|
71
|
+
);
|
|
69
72
|
if (!response.ok) {
|
|
70
73
|
throw new Error('Failed to fetch habits');
|
|
71
74
|
}
|
|
@@ -308,7 +311,7 @@ export function HabitsPanel({ wsId }: HabitsPanelProps) {
|
|
|
308
311
|
|
|
309
312
|
{/* Footer */}
|
|
310
313
|
<div className="border-t p-3">
|
|
311
|
-
<Link href={`/${wsId}/
|
|
314
|
+
<Link href={getTasksAppUrl(`/${wsId}/habits`)}>
|
|
312
315
|
<Button variant="outline" size="sm" className="w-full">
|
|
313
316
|
Manage Habits
|
|
314
317
|
</Button>
|
|
@@ -32,6 +32,7 @@ import { useRouter } from 'next/navigation';
|
|
|
32
32
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
33
33
|
import { useDebouncedCallback } from 'use-debounce';
|
|
34
34
|
import { useCalendar } from '../../../../hooks/use-calendar';
|
|
35
|
+
import { getTaskApiUrl } from '../../../../lib/tasks-app-url';
|
|
35
36
|
import { Progress } from '../../progress';
|
|
36
37
|
import { toast } from '../../sonner';
|
|
37
38
|
import type { ExtendedWorkspaceTask } from '../../time-tracker/types';
|
|
@@ -263,9 +264,11 @@ export default function PriorityView({
|
|
|
263
264
|
const results = await Promise.allSettled(
|
|
264
265
|
tasksToFetchSchedule.map(async (task) => {
|
|
265
266
|
const response = await fetch(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
getTaskApiUrl(
|
|
268
|
+
isPersonalWorkspace
|
|
269
|
+
? `/api/v1/users/me/tasks/${task.id}/schedule`
|
|
270
|
+
: `/api/v1/workspaces/${task.ws_id ?? wsId}/tasks/${task.id}/schedule`
|
|
271
|
+
),
|
|
269
272
|
{ cache: 'no-store' }
|
|
270
273
|
);
|
|
271
274
|
if (!response.ok) {
|
|
@@ -378,10 +381,15 @@ export default function PriorityView({
|
|
|
378
381
|
const task = combinedTasks.find((t) => t.id === taskId);
|
|
379
382
|
const taskWsId = task?.ws_id ?? wsId;
|
|
380
383
|
|
|
381
|
-
const response = await fetch(
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
384
|
+
const response = await fetch(
|
|
385
|
+
getTaskApiUrl(`/api/${taskWsId}/task/${taskId}/edit`),
|
|
386
|
+
{
|
|
387
|
+
method: 'PATCH',
|
|
388
|
+
credentials: 'include',
|
|
389
|
+
headers: { 'Content-Type': 'application/json' },
|
|
390
|
+
body: JSON.stringify({ priority: newPriority }),
|
|
391
|
+
}
|
|
392
|
+
);
|
|
385
393
|
|
|
386
394
|
if (!response.ok) {
|
|
387
395
|
throw new Error('Failed to update task priority');
|
|
@@ -17,6 +17,7 @@ import { createClient } from '@tuturuuu/supabase/next/client';
|
|
|
17
17
|
import { cn } from '@tuturuuu/utils/format';
|
|
18
18
|
import { useRouter } from 'next/navigation';
|
|
19
19
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
20
|
+
import { getTaskApiUrl } from '../../../../lib/tasks-app-url';
|
|
20
21
|
import { Button } from '../../button';
|
|
21
22
|
import {
|
|
22
23
|
Dialog,
|
|
@@ -226,9 +227,12 @@ export function SchedulingDialog({
|
|
|
226
227
|
queryKey: ['task-personal-schedule', task?.id, open],
|
|
227
228
|
enabled: open && !!task?.id,
|
|
228
229
|
queryFn: async () => {
|
|
229
|
-
const res = await fetch(
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
const res = await fetch(
|
|
231
|
+
getTaskApiUrl(`/api/v1/users/me/tasks/${task!.id}/schedule`),
|
|
232
|
+
{
|
|
233
|
+
cache: 'no-store',
|
|
234
|
+
}
|
|
235
|
+
);
|
|
232
236
|
if (!res.ok) return null;
|
|
233
237
|
return (await res.json()) as null | {
|
|
234
238
|
task: {
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
import type { TaskWithScheduling } from '@tuturuuu/types';
|
|
16
16
|
import { cn } from '@tuturuuu/utils/format';
|
|
17
17
|
import { useState } from 'react';
|
|
18
|
+
import { getTaskApiUrl } from '../../../../lib/tasks-app-url';
|
|
18
19
|
import { Badge } from '../../badge';
|
|
19
20
|
import { Button } from '../../button';
|
|
20
21
|
import { Input } from '../../input';
|
|
@@ -147,11 +148,14 @@ export function TaskSchedulerPanel({
|
|
|
147
148
|
|
|
148
149
|
try {
|
|
149
150
|
const response = await fetch(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
getTaskApiUrl(
|
|
152
|
+
isPersonalWorkspace
|
|
153
|
+
? `/api/v1/users/me/tasks/${task.id}/schedule`
|
|
154
|
+
: `/api/v1/workspaces/${wsId}/tasks/${task.id}/schedule`
|
|
155
|
+
),
|
|
153
156
|
{
|
|
154
157
|
method: 'POST',
|
|
158
|
+
credentials: 'include',
|
|
155
159
|
headers: { 'Content-Type': 'application/json' },
|
|
156
160
|
}
|
|
157
161
|
);
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import type { TimeTrackingCategory } from '@tuturuuu/types';
|
|
18
18
|
import { cn } from '@tuturuuu/utils/format';
|
|
19
19
|
import { useCallback, useEffect, useState } from 'react';
|
|
20
|
+
import { getTaskApiUrl } from '../../../../../lib/tasks-app-url';
|
|
20
21
|
import { Badge } from '../../../badge';
|
|
21
22
|
import { Button } from '../../../button';
|
|
22
23
|
import { Card, CardContent, CardHeader, CardTitle } from '../../../card';
|
|
@@ -201,15 +202,19 @@ export default function TimeTracker({ wsId, tasks = [] }: TimeTrackerProps) {
|
|
|
201
202
|
setIsCreatingTask(true);
|
|
202
203
|
|
|
203
204
|
try {
|
|
204
|
-
const response = await fetch(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
205
|
+
const response = await fetch(
|
|
206
|
+
getTaskApiUrl(`/api/v1/workspaces/${wsId}/tasks`),
|
|
207
|
+
{
|
|
208
|
+
method: 'POST',
|
|
209
|
+
credentials: 'include',
|
|
210
|
+
headers: { 'Content-Type': 'application/json' },
|
|
211
|
+
body: JSON.stringify({
|
|
212
|
+
name: newTaskName,
|
|
213
|
+
description: newTaskDescription || null,
|
|
214
|
+
listId: selectedListId,
|
|
215
|
+
}),
|
|
216
|
+
}
|
|
217
|
+
);
|
|
213
218
|
|
|
214
219
|
if (!response.ok) throw new Error('Failed to create task');
|
|
215
220
|
|
|
@@ -27,6 +27,7 @@ import { toast } from '@tuturuuu/ui/sonner';
|
|
|
27
27
|
import { Switch } from '@tuturuuu/ui/switch';
|
|
28
28
|
import { useTranslations } from 'next-intl';
|
|
29
29
|
import { useEffect } from 'react';
|
|
30
|
+
import { getTaskApiUrl } from '../../../../lib/tasks-app-url';
|
|
30
31
|
import {
|
|
31
32
|
normalizeTaskDialogPresentation,
|
|
32
33
|
TASK_DIALOG_DEFAULT_PRESENTATION_CONFIG_ID,
|
|
@@ -145,7 +146,9 @@ export function TaskSettings({ workspace }: TaskSettingsProps) {
|
|
|
145
146
|
const { data: settings, isLoading } = useQuery({
|
|
146
147
|
queryKey: ['user-task-settings'],
|
|
147
148
|
queryFn: async (): Promise<TaskSettingsData> => {
|
|
148
|
-
const res = await fetch('/api/v1/users/task-settings')
|
|
149
|
+
const res = await fetch(getTaskApiUrl('/api/v1/users/task-settings'), {
|
|
150
|
+
credentials: 'include',
|
|
151
|
+
});
|
|
149
152
|
if (!res.ok) throw new Error('Failed to fetch task settings');
|
|
150
153
|
return res.json();
|
|
151
154
|
},
|
|
@@ -162,8 +165,9 @@ export function TaskSettings({ workspace }: TaskSettingsProps) {
|
|
|
162
165
|
|
|
163
166
|
const updateSettings = useMutation({
|
|
164
167
|
mutationFn: async (data: Partial<TaskSettingsData>) => {
|
|
165
|
-
const res = await fetch('/api/v1/users/task-settings', {
|
|
168
|
+
const res = await fetch(getTaskApiUrl('/api/v1/users/task-settings'), {
|
|
166
169
|
method: 'PATCH',
|
|
170
|
+
credentials: 'include',
|
|
167
171
|
headers: { 'Content-Type': 'application/json' },
|
|
168
172
|
body: JSON.stringify(data),
|
|
169
173
|
});
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
getFacetedUniqueValues,
|
|
10
10
|
getFilteredRowModel,
|
|
11
11
|
getSortedRowModel,
|
|
12
|
+
type Row,
|
|
12
13
|
type SortingState,
|
|
13
14
|
useReactTable,
|
|
14
15
|
type VisibilityState,
|
|
@@ -27,6 +28,15 @@ import {
|
|
|
27
28
|
import { DataTablePagination } from './data-table-pagination';
|
|
28
29
|
import { DataTableToolbar } from './data-table-toolbar';
|
|
29
30
|
|
|
31
|
+
function isInteractiveTarget(target: EventTarget | null) {
|
|
32
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
33
|
+
return Boolean(
|
|
34
|
+
target.closest(
|
|
35
|
+
'a, button, input, select, textarea, label, [role="menuitem"], [data-no-row-activate]'
|
|
36
|
+
)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
30
40
|
/**
|
|
31
41
|
* Options for column generator functions.
|
|
32
42
|
* Using named parameters improves readability and maintainability.
|
|
@@ -79,6 +89,8 @@ export interface DataTableProps<TData, TValue> {
|
|
|
79
89
|
/** Custom toolbar actions rendered directly (not wrapped in dialogs) */
|
|
80
90
|
toolbarActions?: ReactNode;
|
|
81
91
|
className?: string;
|
|
92
|
+
tableCardClassName?: string;
|
|
93
|
+
tableClassName?: string;
|
|
82
94
|
preserveParams?: string[];
|
|
83
95
|
onRefresh?: () => void;
|
|
84
96
|
selectedRowsActions?: (selectedRows: TData[]) => ReactNode;
|
|
@@ -87,6 +99,7 @@ export interface DataTableProps<TData, TValue> {
|
|
|
87
99
|
|
|
88
100
|
onRowClick?: (row: TData) => void;
|
|
89
101
|
onRowDoubleClick?: (row: TData) => void;
|
|
102
|
+
getRowId?: (originalRow: TData, index: number, parent?: Row<TData>) => string;
|
|
90
103
|
|
|
91
104
|
setParams?: (params: {
|
|
92
105
|
page?: number;
|
|
@@ -127,11 +140,14 @@ export function DataTable<TData, TValue>({
|
|
|
127
140
|
toolbarExportContent,
|
|
128
141
|
toolbarActions,
|
|
129
142
|
className,
|
|
143
|
+
tableCardClassName,
|
|
144
|
+
tableClassName,
|
|
130
145
|
onRefresh,
|
|
131
146
|
selectedRowsActions,
|
|
132
147
|
onSearch,
|
|
133
148
|
onRowClick,
|
|
134
149
|
onRowDoubleClick,
|
|
150
|
+
getRowId,
|
|
135
151
|
setParams,
|
|
136
152
|
resetParams,
|
|
137
153
|
columnGenerator,
|
|
@@ -169,6 +185,7 @@ export function DataTable<TData, TValue>({
|
|
|
169
185
|
: undefined,
|
|
170
186
|
enableRowSelection: true,
|
|
171
187
|
autoResetPageIndex: true,
|
|
188
|
+
getRowId,
|
|
172
189
|
onRowSelectionChange: setRowSelection,
|
|
173
190
|
onSortingChange: enableServerSideSorting
|
|
174
191
|
? (updaterOrValue) => {
|
|
@@ -232,16 +249,23 @@ export function DataTable<TData, TValue>({
|
|
|
232
249
|
toolbarActions={toolbarActions}
|
|
233
250
|
/>
|
|
234
251
|
)}
|
|
235
|
-
<Card>
|
|
236
|
-
<Table>
|
|
252
|
+
<Card className={tableCardClassName}>
|
|
253
|
+
<Table className={tableClassName}>
|
|
237
254
|
<TableHeader>
|
|
238
255
|
{table.getHeaderGroups().map((headerGroup) => (
|
|
239
256
|
<TableRow key={headerGroup.id}>
|
|
240
257
|
{headerGroup.headers.map((header) => {
|
|
258
|
+
const meta = header.column.columnDef.meta as
|
|
259
|
+
| { className?: string }
|
|
260
|
+
| undefined;
|
|
261
|
+
|
|
241
262
|
return (
|
|
242
263
|
<TableHead
|
|
243
264
|
key={header.id}
|
|
244
|
-
className=
|
|
265
|
+
className={cn(
|
|
266
|
+
'bg-foreground/5 font-semibold text-foreground/70 first:rounded-tl-xl last:rounded-tr-xl',
|
|
267
|
+
meta?.className
|
|
268
|
+
)}
|
|
245
269
|
>
|
|
246
270
|
{header.isPlaceholder
|
|
247
271
|
? null
|
|
@@ -258,16 +282,42 @@ export function DataTable<TData, TValue>({
|
|
|
258
282
|
<TableBody>
|
|
259
283
|
{table.getRowModel().rows?.length ? (
|
|
260
284
|
table.getRowModel().rows.map((row) => {
|
|
285
|
+
const isInteractiveRow = Boolean(
|
|
286
|
+
onRowClick || onRowDoubleClick
|
|
287
|
+
);
|
|
261
288
|
const tableRow = (
|
|
262
289
|
<TableRow
|
|
263
290
|
key={`${namespace}-${row.id}`}
|
|
264
291
|
data-state={row.getIsSelected() && 'selected'}
|
|
265
|
-
className=
|
|
266
|
-
onClick={() =>
|
|
267
|
-
|
|
292
|
+
className={cn(isInteractiveRow && 'cursor-pointer')}
|
|
293
|
+
onClick={(event) => {
|
|
294
|
+
if (isInteractiveTarget(event.target)) return;
|
|
295
|
+
onRowClick?.(row.original);
|
|
296
|
+
}}
|
|
297
|
+
onDoubleClick={(event) => {
|
|
298
|
+
if (isInteractiveTarget(event.target)) return;
|
|
299
|
+
onRowDoubleClick?.(row.original);
|
|
300
|
+
}}
|
|
301
|
+
onKeyDown={(event) => {
|
|
302
|
+
if (!onRowClick) return;
|
|
303
|
+
if (event.key !== 'Enter' && event.key !== ' ') return;
|
|
304
|
+
if (isInteractiveTarget(event.target)) return;
|
|
305
|
+
event.preventDefault();
|
|
306
|
+
onRowClick(row.original);
|
|
307
|
+
}}
|
|
308
|
+
tabIndex={onRowClick ? 0 : undefined}
|
|
268
309
|
>
|
|
269
310
|
{row.getVisibleCells().map((cell) => (
|
|
270
|
-
<TableCell
|
|
311
|
+
<TableCell
|
|
312
|
+
key={`${namespace}-${cell.id}`}
|
|
313
|
+
className={
|
|
314
|
+
(
|
|
315
|
+
cell.column.columnDef.meta as
|
|
316
|
+
| { cellClassName?: string }
|
|
317
|
+
| undefined
|
|
318
|
+
)?.cellClassName
|
|
319
|
+
}
|
|
320
|
+
>
|
|
271
321
|
{flexRender(
|
|
272
322
|
cell.column.columnDef.cell,
|
|
273
323
|
cell.getContext()
|
|
@@ -293,7 +343,7 @@ export function DataTable<TData, TValue>({
|
|
|
293
343
|
>
|
|
294
344
|
{data
|
|
295
345
|
? `${t?.('common.no-results')}.`
|
|
296
|
-
: `${t?.('common.loading')}
|
|
346
|
+
: `${t?.('common.loading')}…`}
|
|
297
347
|
</TableCell>
|
|
298
348
|
</TableRow>
|
|
299
349
|
)}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Check, PackagePlus, Search } from '@tuturuuu/icons';
|
|
4
|
+
import type {
|
|
5
|
+
InventoryBundle,
|
|
6
|
+
InventoryBundleCategoryCandidate,
|
|
7
|
+
InventoryStorefrontListing,
|
|
8
|
+
} from '@tuturuuu/internal-api/inventory';
|
|
9
|
+
import { cn } from '@tuturuuu/utils/format';
|
|
10
|
+
import { useMemo, useState } from 'react';
|
|
11
|
+
import { Badge } from '../badge';
|
|
12
|
+
import { Button } from '../button';
|
|
13
|
+
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '../dialog';
|
|
14
|
+
import { Input } from '../input';
|
|
15
|
+
import type { StorefrontCartLine, StorefrontSurfaceLabels } from './types';
|
|
16
|
+
import {
|
|
17
|
+
createStorefrontBundleSelectionKey,
|
|
18
|
+
formatStorefrontPrice,
|
|
19
|
+
getStorefrontBundleSelectionSubtotal,
|
|
20
|
+
} from './utils';
|
|
21
|
+
|
|
22
|
+
type BundleSelectionDialogProps = {
|
|
23
|
+
bundle: InventoryBundle | null;
|
|
24
|
+
currency: string;
|
|
25
|
+
labels: StorefrontSurfaceLabels;
|
|
26
|
+
listing: InventoryStorefrontListing | null;
|
|
27
|
+
onAdd?: (line: StorefrontCartLine) => void;
|
|
28
|
+
onOpenChange: (open: boolean) => void;
|
|
29
|
+
open: boolean;
|
|
30
|
+
radius: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function StorefrontBundleSelectionDialog({
|
|
34
|
+
bundle,
|
|
35
|
+
currency,
|
|
36
|
+
labels,
|
|
37
|
+
listing,
|
|
38
|
+
onAdd,
|
|
39
|
+
onOpenChange,
|
|
40
|
+
open,
|
|
41
|
+
radius,
|
|
42
|
+
}: BundleSelectionDialogProps) {
|
|
43
|
+
const [query, setQuery] = useState('');
|
|
44
|
+
const [selected, setSelected] = useState<Record<string, string[]>>({});
|
|
45
|
+
const normalizedQuery = query.trim().toLowerCase();
|
|
46
|
+
const selections = useMemo(() => {
|
|
47
|
+
if (!bundle) return {};
|
|
48
|
+
|
|
49
|
+
return Object.fromEntries(
|
|
50
|
+
bundle.categoryComponents.map((component) => {
|
|
51
|
+
const candidates = component.candidates ?? [];
|
|
52
|
+
const items = (selected[component.id] ?? []).flatMap((key) => {
|
|
53
|
+
const candidate = candidates.find(
|
|
54
|
+
(item) => getCandidateKey(item) === key
|
|
55
|
+
);
|
|
56
|
+
return candidate ? [candidateToSelection(candidate)] : [];
|
|
57
|
+
});
|
|
58
|
+
return [component.id, items];
|
|
59
|
+
})
|
|
60
|
+
);
|
|
61
|
+
}, [bundle, selected]);
|
|
62
|
+
const selectionLine: StorefrontCartLine | null =
|
|
63
|
+
listing && bundle
|
|
64
|
+
? {
|
|
65
|
+
bundleSelections: selections,
|
|
66
|
+
listingId: listing.id,
|
|
67
|
+
quantity: 1,
|
|
68
|
+
selectionKey: createStorefrontBundleSelectionKey(bundle, selections),
|
|
69
|
+
}
|
|
70
|
+
: null;
|
|
71
|
+
const subtotal =
|
|
72
|
+
bundle && selectionLine
|
|
73
|
+
? getStorefrontBundleSelectionSubtotal(bundle, selectionLine)
|
|
74
|
+
: null;
|
|
75
|
+
const isComplete =
|
|
76
|
+
Boolean(bundle?.categoryComponents.length) &&
|
|
77
|
+
bundle?.categoryComponents.every(
|
|
78
|
+
(component) =>
|
|
79
|
+
(selected[component.id]?.length ?? 0) === component.quantityRequired
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
if (!bundle || !listing) return null;
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<Dialog
|
|
86
|
+
onOpenChange={(nextOpen) => {
|
|
87
|
+
if (!nextOpen) {
|
|
88
|
+
setQuery('');
|
|
89
|
+
setSelected({});
|
|
90
|
+
}
|
|
91
|
+
onOpenChange(nextOpen);
|
|
92
|
+
}}
|
|
93
|
+
open={open}
|
|
94
|
+
>
|
|
95
|
+
<DialogContent className="grid max-h-[90dvh] max-w-[min(42rem,calc(100vw-1rem))] grid-rows-[auto_auto_minmax(0,1fr)_auto] gap-4 overflow-hidden border-border/60 p-5 sm:rounded-2xl">
|
|
96
|
+
<DialogHeader className="text-left">
|
|
97
|
+
<DialogTitle>{labels.bundleSelectionTitle}</DialogTitle>
|
|
98
|
+
<p className="text-muted-foreground text-sm">{listing.title}</p>
|
|
99
|
+
</DialogHeader>
|
|
100
|
+
<div className="grid gap-2">
|
|
101
|
+
<label className="relative block">
|
|
102
|
+
<Search className="pointer-events-none absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
|
103
|
+
<Input
|
|
104
|
+
className="h-10 pl-9"
|
|
105
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
106
|
+
placeholder={labels.searchBundleItems}
|
|
107
|
+
value={query}
|
|
108
|
+
/>
|
|
109
|
+
</label>
|
|
110
|
+
<p className="rounded-md border border-border bg-muted/25 px-3 py-2 text-muted-foreground text-xs">
|
|
111
|
+
{labels.cheapestFreePreview}
|
|
112
|
+
</p>
|
|
113
|
+
</div>
|
|
114
|
+
<div className="-mr-1 grid gap-4 overflow-y-auto pr-1">
|
|
115
|
+
{bundle.categoryComponents.map((component) => {
|
|
116
|
+
const selectedKeys = selected[component.id] ?? [];
|
|
117
|
+
const filteredCandidates = (component.candidates ?? []).filter(
|
|
118
|
+
(candidate) =>
|
|
119
|
+
!normalizedQuery ||
|
|
120
|
+
candidate.title.toLowerCase().includes(normalizedQuery)
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<section className="grid gap-2" key={component.id}>
|
|
125
|
+
<div className="flex items-center justify-between gap-3">
|
|
126
|
+
<div className="min-w-0">
|
|
127
|
+
<p className="truncate font-medium text-sm">
|
|
128
|
+
{component.categoryName}
|
|
129
|
+
</p>
|
|
130
|
+
<p className="text-muted-foreground text-xs">
|
|
131
|
+
{labels.selectedItems
|
|
132
|
+
.replace('{selected}', String(selectedKeys.length))
|
|
133
|
+
.replace(
|
|
134
|
+
'{required}',
|
|
135
|
+
String(component.quantityRequired)
|
|
136
|
+
)}
|
|
137
|
+
</p>
|
|
138
|
+
</div>
|
|
139
|
+
<Badge
|
|
140
|
+
className="border-border bg-background"
|
|
141
|
+
variant="outline"
|
|
142
|
+
>
|
|
143
|
+
{labels.requiredItems.replace(
|
|
144
|
+
'{count}',
|
|
145
|
+
String(component.quantityRequired)
|
|
146
|
+
)}
|
|
147
|
+
</Badge>
|
|
148
|
+
</div>
|
|
149
|
+
<div className="grid gap-2 sm:grid-cols-2">
|
|
150
|
+
{filteredCandidates.map((candidate) => {
|
|
151
|
+
const key = getCandidateKey(candidate);
|
|
152
|
+
const active = selectedKeys.includes(key);
|
|
153
|
+
const full =
|
|
154
|
+
!active &&
|
|
155
|
+
selectedKeys.length >= component.quantityRequired;
|
|
156
|
+
const disabled =
|
|
157
|
+
full || candidate.availableQuantity === 0 || !onAdd;
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<button
|
|
161
|
+
className={cn(
|
|
162
|
+
'grid min-h-20 gap-1 rounded-lg border bg-background p-3 text-left text-sm transition',
|
|
163
|
+
active
|
|
164
|
+
? 'border-[var(--storefront-accent,var(--primary))] bg-[var(--storefront-accent-soft,var(--muted))]'
|
|
165
|
+
: 'border-border hover:border-foreground/35',
|
|
166
|
+
disabled ? 'cursor-not-allowed opacity-60' : null
|
|
167
|
+
)}
|
|
168
|
+
disabled={disabled}
|
|
169
|
+
key={key}
|
|
170
|
+
onClick={() =>
|
|
171
|
+
setSelected((current) => ({
|
|
172
|
+
...current,
|
|
173
|
+
[component.id]: active
|
|
174
|
+
? selectedKeys.filter((item) => item !== key)
|
|
175
|
+
: [...selectedKeys, key],
|
|
176
|
+
}))
|
|
177
|
+
}
|
|
178
|
+
type="button"
|
|
179
|
+
>
|
|
180
|
+
<span className="flex min-w-0 items-center justify-between gap-2">
|
|
181
|
+
<span className="line-clamp-2 font-medium">
|
|
182
|
+
{candidate.title}
|
|
183
|
+
</span>
|
|
184
|
+
{active ? <Check className="h-4 w-4" /> : null}
|
|
185
|
+
</span>
|
|
186
|
+
<span className="text-muted-foreground text-xs">
|
|
187
|
+
{candidate.unitName || candidate.unitId} /{' '}
|
|
188
|
+
{candidate.warehouseName || candidate.warehouseId}
|
|
189
|
+
</span>
|
|
190
|
+
<span className="font-semibold tabular-nums">
|
|
191
|
+
{formatStorefrontPrice(candidate.price, currency)}
|
|
192
|
+
</span>
|
|
193
|
+
</button>
|
|
194
|
+
);
|
|
195
|
+
})}
|
|
196
|
+
</div>
|
|
197
|
+
</section>
|
|
198
|
+
);
|
|
199
|
+
})}
|
|
200
|
+
</div>
|
|
201
|
+
<div className="flex flex-wrap items-center justify-between gap-3 border-border border-t pt-4">
|
|
202
|
+
<div className="min-w-0">
|
|
203
|
+
<p className="text-muted-foreground text-xs">{labels.total}</p>
|
|
204
|
+
<p className="font-semibold tabular-nums">
|
|
205
|
+
{formatStorefrontPrice(subtotal ?? 0, currency)}
|
|
206
|
+
</p>
|
|
207
|
+
</div>
|
|
208
|
+
<Button
|
|
209
|
+
className={cn('min-w-36', radius)}
|
|
210
|
+
disabled={!isComplete || !selectionLine || !onAdd}
|
|
211
|
+
onClick={() => {
|
|
212
|
+
if (!selectionLine || !onAdd) return;
|
|
213
|
+
onAdd(selectionLine);
|
|
214
|
+
onOpenChange(false);
|
|
215
|
+
setQuery('');
|
|
216
|
+
setSelected({});
|
|
217
|
+
}}
|
|
218
|
+
type="button"
|
|
219
|
+
>
|
|
220
|
+
<PackagePlus className="h-4 w-4" />
|
|
221
|
+
{labels.add}
|
|
222
|
+
</Button>
|
|
223
|
+
</div>
|
|
224
|
+
</DialogContent>
|
|
225
|
+
</Dialog>
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function candidateToSelection(candidate: InventoryBundleCategoryCandidate) {
|
|
230
|
+
return {
|
|
231
|
+
listingId: candidate.listingId,
|
|
232
|
+
productId: candidate.productId,
|
|
233
|
+
quantity: 1,
|
|
234
|
+
unitId: candidate.unitId,
|
|
235
|
+
variantId: candidate.variantId,
|
|
236
|
+
warehouseId: candidate.warehouseId,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function getCandidateKey(candidate: InventoryBundleCategoryCandidate) {
|
|
241
|
+
return [
|
|
242
|
+
candidate.selectionKind,
|
|
243
|
+
candidate.listingId ?? '',
|
|
244
|
+
candidate.variantId ?? '',
|
|
245
|
+
candidate.productId,
|
|
246
|
+
candidate.unitId,
|
|
247
|
+
candidate.warehouseId,
|
|
248
|
+
].join(':');
|
|
249
|
+
}
|