@tuturuuu/ui 0.8.0 → 0.9.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.
Files changed (182) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/biome.json +1 -1
  3. package/package.json +73 -71
  4. package/src/components/ui/accordion.tsx +1 -1
  5. package/src/components/ui/breadcrumb.tsx +1 -1
  6. package/src/components/ui/calendar-app/calendar-page-shell.tsx +4 -0
  7. package/src/components/ui/calendar-app/components/calendar-connections-settings-content.tsx +239 -33
  8. package/src/components/ui/calendar-app/components/load-smart-scheduling-tasks.tsx +143 -0
  9. package/src/components/ui/calendar-app/components/priority-view.tsx +10 -3
  10. package/src/components/ui/calendar-app/components/tasks-sidebar.tsx +4 -116
  11. package/src/components/ui/calendar-app/components/use-calendar-connections-manager.ts +67 -2
  12. package/src/components/ui/calendar.tsx +1 -1
  13. package/src/components/ui/carousel.tsx +1 -1
  14. package/src/components/ui/chat/chat-agent-details-external-thread-panel.test.tsx +1 -1
  15. package/src/components/ui/chat/chat-agent-details-external-thread-panel.tsx +1 -1
  16. package/src/components/ui/chat/chat-agent-details-operations-panel.test.tsx +1 -1
  17. package/src/components/ui/chat/chat-agent-details-operations-panel.tsx +1 -1
  18. package/src/components/ui/chat/chat-agent-details-setup-panel.tsx +1 -1
  19. package/src/components/ui/chat/chat-agent-details-sidebar.test.tsx +1 -1
  20. package/src/components/ui/chat/chat-agent-details-sidebar.tsx +2 -2
  21. package/src/components/ui/chat/chat-agent-details-utils.test.ts +1 -1
  22. package/src/components/ui/chat/chat-agent-details-utils.tsx +1 -1
  23. package/src/components/ui/chat/chat-agent-details-zalo-personal-panel.tsx +2 -2
  24. package/src/components/ui/checkbox.tsx +1 -1
  25. package/src/components/ui/color-picker.tsx +1 -1
  26. package/src/components/ui/command.tsx +1 -1
  27. package/src/components/ui/context-menu.tsx +5 -1
  28. package/src/components/ui/custom/__tests__/settings-dialog-shell.test.tsx +3 -0
  29. package/src/components/ui/custom/__tests__/workspace-select-helpers.test.ts +19 -0
  30. package/src/components/ui/custom/combobox.test.tsx +195 -0
  31. package/src/components/ui/custom/combobox.tsx +273 -156
  32. package/src/components/ui/custom/education/modules/youtube/delete-link-button.tsx +5 -13
  33. package/src/components/ui/custom/facebook-mockup/facebook-mockup.tsx +7 -1
  34. package/src/components/ui/custom/facebook-mockup/form.tsx +1 -1
  35. package/src/components/ui/custom/facebook-mockup/image-upload-field.tsx +1 -1
  36. package/src/components/ui/custom/facebook-mockup/preview.tsx +1 -1
  37. package/src/components/ui/custom/settings-dialog-shell.tsx +2 -1
  38. package/src/components/ui/custom/theme-toggle.tsx +1 -1
  39. package/src/components/ui/custom/workspace-select.tsx +8 -3
  40. package/src/components/ui/dialog.test.tsx +52 -0
  41. package/src/components/ui/dialog.tsx +6 -2
  42. package/src/components/ui/dropdown-menu.tsx +5 -1
  43. package/src/components/ui/finance/debts/debt-loan-form.tsx +12 -5
  44. package/src/components/ui/finance/debts/debt-loan-summary.tsx +3 -2
  45. package/src/components/ui/finance/debts/debts-page.test.tsx +54 -5
  46. package/src/components/ui/finance/debts/debts-page.tsx +15 -2
  47. package/src/components/ui/finance/invoices/components/subscription-group-selector.tsx +3 -5
  48. package/src/components/ui/finance/invoices/new-invoice-page.test.tsx +25 -5
  49. package/src/components/ui/finance/invoices/new-invoice-page.tsx +7 -2
  50. package/src/components/ui/finance/invoices/standard-invoice.tsx +4 -2
  51. package/src/components/ui/finance/invoices/subscription-invoice.tsx +4 -2
  52. package/src/components/ui/finance/invoices/utils.ts +3 -1
  53. package/src/components/ui/finance/transactions/form-content-dialog.tsx +3 -0
  54. package/src/components/ui/finance/transactions/form-types.ts +1 -0
  55. package/src/components/ui/finance/transactions/form.tsx +2 -0
  56. package/src/components/ui/finance/transactions/infinite-transactions-list.tsx +2 -0
  57. package/src/components/ui/finance/transactions/period-charts/category-breakdown-dialog.tsx +1 -1
  58. package/src/components/ui/finance/transactions/transaction-edit-dialog.tsx +1 -4
  59. package/src/components/ui/finance/transactions/transactions-create-summary.tsx +3 -0
  60. package/src/components/ui/finance/transactions/transactions-page.tsx +4 -1
  61. package/src/components/ui/finance/wallets/form.test.tsx +51 -3
  62. package/src/components/ui/finance/wallets/form.tsx +15 -4
  63. package/src/components/ui/finance/wallets/walletId/wallet-details-actions.tsx +4 -0
  64. package/src/components/ui/finance/wallets/walletId/wallet-details-page.tsx +4 -2
  65. package/src/components/ui/finance/wallets/wallets-data-table.tsx +1 -0
  66. package/src/components/ui/finance/wallets/wallets-page.tsx +5 -2
  67. package/src/components/ui/input-otp.tsx +1 -1
  68. package/src/components/ui/legacy/calendar/all-day-event-bar.tsx +28 -39
  69. package/src/components/ui/legacy/calendar/calendar-cell.tsx +2 -0
  70. package/src/components/ui/legacy/calendar/calendar-content.tsx +10 -6
  71. package/src/components/ui/legacy/calendar/calendar-header.tsx +23 -3
  72. package/src/components/ui/legacy/calendar/calendar-loading-skeleton.tsx +135 -0
  73. package/src/components/ui/legacy/calendar/calendar-matrix.tsx +175 -237
  74. package/src/components/ui/legacy/calendar/event-card.test.tsx +177 -0
  75. package/src/components/ui/legacy/calendar/event-card.tsx +220 -131
  76. package/src/components/ui/legacy/calendar/event-modal.tsx +17 -17
  77. package/src/components/ui/legacy/calendar/event-provider-display.tsx +69 -0
  78. package/src/components/ui/legacy/calendar/smart-calendar.test.tsx +86 -4
  79. package/src/components/ui/legacy/calendar/smart-calendar.tsx +32 -2
  80. package/src/components/ui/legacy/meet/create-plan-dialog.tsx +19 -10
  81. package/src/components/ui/navigation-menu.tsx +1 -1
  82. package/src/components/ui/pagination.tsx +1 -1
  83. package/src/components/ui/radio-group.tsx +1 -1
  84. package/src/components/ui/select.tsx +5 -1
  85. package/src/components/ui/sheet.tsx +1 -1
  86. package/src/components/ui/sidebar.tsx +1 -1
  87. package/src/components/ui/storefront/cart-popover.tsx +61 -0
  88. package/src/components/ui/storefront/cart-summary-parts.tsx +290 -0
  89. package/src/components/ui/storefront/cart-summary.tsx +93 -154
  90. package/src/components/ui/storefront/checkout-overlay.tsx +4 -5
  91. package/src/components/ui/storefront/listing-card.tsx +1 -1
  92. package/src/components/ui/storefront/merch-sections.tsx +70 -0
  93. package/src/components/ui/storefront/product-detail.tsx +1 -1
  94. package/src/components/ui/storefront/storefront-surface.test.tsx +106 -11
  95. package/src/components/ui/storefront/storefront-surface.tsx +101 -166
  96. package/src/components/ui/storefront/types.ts +4 -0
  97. package/src/components/ui/storefront/utils.ts +6 -0
  98. package/src/components/ui/text-editor/__tests__/extensions.test.ts +123 -0
  99. package/src/components/ui/text-editor/background-color-extension.ts +62 -0
  100. package/src/components/ui/text-editor/color-controls.tsx +284 -0
  101. package/src/components/ui/text-editor/editor.tsx +69 -14
  102. package/src/components/ui/text-editor/extensions.ts +8 -2
  103. package/src/components/ui/text-editor/highlight-extension.ts +22 -0
  104. package/src/components/ui/text-editor/tool-bar.tsx +9 -16
  105. package/src/components/ui/toast.tsx +1 -1
  106. package/src/components/ui/tu-do/boards/__tests__/board-share-dialog.test.tsx +270 -0
  107. package/src/components/ui/tu-do/boards/board-public-link-section.tsx +231 -0
  108. package/src/components/ui/tu-do/boards/board-share-dialog.tsx +222 -109
  109. package/src/components/ui/tu-do/boards/boardId/board-column.tsx +112 -43
  110. package/src/components/ui/tu-do/boards/boardId/kanban/bulk/bulk-mutations-clear-delete.ts +2 -0
  111. package/src/components/ui/tu-do/boards/boardId/kanban/bulk/bulk-mutations-move.ts +5 -0
  112. package/src/components/ui/tu-do/boards/boardId/kanban/bulk/bulk-mutations-updates.ts +3 -0
  113. package/src/components/ui/tu-do/boards/boardId/kanban/data/kanban-deadline-query.ts +50 -2
  114. package/src/components/ui/tu-do/boards/boardId/kanban/dnd/__tests__/column-reorder.test.ts +17 -0
  115. package/src/components/ui/tu-do/boards/boardId/kanban/dnd/column-reorder.ts +4 -1
  116. package/src/components/ui/tu-do/boards/boardId/kanban/dnd/task-drag-cache.ts +38 -9
  117. package/src/components/ui/tu-do/boards/boardId/kanban/dnd/task-drag-order.ts +2 -8
  118. package/src/components/ui/tu-do/boards/boardId/kanban/dnd/task-sort-key.ts +47 -0
  119. package/src/components/ui/tu-do/boards/boardId/kanban/dnd/use-kanban-dnd.ts +81 -30
  120. package/src/components/ui/tu-do/boards/boardId/kanban/planner/__tests__/kanban-planner-island.test.tsx +380 -0
  121. package/src/components/ui/tu-do/boards/boardId/kanban/planner/kanban-planner-dialog.tsx +204 -0
  122. package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-digest-panel.tsx +61 -0
  123. package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-item-strip.tsx +54 -0
  124. package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-plan-toolbar.tsx +251 -0
  125. package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-scope-badge.tsx +27 -0
  126. package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-section.tsx +58 -0
  127. package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-share-dialog.tsx +238 -0
  128. package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-target-controls.tsx +143 -0
  129. package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-utils.ts +65 -0
  130. package/src/components/ui/tu-do/boards/boardId/kanban/planner/use-kanban-planner-state.ts +234 -0
  131. package/src/components/ui/tu-do/boards/boardId/kanban/rendering/kanban-columns.test.tsx +397 -2
  132. package/src/components/ui/tu-do/boards/boardId/kanban/rendering/kanban-columns.tsx +103 -13
  133. package/src/components/ui/tu-do/boards/boardId/kanban/rendering/kanban-deadline-panels.tsx +443 -19
  134. package/src/components/ui/tu-do/boards/boardId/kanban/rendering/kanban-skeleton.tsx +94 -32
  135. package/src/components/ui/tu-do/boards/boardId/kanban.tsx +213 -106
  136. package/src/components/ui/tu-do/boards/boardId/task-board-server-page.test.tsx +26 -4
  137. package/src/components/ui/tu-do/boards/boardId/task-board-server-page.tsx +5 -2
  138. package/src/components/ui/tu-do/boards/boardId/task-card/measured-task-card.tsx +3 -0
  139. package/src/components/ui/tu-do/boards/boardId/task-card/task-card-comparator.ts +3 -0
  140. package/src/components/ui/tu-do/boards/boardId/task-card/task-card.tsx +191 -28
  141. package/src/components/ui/tu-do/boards/boardId/task-filter.test.tsx +152 -0
  142. package/src/components/ui/tu-do/boards/boardId/task-filter.tsx +555 -545
  143. package/src/components/ui/tu-do/boards/boardId/task-list.tsx +7 -0
  144. package/src/components/ui/tu-do/boards/share-section.tsx +100 -0
  145. package/src/components/ui/tu-do/drafts/draft-convert-dialog.tsx +10 -12
  146. package/src/components/ui/tu-do/drafts/drafts-page.tsx +33 -16
  147. package/src/components/ui/tu-do/initiatives/task-initiatives-client.tsx +56 -88
  148. package/src/components/ui/tu-do/my-tasks/my-tasks-content.tsx +26 -2
  149. package/src/components/ui/tu-do/my-tasks/use-my-tasks-state.ts +55 -8
  150. package/src/components/ui/tu-do/notes/note-edit-dialog.tsx +1 -4
  151. package/src/components/ui/tu-do/shared/__tests__/board-client.test.tsx +25 -0
  152. package/src/components/ui/tu-do/shared/__tests__/board-header.test.tsx +341 -38
  153. package/src/components/ui/tu-do/shared/__tests__/board-switcher.test.tsx +253 -0
  154. package/src/components/ui/tu-do/shared/__tests__/board-views.test.tsx +203 -2
  155. package/src/components/ui/tu-do/shared/__tests__/task-board-loading-state.test.tsx +17 -0
  156. package/src/components/ui/tu-do/shared/__tests__/task-legacy-route-recovery.test.tsx +16 -0
  157. package/src/components/ui/tu-do/shared/board-client.tsx +2 -7
  158. package/src/components/ui/tu-do/shared/board-config-storage.ts +7 -1
  159. package/src/components/ui/tu-do/shared/board-header.tsx +464 -975
  160. package/src/components/ui/tu-do/shared/board-layout-settings.tsx +165 -136
  161. package/src/components/ui/tu-do/shared/board-switcher.tsx +209 -217
  162. package/src/components/ui/tu-do/shared/board-views.tsx +587 -75
  163. package/src/components/ui/tu-do/shared/list-view.tsx +227 -1
  164. package/src/components/ui/tu-do/shared/recycle-bin-panel.tsx +142 -94
  165. package/src/components/ui/tu-do/shared/special-task-list-pins.ts +51 -0
  166. package/src/components/ui/tu-do/shared/task-board-loading-state.tsx +28 -0
  167. package/src/components/ui/tu-do/shared/task-edit-dialog/field-diff-viewer.tsx +3 -2
  168. package/src/components/ui/tu-do/shared/task-edit-dialog/selective-revert-panel.test.tsx +91 -0
  169. package/src/components/ui/tu-do/shared/task-edit-dialog/selective-revert-panel.tsx +123 -78
  170. package/src/components/ui/tu-do/shared/task-edit-dialog/task-activity-section.tsx +7 -1
  171. package/src/components/ui/tu-do/shared/task-edit-dialog/task-snapshot-dialog.tsx +8 -3
  172. package/src/components/ui/tu-do/shared/task-edit-dialog.tsx +2 -1
  173. package/src/components/ui/tu-do/shared/task-legacy-route-recovery.tsx +2 -9
  174. package/src/declarations.d.ts +1 -0
  175. package/src/hooks/__tests__/use-calendar-readonly.test.tsx +322 -2
  176. package/src/hooks/__tests__/use-calendar-sync.test.tsx +446 -0
  177. package/src/hooks/use-calendar-sync.tsx +247 -243
  178. package/src/hooks/use-calendar.tsx +323 -138
  179. package/src/hooks/use-task-actions.ts +24 -0
  180. package/src/hooks/use-user-workspace-config.ts +75 -0
  181. package/src/hooks/use-workspace-currency.ts +8 -3
  182. package/src/hooks/useBoardRealtimeEventHandler.ts +11 -0
@@ -0,0 +1,270 @@
1
+ import '@testing-library/jest-dom';
2
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
3
+ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
4
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
5
+ import { BoardShareDialog } from '../board-share-dialog';
6
+
7
+ const createWorkspaceTaskBoardShareMock = vi.fn();
8
+ const deleteWorkspaceTaskBoardShareMock = vi.fn();
9
+ const disableWorkspaceTaskBoardPublicLinkMock = vi.fn();
10
+ const enableWorkspaceTaskBoardPublicLinkMock = vi.fn();
11
+ const getWorkspaceTaskBoardPublicLinkMock = vi.fn();
12
+ const listWorkspaceTaskBoardSharesMock = vi.fn();
13
+ const listWorkspaceTaskBoardViewableMembersMock = vi.fn();
14
+ const updateWorkspaceTaskBoardShareMock = vi.fn();
15
+
16
+ vi.mock('next-intl', () => ({
17
+ useLocale: () => 'en',
18
+ useTranslations: () => (key: string) => key,
19
+ }));
20
+
21
+ vi.mock('@tuturuuu/ui/custom/combobox', () => ({
22
+ Combobox: ({
23
+ disabled,
24
+ onChange,
25
+ options,
26
+ placeholder,
27
+ selected,
28
+ }: {
29
+ disabled?: boolean;
30
+ onChange?: (value: string) => void;
31
+ options: { label: string; value: string }[];
32
+ placeholder?: string;
33
+ selected: string;
34
+ }) => (
35
+ <select
36
+ aria-label={placeholder}
37
+ disabled={disabled}
38
+ value={selected}
39
+ onChange={(event) => onChange?.(event.target.value)}
40
+ >
41
+ {options.map((option) => (
42
+ <option key={option.value} value={option.value}>
43
+ {option.label}
44
+ </option>
45
+ ))}
46
+ </select>
47
+ ),
48
+ }));
49
+
50
+ vi.mock('@tuturuuu/internal-api/tasks', () => ({
51
+ createWorkspaceTaskBoardShare: (
52
+ ...args: Parameters<typeof createWorkspaceTaskBoardShareMock>
53
+ ) => createWorkspaceTaskBoardShareMock(...args),
54
+ deleteWorkspaceTaskBoardShare: (
55
+ ...args: Parameters<typeof deleteWorkspaceTaskBoardShareMock>
56
+ ) => deleteWorkspaceTaskBoardShareMock(...args),
57
+ disableWorkspaceTaskBoardPublicLink: (
58
+ ...args: Parameters<typeof disableWorkspaceTaskBoardPublicLinkMock>
59
+ ) => disableWorkspaceTaskBoardPublicLinkMock(...args),
60
+ enableWorkspaceTaskBoardPublicLink: (
61
+ ...args: Parameters<typeof enableWorkspaceTaskBoardPublicLinkMock>
62
+ ) => enableWorkspaceTaskBoardPublicLinkMock(...args),
63
+ getWorkspaceTaskBoardPublicLink: (
64
+ ...args: Parameters<typeof getWorkspaceTaskBoardPublicLinkMock>
65
+ ) => getWorkspaceTaskBoardPublicLinkMock(...args),
66
+ listWorkspaceTaskBoardShares: (
67
+ ...args: Parameters<typeof listWorkspaceTaskBoardSharesMock>
68
+ ) => listWorkspaceTaskBoardSharesMock(...args),
69
+ listWorkspaceTaskBoardViewableMembers: (
70
+ ...args: Parameters<typeof listWorkspaceTaskBoardViewableMembersMock>
71
+ ) => listWorkspaceTaskBoardViewableMembersMock(...args),
72
+ updateWorkspaceTaskBoardShare: (
73
+ ...args: Parameters<typeof updateWorkspaceTaskBoardShareMock>
74
+ ) => updateWorkspaceTaskBoardShareMock(...args),
75
+ }));
76
+
77
+ vi.mock('sonner', () => ({
78
+ toast: {
79
+ error: vi.fn(),
80
+ success: vi.fn(),
81
+ },
82
+ }));
83
+
84
+ function renderBoardShareDialog() {
85
+ const queryClient = new QueryClient({
86
+ defaultOptions: {
87
+ queries: {
88
+ retry: false,
89
+ },
90
+ },
91
+ });
92
+
93
+ return render(
94
+ <QueryClientProvider client={queryClient}>
95
+ <BoardShareDialog
96
+ board={{ id: 'board-1', name: 'Tasks' }}
97
+ onOpenChange={vi.fn()}
98
+ open
99
+ wsId="ws-1"
100
+ />
101
+ </QueryClientProvider>
102
+ );
103
+ }
104
+
105
+ describe('BoardShareDialog', () => {
106
+ beforeEach(() => {
107
+ vi.clearAllMocks();
108
+ getWorkspaceTaskBoardPublicLinkMock.mockResolvedValue({ publicLink: null });
109
+ enableWorkspaceTaskBoardPublicLinkMock.mockResolvedValue({
110
+ publicLink: { code: 'abc123' },
111
+ });
112
+ disableWorkspaceTaskBoardPublicLinkMock.mockResolvedValue({
113
+ publicLink: null,
114
+ });
115
+ createWorkspaceTaskBoardShareMock.mockResolvedValue({ share: null });
116
+ updateWorkspaceTaskBoardShareMock.mockResolvedValue({ share: null });
117
+ deleteWorkspaceTaskBoardShareMock.mockResolvedValue({ ok: true });
118
+ listWorkspaceTaskBoardSharesMock.mockResolvedValue({ shares: [] });
119
+ listWorkspaceTaskBoardViewableMembersMock.mockResolvedValue({
120
+ members: [
121
+ {
122
+ avatar_url: null,
123
+ display_name: 'Project Manager',
124
+ email: 'pm@example.com',
125
+ handle: null,
126
+ id: 'user-1',
127
+ is_creator: false,
128
+ roles: [{ id: 'role-1', name: 'Project manager' }],
129
+ user_id: 'user-1',
130
+ workspace_member_type: 'MEMBER',
131
+ },
132
+ ],
133
+ });
134
+ });
135
+
136
+ it('starts compact with all sections collapsed and tooltip copy hidden', async () => {
137
+ renderBoardShareDialog();
138
+
139
+ for (const title of [
140
+ 'ws-task-boards.share.public.title',
141
+ 'ws-task-boards.share.workspace_members.title',
142
+ 'ws-task-boards.share.guests.title',
143
+ ]) {
144
+ expect(
145
+ screen.getByRole('button', { name: new RegExp(title) })
146
+ ).toHaveAttribute('aria-expanded', 'false');
147
+ }
148
+
149
+ expect(
150
+ screen.queryByText('ws-task-boards.share.public.description')
151
+ ).not.toBeInTheDocument();
152
+ expect(
153
+ screen.queryByText('ws-task-boards.share.public.tooltip')
154
+ ).not.toBeInTheDocument();
155
+ expect(
156
+ screen.queryByText('ws-task-boards.share.workspace_members.description')
157
+ ).not.toBeInTheDocument();
158
+ expect(
159
+ screen.queryByText('ws-task-boards.share.guests.description')
160
+ ).not.toBeInTheDocument();
161
+ await waitFor(() => {
162
+ expect(getWorkspaceTaskBoardPublicLinkMock).toHaveBeenCalledWith(
163
+ 'ws-1',
164
+ 'board-1'
165
+ );
166
+ });
167
+ expect(listWorkspaceTaskBoardViewableMembersMock).not.toHaveBeenCalled();
168
+
169
+ expect(await screen.findByText('common.disabled')).toBeInTheDocument();
170
+ expect(screen.getByText('common.workspace')).toBeInTheDocument();
171
+ expect(screen.getByText('common.none')).toBeInTheDocument();
172
+ expect(
173
+ screen.queryByRole('button', {
174
+ name: /ws-task-boards.share.shared_with/,
175
+ })
176
+ ).not.toBeInTheDocument();
177
+ });
178
+
179
+ it('fetches viewable members only when the workspace section opens', async () => {
180
+ renderBoardShareDialog();
181
+
182
+ fireEvent.click(
183
+ screen.getByRole('button', {
184
+ name: /ws-task-boards.share.workspace_members.title/,
185
+ })
186
+ );
187
+
188
+ await waitFor(() => {
189
+ expect(listWorkspaceTaskBoardViewableMembersMock).toHaveBeenCalledWith(
190
+ 'ws-1',
191
+ 'board-1'
192
+ );
193
+ });
194
+ expect(await screen.findByText('Project Manager')).toBeInTheDocument();
195
+ expect(screen.getByText('pm@example.com')).toBeInTheDocument();
196
+ });
197
+
198
+ it('keeps direct board guests first-class for invite, update, and remove', async () => {
199
+ listWorkspaceTaskBoardSharesMock.mockResolvedValue({
200
+ shares: [
201
+ {
202
+ id: 'share-1',
203
+ email: 'guest@example.com',
204
+ permission: 'view',
205
+ user: null,
206
+ user_id: null,
207
+ },
208
+ ],
209
+ });
210
+
211
+ renderBoardShareDialog();
212
+ await waitFor(() => {
213
+ expect(listWorkspaceTaskBoardSharesMock).toHaveBeenCalledWith(
214
+ 'ws-1',
215
+ 'board-1'
216
+ );
217
+ });
218
+ await waitFor(() => {
219
+ expect(
220
+ screen.getByRole('button', {
221
+ name: /ws-task-boards.share.guests.title/,
222
+ })
223
+ ).toHaveTextContent('1');
224
+ });
225
+
226
+ fireEvent.click(
227
+ screen.getByRole('button', {
228
+ name: /ws-task-boards.share.guests.title/,
229
+ })
230
+ );
231
+ fireEvent.change(
232
+ screen.getByPlaceholderText('ws-task-boards.share.email_placeholder'),
233
+ {
234
+ target: { value: 'new@example.com' },
235
+ }
236
+ );
237
+ fireEvent.click(screen.getByText('common.share'));
238
+
239
+ await waitFor(() => {
240
+ expect(createWorkspaceTaskBoardShareMock).toHaveBeenCalledWith(
241
+ 'ws-1',
242
+ 'board-1',
243
+ { email: 'new@example.com', permission: 'view' }
244
+ );
245
+ });
246
+
247
+ expect(await screen.findAllByText('guest@example.com')).toHaveLength(2);
248
+
249
+ fireEvent.change(
250
+ screen.getAllByLabelText('ws-task-boards.share.permission.view').at(-1)!,
251
+ { target: { value: 'edit' } }
252
+ );
253
+ await waitFor(() => {
254
+ expect(updateWorkspaceTaskBoardShareMock).toHaveBeenCalledWith(
255
+ 'ws-1',
256
+ 'board-1',
257
+ { shareId: 'share-1', permission: 'edit' }
258
+ );
259
+ });
260
+
261
+ fireEvent.click(screen.getByLabelText('common.remove'));
262
+ await waitFor(() => {
263
+ expect(deleteWorkspaceTaskBoardShareMock).toHaveBeenCalledWith(
264
+ 'ws-1',
265
+ 'board-1',
266
+ 'share-1'
267
+ );
268
+ });
269
+ });
270
+ });
@@ -0,0 +1,231 @@
1
+ 'use client';
2
+
3
+ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
4
+ import {
5
+ ChevronDown,
6
+ Copy,
7
+ ExternalLink,
8
+ Globe2,
9
+ Info,
10
+ Loader2,
11
+ Trash2,
12
+ } from '@tuturuuu/icons';
13
+ import {
14
+ disableWorkspaceTaskBoardPublicLink,
15
+ enableWorkspaceTaskBoardPublicLink,
16
+ getWorkspaceTaskBoardPublicLink,
17
+ type WorkspaceTaskBoardPublicLink,
18
+ } from '@tuturuuu/internal-api/tasks';
19
+ import { Badge } from '@tuturuuu/ui/badge';
20
+ import { Button } from '@tuturuuu/ui/button';
21
+ import {
22
+ Collapsible,
23
+ CollapsibleContent,
24
+ CollapsibleTrigger,
25
+ } from '@tuturuuu/ui/collapsible';
26
+ import { Input } from '@tuturuuu/ui/input';
27
+ import {
28
+ Tooltip,
29
+ TooltipContent,
30
+ TooltipProvider,
31
+ TooltipTrigger,
32
+ } from '@tuturuuu/ui/tooltip';
33
+ import { cn } from '@tuturuuu/utils/format';
34
+ import { useLocale, useTranslations } from 'next-intl';
35
+ import { useState } from 'react';
36
+ import { toast } from 'sonner';
37
+
38
+ interface BoardPublicLinkSectionProps {
39
+ boardId: string;
40
+ open: boolean;
41
+ wsId: string;
42
+ }
43
+
44
+ function buildPublicBoardUrl(
45
+ locale: string,
46
+ link: WorkspaceTaskBoardPublicLink | null
47
+ ) {
48
+ if (!link?.code) return '';
49
+
50
+ const path = `/${locale}/shared/task-boards/${link.code}`;
51
+ if (typeof window === 'undefined') return path;
52
+ return `${window.location.origin}${path}`;
53
+ }
54
+
55
+ export function BoardPublicLinkSection({
56
+ boardId,
57
+ open,
58
+ wsId,
59
+ }: BoardPublicLinkSectionProps) {
60
+ const t = useTranslations();
61
+ const locale = useLocale();
62
+ const queryClient = useQueryClient();
63
+ const [sectionOpen, setSectionOpen] = useState(false);
64
+ const queryKey = ['task-board-public-link', wsId, boardId] as const;
65
+
66
+ const publicLinkQuery = useQuery({
67
+ queryKey,
68
+ queryFn: () => getWorkspaceTaskBoardPublicLink(wsId, boardId),
69
+ enabled: open,
70
+ staleTime: 60_000,
71
+ });
72
+
73
+ const enableMutation = useMutation({
74
+ mutationFn: () => enableWorkspaceTaskBoardPublicLink(wsId, boardId),
75
+ onSuccess: () => {
76
+ void queryClient.invalidateQueries({ queryKey });
77
+ toast.success(t('ws-task-boards.share.public.enabled'));
78
+ },
79
+ onError: () => {
80
+ toast.error(t('ws-task-boards.share.public.enable_failed'));
81
+ },
82
+ });
83
+
84
+ const disableMutation = useMutation({
85
+ mutationFn: () => disableWorkspaceTaskBoardPublicLink(wsId, boardId),
86
+ onSuccess: () => {
87
+ void queryClient.invalidateQueries({ queryKey });
88
+ toast.success(t('ws-task-boards.share.public.disabled'));
89
+ },
90
+ onError: () => {
91
+ toast.error(t('ws-task-boards.share.public.disable_failed'));
92
+ },
93
+ });
94
+
95
+ const publicLink = publicLinkQuery.data?.publicLink ?? null;
96
+ const publicUrl = buildPublicBoardUrl(locale, publicLink);
97
+ const isMutating = enableMutation.isPending || disableMutation.isPending;
98
+ const statusBadge = publicLinkQuery.isLoading ? (
99
+ <Badge variant="secondary" className="gap-1 px-2 py-0.5 text-[10px]">
100
+ <Loader2 className="h-3 w-3 animate-spin" />
101
+ {t('common.loading')}
102
+ </Badge>
103
+ ) : publicLink ? (
104
+ <Badge className="bg-dynamic-green/10 px-2 py-0.5 text-[10px] text-dynamic-green">
105
+ {t('common.enabled')}
106
+ </Badge>
107
+ ) : (
108
+ <Badge variant="secondary" className="px-2 py-0.5 text-[10px]">
109
+ {t('common.disabled')}
110
+ </Badge>
111
+ );
112
+
113
+ async function copyPublicUrl() {
114
+ if (!publicUrl) return;
115
+
116
+ try {
117
+ await navigator.clipboard.writeText(publicUrl);
118
+ toast.success(t('ws-task-boards.share.public.copy_success'));
119
+ } catch {
120
+ toast.error(t('ws-task-boards.share.public.copy_failed'));
121
+ }
122
+ }
123
+
124
+ function openPublicUrl() {
125
+ if (!publicUrl || typeof window === 'undefined') return;
126
+ window.open(publicUrl, '_blank', 'noopener,noreferrer');
127
+ }
128
+
129
+ return (
130
+ <Collapsible
131
+ open={sectionOpen}
132
+ onOpenChange={setSectionOpen}
133
+ className="rounded-md border"
134
+ >
135
+ <div className="flex min-h-11 items-center gap-2 px-3">
136
+ <CollapsibleTrigger asChild>
137
+ <button
138
+ type="button"
139
+ className="flex min-w-0 flex-1 items-center gap-2 text-left transition-colors hover:text-foreground"
140
+ >
141
+ <Globe2 className="h-4 w-4 text-muted-foreground" />
142
+ <span className="min-w-0 flex-1 truncate font-medium text-sm">
143
+ {t('ws-task-boards.share.public.title')}
144
+ </span>
145
+ {statusBadge}
146
+ <ChevronDown
147
+ className={cn(
148
+ 'h-4 w-4 shrink-0 text-muted-foreground transition-transform',
149
+ sectionOpen && 'rotate-180'
150
+ )}
151
+ />
152
+ </button>
153
+ </CollapsibleTrigger>
154
+ <TooltipProvider delayDuration={0} skipDelayDuration={0}>
155
+ <Tooltip>
156
+ <TooltipTrigger asChild>
157
+ <button
158
+ type="button"
159
+ className="text-muted-foreground transition-colors hover:text-foreground"
160
+ aria-label={t('ws-task-boards.share.note')}
161
+ >
162
+ <Info className="h-3.5 w-3.5" />
163
+ </button>
164
+ </TooltipTrigger>
165
+ <TooltipContent className="max-w-xs">
166
+ {t('ws-task-boards.share.public.tooltip')}
167
+ </TooltipContent>
168
+ </Tooltip>
169
+ </TooltipProvider>
170
+ </div>
171
+
172
+ <CollapsibleContent className="border-t p-3">
173
+ {publicLinkQuery.isLoading ? (
174
+ <div className="flex items-center gap-2 rounded-md border border-dashed p-3 text-muted-foreground text-sm">
175
+ <Loader2 className="h-4 w-4 animate-spin" />
176
+ {t('common.loading')}
177
+ </div>
178
+ ) : publicLink ? (
179
+ <div className="grid gap-2 sm:grid-cols-[1fr_auto_auto_auto]">
180
+ <Input value={publicUrl} readOnly className="min-w-0" />
181
+ <Button
182
+ type="button"
183
+ variant="outline"
184
+ onClick={copyPublicUrl}
185
+ disabled={!publicUrl}
186
+ >
187
+ <Copy className="h-4 w-4" />
188
+ {t('ws-task-boards.share.public.copy')}
189
+ </Button>
190
+ <Button
191
+ type="button"
192
+ variant="outline"
193
+ onClick={openPublicUrl}
194
+ disabled={!publicUrl}
195
+ >
196
+ <ExternalLink className="h-4 w-4" />
197
+ {t('ws-task-boards.share.public.open')}
198
+ </Button>
199
+ <Button
200
+ type="button"
201
+ variant="outline"
202
+ onClick={() => disableMutation.mutate()}
203
+ disabled={isMutating}
204
+ >
205
+ {disableMutation.isPending ? (
206
+ <Loader2 className="h-4 w-4 animate-spin" />
207
+ ) : (
208
+ <Trash2 className="h-4 w-4" />
209
+ )}
210
+ {t('ws-task-boards.share.public.disable')}
211
+ </Button>
212
+ </div>
213
+ ) : (
214
+ <Button
215
+ type="button"
216
+ variant="outline"
217
+ onClick={() => enableMutation.mutate()}
218
+ disabled={isMutating}
219
+ >
220
+ {enableMutation.isPending ? (
221
+ <Loader2 className="h-4 w-4 animate-spin" />
222
+ ) : (
223
+ <Globe2 className="h-4 w-4" />
224
+ )}
225
+ {t('ws-task-boards.share.public.enable')}
226
+ </Button>
227
+ )}
228
+ </CollapsibleContent>
229
+ </Collapsible>
230
+ );
231
+ }