@tuturuuu/ui 0.38.0 → 0.39.1
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 +34 -0
- package/package.json +8 -8
- package/src/components/ui/custom/public-profile-menu-item.tsx +25 -0
- package/src/components/ui/custom/satellite-user-menu-items.test.tsx +61 -0
- package/src/components/ui/custom/satellite-user-menu-items.tsx +8 -0
- package/src/components/ui/finance/invoices/attendance-calendar.test.tsx +294 -0
- package/src/components/ui/finance/invoices/attendance-calendar.tsx +14 -6
- package/src/components/ui/finance/invoices/components/invoice-history-actor.test.tsx +341 -0
- package/src/components/ui/finance/invoices/components/invoice-history-date.test.tsx +173 -0
- package/src/components/ui/finance/invoices/components/invoice-history-error.test.tsx +269 -0
- package/src/components/ui/finance/invoices/components/invoice-history-recovery.tsx +47 -0
- package/src/components/ui/finance/invoices/components/invoice-user-history-accordion.tsx +43 -10
- package/src/components/ui/finance/invoices/components/subscription-create-action.tsx +42 -0
- package/src/components/ui/finance/invoices/hooks/customer-search-scope.test.tsx +404 -0
- package/src/components/ui/finance/invoices/hooks/invoice-actor-lifetime-key.ts +11 -0
- package/src/components/ui/finance/invoices/hooks/use-infinite-user-invoices.ts +48 -0
- package/src/components/ui/finance/invoices/hooks/use-invoice-customer-search.test.tsx +6 -1
- package/src/components/ui/finance/invoices/hooks/use-invoice-customer-search.ts +58 -6
- package/src/components/ui/finance/invoices/hooks/use-subscription-auto-selection.test.tsx +34 -0
- package/src/components/ui/finance/invoices/hooks/use-subscription-auto-selection.ts +8 -2
- package/src/components/ui/finance/invoices/hooks/use-subscription-create.ts +219 -0
- package/src/components/ui/finance/invoices/hooks/use-subscription-invoice-context.ts +59 -0
- package/src/components/ui/finance/invoices/hooks/use-user-groups.ts +38 -0
- package/src/components/ui/finance/invoices/hooks.ts +3 -100
- package/src/components/ui/finance/invoices/invoiceId/compact-invoice-template.tsx +2 -7
- package/src/components/ui/finance/invoices/invoiceId/format-invoice-template-date.ts +13 -0
- package/src/components/ui/finance/invoices/invoiceId/full-invoice-template.tsx +2 -7
- package/src/components/ui/finance/invoices/invoiceId/invoice-card-date.test.tsx +169 -0
- package/src/components/ui/finance/invoices/invoiceId/invoice-card-storage.test.tsx +120 -0
- package/src/components/ui/finance/invoices/invoiceId/invoice-card.tsx +25 -62
- package/src/components/ui/finance/invoices/invoiceId/invoice-details-page.tsx +1 -0
- package/src/components/ui/finance/invoices/invoiceId/invoice-png-lifetime.test.tsx +489 -0
- package/src/components/ui/finance/invoices/invoiceId/use-invoice-png-export.ts +184 -0
- package/src/components/ui/finance/invoices/subscription-admission.test.ts +77 -0
- package/src/components/ui/finance/invoices/subscription-admission.ts +101 -0
- package/src/components/ui/finance/invoices/subscription-billing-groups.test.ts +162 -1
- package/src/components/ui/finance/invoices/subscription-billing-groups.ts +50 -9
- package/src/components/ui/finance/invoices/subscription-context-actor.test.tsx +246 -0
- package/src/components/ui/finance/invoices/subscription-create-scope.test.tsx +562 -0
- package/src/components/ui/finance/invoices/subscription-invoice.test.tsx +88 -6
- package/src/components/ui/finance/invoices/subscription-invoice.tsx +76 -135
- package/src/components/ui/finance/invoices/types.ts +3 -3
- package/src/components/ui/finance/invoices/user-groups-actor.test.tsx +334 -0
- package/src/components/ui/finance/wallets/checkpoints/wallet-checkpoint-adjustment-dialog.tsx +47 -10
- package/src/components/ui/finance/wallets/checkpoints/wallet-checkpoints.test.tsx +95 -1
- package/src/components/ui/legacy/calendar/agenda-view.tsx +4 -1
- package/src/components/ui/legacy/calendar/all-day-event-bar.tsx +33 -369
- package/src/components/ui/legacy/calendar/all-day-event-layout.test.ts +94 -0
- package/src/components/ui/legacy/calendar/all-day-event-layout.ts +322 -0
- package/src/components/ui/legacy/calendar/calendar-views.test.tsx +58 -27
- package/src/components/ui/legacy/calendar/event-card.test.tsx +25 -1
- package/src/components/ui/legacy/calendar/event-card.tsx +10 -12
- package/src/components/ui/legacy/calendar/event-modal-header.tsx +17 -4
- package/src/components/ui/legacy/calendar/event-modal.tsx +26 -1554
- package/src/components/ui/legacy/calendar/legacy-event-modal.tsx +1559 -0
- package/src/components/ui/legacy/calendar/month-calendar.tsx +5 -2
- package/src/components/ui/legacy/calendar/native-recurrence-context-menu.tsx +21 -0
- package/src/components/ui/legacy/calendar/native-recurrence-dialog.test.tsx +245 -0
- package/src/components/ui/legacy/calendar/native-recurrence-dialog.tsx +95 -0
- package/src/components/ui/legacy/calendar/native-recurrence-fields.tsx +137 -0
- package/src/components/ui/legacy/calendar/native-recurrence-form.tsx +340 -0
- package/src/components/ui/legacy/calendar/native-recurrence-model.test.ts +234 -0
- package/src/components/ui/legacy/calendar/native-recurrence-model.ts +245 -0
- package/src/components/ui/legacy/calendar/native-recurrence-pattern-fields.test.tsx +142 -0
- package/src/components/ui/legacy/calendar/native-recurrence-pattern-fields.tsx +178 -0
- package/src/components/ui/legacy/calendar/native-recurrence-pattern-model.test.ts +205 -0
- package/src/components/ui/legacy/calendar/native-recurrence-provider-routing.test.tsx +255 -0
- package/src/components/ui/legacy/calendar/past-event-treatment.test.ts +137 -0
- package/src/components/ui/legacy/calendar/past-event-treatment.ts +25 -0
- package/src/components/ui/legacy/calendar/provider-readonly-dialog.test.tsx +52 -0
- package/src/components/ui/legacy/calendar/provider-readonly-dialog.tsx +48 -0
- package/src/components/ui/legacy/calendar/use-calendar-draft-save.test.tsx +1 -1
- package/src/components/ui/legacy/calendar/use-calendar-draft-save.tsx +1 -1
- package/src/components/ui/legacy/calendar/use-provider-recurrence-operation.test.tsx +185 -0
- package/src/components/ui/legacy/calendar/use-provider-recurrence-operation.ts +186 -0
- package/src/components/ui/public-link-button.test.tsx +116 -0
- package/src/components/ui/public-link-button.tsx +81 -0
- package/src/components/ui/text-editor/editor.tsx +3 -0
- package/src/components/ui/text-editor/fixed-toolbar-contents.test.tsx +59 -0
- package/src/components/ui/text-editor/fixed-toolbar-contents.tsx +156 -0
- package/src/components/ui/text-editor/tool-bar.tsx +18 -74
- package/src/hooks/__tests__/calendar-event-write-payload-readonly.test.ts +40 -0
- package/src/hooks/__tests__/native-calendar-mutation-guard.test.ts +45 -0
- package/src/hooks/__tests__/supabase-provider.test.ts +101 -7
- package/src/hooks/__tests__/use-calendar-readonly.test.tsx +27 -0
- package/src/hooks/__tests__/use-local-storage.test.tsx +42 -0
- package/src/hooks/__tests__/use-native-calendar-occurrences.test.tsx +140 -0
- package/src/hooks/__tests__/use-yjs-collaboration.test.tsx +39 -0
- package/src/hooks/calendar-connection-types.ts +49 -0
- package/src/hooks/calendar-event-update-queue-types.ts +12 -0
- package/src/hooks/calendar-event-write-payload.ts +33 -0
- package/src/hooks/collaboration-document-hydration.ts +35 -0
- package/src/hooks/supabase-provider.ts +39 -41
- package/src/hooks/use-calendar-sync.tsx +41 -62
- package/src/hooks/use-calendar.tsx +24 -38
- package/src/hooks/use-local-storage.ts +9 -11
- package/src/hooks/use-native-calendar-occurrences.ts +85 -0
- package/src/hooks/use-yjs-collaboration.ts +23 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import type { CalendarEvent } from '@tuturuuu/types/primitives/calendar-event';
|
|
3
|
+
import { Dialog, DialogContent } from '@tuturuuu/ui/dialog';
|
|
4
|
+
import { useFormatter } from 'next-intl';
|
|
5
|
+
import { EventModalHeader } from './event-modal-header';
|
|
6
|
+
|
|
7
|
+
/** Unsupported provider rules never mount the ordinary editable event form. */
|
|
8
|
+
export function ProviderReadonlyDialog({
|
|
9
|
+
event,
|
|
10
|
+
open,
|
|
11
|
+
onOpenChange,
|
|
12
|
+
}: {
|
|
13
|
+
event: CalendarEvent;
|
|
14
|
+
open: boolean;
|
|
15
|
+
onOpenChange: (open: boolean) => void;
|
|
16
|
+
}) {
|
|
17
|
+
const format = useFormatter();
|
|
18
|
+
return (
|
|
19
|
+
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
20
|
+
<DialogContent className="max-w-lg gap-0 overflow-hidden p-0">
|
|
21
|
+
<EventModalHeader event={event} isEditing />
|
|
22
|
+
<div className="space-y-4 px-6 py-5">
|
|
23
|
+
<p className="text-muted-foreground text-sm">
|
|
24
|
+
<time dateTime={event.start_at}>
|
|
25
|
+
{format.dateTime(new Date(event.start_at), {
|
|
26
|
+
dateStyle: 'medium',
|
|
27
|
+
timeStyle: 'short',
|
|
28
|
+
})}
|
|
29
|
+
</time>
|
|
30
|
+
{' – '}
|
|
31
|
+
<time dateTime={event.end_at}>
|
|
32
|
+
{format.dateTime(new Date(event.end_at), {
|
|
33
|
+
dateStyle: 'medium',
|
|
34
|
+
timeStyle: 'short',
|
|
35
|
+
})}
|
|
36
|
+
</time>
|
|
37
|
+
</p>
|
|
38
|
+
{event.location && <p className="text-sm">{event.location}</p>}
|
|
39
|
+
{event.description && (
|
|
40
|
+
<p className="max-h-64 overflow-auto whitespace-pre-wrap text-sm">
|
|
41
|
+
{event.description}
|
|
42
|
+
</p>
|
|
43
|
+
)}
|
|
44
|
+
</div>
|
|
45
|
+
</DialogContent>
|
|
46
|
+
</Dialog>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
import { act, renderHook } from '@testing-library/react';
|
|
3
|
-
import { expect, it, vi } from 'vitest';
|
|
4
3
|
import type { CalendarEvent } from '@tuturuuu/types/primitives/calendar-event';
|
|
4
|
+
import { expect, it, vi } from 'vitest';
|
|
5
5
|
import { useCalendarDraftSave } from './use-calendar-draft-save';
|
|
6
6
|
|
|
7
7
|
const query = vi.hoisted(() => ({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useQuery } from '@tanstack/react-query';
|
|
2
2
|
import {
|
|
3
|
-
getGoogleCalendarColorOptions,
|
|
4
3
|
type CalendarSourceOption,
|
|
4
|
+
getGoogleCalendarColorOptions,
|
|
5
5
|
} from '@tuturuuu/internal-api';
|
|
6
6
|
import type { CalendarEvent } from '@tuturuuu/types/primitives/calendar-event';
|
|
7
7
|
import { Button } from '@tuturuuu/ui/button';
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
2
|
+
import { act, renderHook, waitFor } from '@testing-library/react';
|
|
3
|
+
import { InternalApiError } from '@tuturuuu/internal-api/client';
|
|
4
|
+
import type { PropsWithChildren } from 'react';
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
|
|
7
|
+
const mocks = vi.hoisted(() => ({
|
|
8
|
+
reserve: vi.fn(),
|
|
9
|
+
read: vi.fn(),
|
|
10
|
+
retry: vi.fn(),
|
|
11
|
+
}));
|
|
12
|
+
vi.mock('@tuturuuu/internal-api/calendar-provider-series', () => ({
|
|
13
|
+
reserveCalendarProviderSeriesOperation: mocks.reserve,
|
|
14
|
+
getCalendarProviderSeriesOperation: mocks.read,
|
|
15
|
+
retryCalendarProviderSeriesOperation: mocks.retry,
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
import { useProviderRecurrenceOperation } from './use-provider-recurrence-operation';
|
|
19
|
+
|
|
20
|
+
const clients: QueryClient[] = [];
|
|
21
|
+
const payload = {
|
|
22
|
+
requestId: '11111111-1111-4111-8111-111111111111',
|
|
23
|
+
action: 'create' as const,
|
|
24
|
+
source: { provider: 'google' as const, connectionId: 'connection' },
|
|
25
|
+
rule: {
|
|
26
|
+
version: 1 as const,
|
|
27
|
+
timeZone: 'UTC',
|
|
28
|
+
frequency: 'daily' as const,
|
|
29
|
+
interval: 1,
|
|
30
|
+
end: { type: 'never' as const },
|
|
31
|
+
},
|
|
32
|
+
anchor: {
|
|
33
|
+
startLocal: '2026-10-06T09:00:00',
|
|
34
|
+
endLocal: '2026-10-06T10:00:00',
|
|
35
|
+
allDay: false,
|
|
36
|
+
},
|
|
37
|
+
event: { title: 'Test series' },
|
|
38
|
+
};
|
|
39
|
+
function setup(
|
|
40
|
+
client = new QueryClient({ defaultOptions: { queries: { retry: false } } }),
|
|
41
|
+
actorId = 'actor'
|
|
42
|
+
) {
|
|
43
|
+
clients.push(client);
|
|
44
|
+
const applied = vi.fn(),
|
|
45
|
+
assertActive = vi.fn();
|
|
46
|
+
const actor = {
|
|
47
|
+
actorId,
|
|
48
|
+
lifetime: { active: true },
|
|
49
|
+
assertActive,
|
|
50
|
+
} as Parameters<typeof useProviderRecurrenceOperation>[0]['actor'];
|
|
51
|
+
const wrapper = ({ children }: PropsWithChildren) => (
|
|
52
|
+
<QueryClientProvider client={client}>{children}</QueryClientProvider>
|
|
53
|
+
);
|
|
54
|
+
const hook = renderHook(
|
|
55
|
+
() =>
|
|
56
|
+
useProviderRecurrenceOperation({
|
|
57
|
+
wsId: 'workspace',
|
|
58
|
+
actor,
|
|
59
|
+
identity: 'new',
|
|
60
|
+
onApplied: applied,
|
|
61
|
+
}),
|
|
62
|
+
{ wrapper }
|
|
63
|
+
);
|
|
64
|
+
return { ...hook, client, applied, assertActive };
|
|
65
|
+
}
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
vi.clearAllMocks();
|
|
68
|
+
sessionStorage.clear();
|
|
69
|
+
mocks.read.mockResolvedValue({
|
|
70
|
+
operationId: '11111111-1111-4111-8111-111111111111',
|
|
71
|
+
status: 'pending',
|
|
72
|
+
});
|
|
73
|
+
mocks.reserve.mockResolvedValue({
|
|
74
|
+
operationId: '11111111-1111-4111-8111-111111111111',
|
|
75
|
+
status: 'pending',
|
|
76
|
+
});
|
|
77
|
+
mocks.retry.mockResolvedValue({
|
|
78
|
+
operationId: '11111111-1111-4111-8111-111111111111',
|
|
79
|
+
status: 'pending',
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
afterEach(() => {
|
|
83
|
+
for (const client of clients.splice(0)) client.clear();
|
|
84
|
+
});
|
|
85
|
+
describe('recoverable provider operation UI state', () => {
|
|
86
|
+
it('does not finish a pending reservation and retries the exact confirmed operation', async () => {
|
|
87
|
+
const h = setup();
|
|
88
|
+
act(() => h.result.current.submission.mutate(payload));
|
|
89
|
+
await waitFor(() => expect(h.result.current.pending).toBe(true));
|
|
90
|
+
await waitFor(() =>
|
|
91
|
+
expect(h.result.current.submission.isSuccess).toBe(true)
|
|
92
|
+
);
|
|
93
|
+
expect(h.applied).not.toHaveBeenCalled();
|
|
94
|
+
act(() => h.result.current.retry());
|
|
95
|
+
await waitFor(() =>
|
|
96
|
+
expect(mocks.retry).toHaveBeenCalledWith(
|
|
97
|
+
'workspace',
|
|
98
|
+
'11111111-1111-4111-8111-111111111111'
|
|
99
|
+
)
|
|
100
|
+
);
|
|
101
|
+
expect(mocks.reserve).toHaveBeenCalledTimes(1);
|
|
102
|
+
h.unmount();
|
|
103
|
+
});
|
|
104
|
+
it('retains an ambiguous admission across dialog dismissal and never creates a new intent', async () => {
|
|
105
|
+
mocks.reserve.mockRejectedValue(new Error('Response lost'));
|
|
106
|
+
const h = setup();
|
|
107
|
+
act(() => h.result.current.submission.mutate(payload));
|
|
108
|
+
await waitFor(() => expect(h.result.current.submission.isError).toBe(true));
|
|
109
|
+
h.unmount();
|
|
110
|
+
const reopened = setup(h.client);
|
|
111
|
+
expect(reopened.result.current.pending).toBe(true);
|
|
112
|
+
mocks.reserve.mockResolvedValue({
|
|
113
|
+
operationId: '11111111-1111-4111-8111-111111111111',
|
|
114
|
+
status: 'pending',
|
|
115
|
+
});
|
|
116
|
+
act(() => reopened.result.current.retry());
|
|
117
|
+
await waitFor(() => expect(mocks.reserve).toHaveBeenCalledTimes(2));
|
|
118
|
+
expect(mocks.reserve.mock.calls[1]).toEqual(['workspace', payload]);
|
|
119
|
+
reopened.unmount();
|
|
120
|
+
});
|
|
121
|
+
it('finishes only a matching applied receipt and clears the retained intent', async () => {
|
|
122
|
+
mocks.reserve.mockResolvedValue({
|
|
123
|
+
operationId: '11111111-1111-4111-8111-111111111111',
|
|
124
|
+
status: 'applied',
|
|
125
|
+
result: {},
|
|
126
|
+
});
|
|
127
|
+
const h = setup();
|
|
128
|
+
act(() => h.result.current.submission.mutate(payload));
|
|
129
|
+
await waitFor(() => expect(h.applied).toHaveBeenCalledTimes(1));
|
|
130
|
+
expect(h.result.current.pending).toBe(false);
|
|
131
|
+
h.unmount();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('recovers only the operation UUID after reload without persisting event contents', async () => {
|
|
135
|
+
const h = setup();
|
|
136
|
+
act(() => h.result.current.submission.mutate(payload));
|
|
137
|
+
await waitFor(() =>
|
|
138
|
+
expect(h.result.current.submission.isSuccess).toBe(true)
|
|
139
|
+
);
|
|
140
|
+
expect(JSON.stringify(sessionStorage)).not.toContain('Test series');
|
|
141
|
+
h.unmount();
|
|
142
|
+
const restored = setup();
|
|
143
|
+
expect(restored.result.current.pending).toBe(true);
|
|
144
|
+
act(() => restored.result.current.retry());
|
|
145
|
+
await waitFor(() =>
|
|
146
|
+
expect(mocks.retry).toHaveBeenCalledWith('workspace', payload.requestId)
|
|
147
|
+
);
|
|
148
|
+
expect(mocks.reserve).toHaveBeenCalledTimes(1);
|
|
149
|
+
restored.unmount();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('releases a completed preflight rejection only after an authoritative absent operation', async () => {
|
|
153
|
+
mocks.reserve.mockRejectedValue(new InternalApiError('Unsupported', 422));
|
|
154
|
+
mocks.read.mockRejectedValue(new InternalApiError('Absent', 404));
|
|
155
|
+
const h = setup();
|
|
156
|
+
act(() => h.result.current.submission.mutate(payload));
|
|
157
|
+
await waitFor(() => expect(h.result.current.submission.isError).toBe(true));
|
|
158
|
+
expect(h.result.current.pending).toBe(false);
|
|
159
|
+
expect(sessionStorage.length).toBe(0);
|
|
160
|
+
h.unmount();
|
|
161
|
+
});
|
|
162
|
+
it('blocks dispatch when UUID recovery storage is unavailable', async () => {
|
|
163
|
+
const storage = vi
|
|
164
|
+
.spyOn(Storage.prototype, 'setItem')
|
|
165
|
+
.mockImplementation(() => {
|
|
166
|
+
throw new Error('Storage denied');
|
|
167
|
+
});
|
|
168
|
+
const h = setup();
|
|
169
|
+
act(() => h.result.current.submission.mutate(payload));
|
|
170
|
+
await waitFor(() => expect(h.result.current.submission.isError).toBe(true));
|
|
171
|
+
expect(mocks.reserve).not.toHaveBeenCalled();
|
|
172
|
+
expect(h.result.current.pending).toBe(false);
|
|
173
|
+
h.unmount();
|
|
174
|
+
storage.mockRestore();
|
|
175
|
+
});
|
|
176
|
+
it('does not carry another actor’s pending draft into the new session', async () => {
|
|
177
|
+
const h = setup();
|
|
178
|
+
act(() => h.result.current.submission.mutate(payload));
|
|
179
|
+
await waitFor(() => expect(h.result.current.pending).toBe(true));
|
|
180
|
+
h.unmount();
|
|
181
|
+
const other = setup(h.client, 'another-actor');
|
|
182
|
+
expect(other.result.current.pending).toBe(false);
|
|
183
|
+
other.unmount();
|
|
184
|
+
});
|
|
185
|
+
});
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
3
|
+
import {
|
|
4
|
+
type CalendarProviderSeriesOperationPayload,
|
|
5
|
+
type CalendarProviderSeriesOperationResult,
|
|
6
|
+
getCalendarProviderSeriesOperation,
|
|
7
|
+
reserveCalendarProviderSeriesOperation,
|
|
8
|
+
retryCalendarProviderSeriesOperation,
|
|
9
|
+
} from '@tuturuuu/internal-api/calendar-provider-series';
|
|
10
|
+
import { InternalApiError } from '@tuturuuu/internal-api/client';
|
|
11
|
+
import { useEffect, useMemo } from 'react';
|
|
12
|
+
import type { useWorkspaceActor } from '../../../../hooks/use-workspace-visibility';
|
|
13
|
+
|
|
14
|
+
type Pending = {
|
|
15
|
+
operationId: string;
|
|
16
|
+
payload?: CalendarProviderSeriesOperationPayload;
|
|
17
|
+
confirmed: boolean;
|
|
18
|
+
};
|
|
19
|
+
/** Retained within the actor-scoped query cache so dismissing a pending dialog cannot create another intent. */
|
|
20
|
+
export function useProviderRecurrenceOperation({
|
|
21
|
+
wsId,
|
|
22
|
+
actor,
|
|
23
|
+
identity,
|
|
24
|
+
onApplied,
|
|
25
|
+
}: {
|
|
26
|
+
wsId: string;
|
|
27
|
+
actor: NonNullable<ReturnType<typeof useWorkspaceActor>>;
|
|
28
|
+
identity: string;
|
|
29
|
+
onApplied: () => void;
|
|
30
|
+
}) {
|
|
31
|
+
const client = useQueryClient();
|
|
32
|
+
const key = useMemo(
|
|
33
|
+
() => ['calendar-provider-pending', wsId, actor.actorId, identity],
|
|
34
|
+
[wsId, actor.actorId, identity]
|
|
35
|
+
);
|
|
36
|
+
const storageKey = `calendar-provider-operation:${wsId}:${actor.actorId}:${identity}`;
|
|
37
|
+
const retained = useQuery<Pending | null>({
|
|
38
|
+
queryKey: key,
|
|
39
|
+
queryFn: () => null,
|
|
40
|
+
enabled: false,
|
|
41
|
+
initialData: () => {
|
|
42
|
+
try {
|
|
43
|
+
const id = sessionStorage.getItem(storageKey);
|
|
44
|
+
return id && /^[0-9a-f]{8}-[0-9a-f-]{27,40}$/i.test(id)
|
|
45
|
+
? { operationId: id, confirmed: true }
|
|
46
|
+
: null;
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
gcTime: Infinity,
|
|
52
|
+
});
|
|
53
|
+
const pending = retained.data;
|
|
54
|
+
const status = useQuery({
|
|
55
|
+
queryKey: [
|
|
56
|
+
'calendar-provider-operation',
|
|
57
|
+
wsId,
|
|
58
|
+
actor.actorId,
|
|
59
|
+
pending?.operationId,
|
|
60
|
+
],
|
|
61
|
+
enabled: !!pending,
|
|
62
|
+
queryFn: async ({ signal }) => {
|
|
63
|
+
actor.assertActive();
|
|
64
|
+
const value = await getCalendarProviderSeriesOperation(
|
|
65
|
+
wsId,
|
|
66
|
+
pending!.operationId,
|
|
67
|
+
{ signal }
|
|
68
|
+
);
|
|
69
|
+
actor.assertActive();
|
|
70
|
+
return value;
|
|
71
|
+
},
|
|
72
|
+
retry: false,
|
|
73
|
+
refetchInterval: (query) => {
|
|
74
|
+
if (query.state.data?.status === 'applied') return false;
|
|
75
|
+
const error = query.state.error;
|
|
76
|
+
if (
|
|
77
|
+
error instanceof InternalApiError &&
|
|
78
|
+
[401, 403, 404, 409, 422, 429].includes(error.status)
|
|
79
|
+
)
|
|
80
|
+
return false;
|
|
81
|
+
// Network/server failures need an explicit retry, not a repeated request storm.
|
|
82
|
+
return error ? false : 2000;
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
const submission = useMutation({
|
|
86
|
+
mutationFn: async (payload?: CalendarProviderSeriesOperationPayload) => {
|
|
87
|
+
actor.assertActive();
|
|
88
|
+
const current = client.getQueryData<Pending | null>(key);
|
|
89
|
+
const intent = current?.payload ?? payload;
|
|
90
|
+
const operationId = current?.operationId ?? intent?.requestId;
|
|
91
|
+
if (!operationId) throw new Error('No provider operation');
|
|
92
|
+
// UUID only: preserve recovery across reloads without storing event content or credentials.
|
|
93
|
+
// If storage is unavailable, fail before admitting a request that cannot be recovered.
|
|
94
|
+
sessionStorage.setItem(storageKey, operationId);
|
|
95
|
+
// Retain before sending: a failed response may follow a successful remote reservation.
|
|
96
|
+
client.setQueryData<Pending>(key, {
|
|
97
|
+
operationId,
|
|
98
|
+
payload: intent,
|
|
99
|
+
confirmed: current?.confirmed ?? false,
|
|
100
|
+
});
|
|
101
|
+
let value: CalendarProviderSeriesOperationResult;
|
|
102
|
+
try {
|
|
103
|
+
value =
|
|
104
|
+
current?.confirmed || !intent
|
|
105
|
+
? await retryCalendarProviderSeriesOperation(wsId, operationId)
|
|
106
|
+
: await reserveCalendarProviderSeriesOperation(wsId, intent);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
// Only a completed rejection plus authoritative absence can release an intent.
|
|
109
|
+
// Transport errors retain it because the server may already have reserved it.
|
|
110
|
+
if (
|
|
111
|
+
!current?.confirmed &&
|
|
112
|
+
error instanceof InternalApiError &&
|
|
113
|
+
[400, 403, 404, 409, 422].includes(error.status)
|
|
114
|
+
) {
|
|
115
|
+
try {
|
|
116
|
+
await getCalendarProviderSeriesOperation(wsId, operationId);
|
|
117
|
+
} catch (lookupError) {
|
|
118
|
+
actor.assertActive();
|
|
119
|
+
if (
|
|
120
|
+
lookupError instanceof InternalApiError &&
|
|
121
|
+
lookupError.status === 404
|
|
122
|
+
) {
|
|
123
|
+
sessionStorage.removeItem(storageKey);
|
|
124
|
+
client.setQueryData(key, null);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
actor.assertActive();
|
|
131
|
+
const operationKey = [
|
|
132
|
+
'calendar-provider-operation',
|
|
133
|
+
wsId,
|
|
134
|
+
actor.actorId,
|
|
135
|
+
operationId,
|
|
136
|
+
];
|
|
137
|
+
const observed =
|
|
138
|
+
client.getQueryData<CalendarProviderSeriesOperationResult>(
|
|
139
|
+
operationKey
|
|
140
|
+
);
|
|
141
|
+
if (
|
|
142
|
+
observed?.status === 'applied' &&
|
|
143
|
+
observed.operationId === operationId
|
|
144
|
+
)
|
|
145
|
+
return observed;
|
|
146
|
+
client.setQueryData<Pending>(key, {
|
|
147
|
+
operationId,
|
|
148
|
+
payload: intent,
|
|
149
|
+
confirmed: true,
|
|
150
|
+
});
|
|
151
|
+
client.setQueryData<CalendarProviderSeriesOperationResult>(
|
|
152
|
+
['calendar-provider-operation', wsId, actor.actorId, operationId],
|
|
153
|
+
value
|
|
154
|
+
);
|
|
155
|
+
return value;
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
const receipt =
|
|
159
|
+
status.data?.status === 'applied' ? status.data : submission.data;
|
|
160
|
+
const applied =
|
|
161
|
+
!!pending &&
|
|
162
|
+
receipt?.status === 'applied' &&
|
|
163
|
+
receipt.operationId === pending.operationId;
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
if (!applied) return;
|
|
166
|
+
try {
|
|
167
|
+
actor.assertActive();
|
|
168
|
+
} catch {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (!client.getQueryData<Pending | null>(key)) return;
|
|
172
|
+
try {
|
|
173
|
+
sessionStorage.removeItem(storageKey);
|
|
174
|
+
} catch {
|
|
175
|
+
/* An applied UUID is safe to recover again. */
|
|
176
|
+
}
|
|
177
|
+
client.setQueryData(key, null);
|
|
178
|
+
onApplied();
|
|
179
|
+
}, [applied, actor, client, key, storageKey, onApplied]);
|
|
180
|
+
return {
|
|
181
|
+
pending: !!pending,
|
|
182
|
+
submission,
|
|
183
|
+
status,
|
|
184
|
+
retry: () => submission.mutate(undefined),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, type ComponentProps } from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
|
|
5
|
+
import { PublicLinkButton } from './public-link-button';
|
|
6
|
+
|
|
7
|
+
vi.mock('./button', () => ({
|
|
8
|
+
Button: ({
|
|
9
|
+
variant: _variant,
|
|
10
|
+
...props
|
|
11
|
+
}: ComponentProps<'button'> & { variant?: string }) => <button {...props} />,
|
|
12
|
+
}));
|
|
13
|
+
vi.mock('./input', () => ({
|
|
14
|
+
Input: (props: ComponentProps<'input'>) => <input {...props} />,
|
|
15
|
+
}));
|
|
16
|
+
const container = document.createElement('div');
|
|
17
|
+
document.body.append(container);
|
|
18
|
+
let root = createRoot(container);
|
|
19
|
+
const copy = vi.fn(),
|
|
20
|
+
url = 'https://tuturuuu.com/u/creator';
|
|
21
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
Object.defineProperty(navigator, 'clipboard', {
|
|
24
|
+
configurable: true,
|
|
25
|
+
value: { writeText: copy },
|
|
26
|
+
});
|
|
27
|
+
copy.mockResolvedValue(undefined);
|
|
28
|
+
});
|
|
29
|
+
afterEach(async () => {
|
|
30
|
+
await act(() => root.unmount());
|
|
31
|
+
root = createRoot(container);
|
|
32
|
+
vi.clearAllMocks();
|
|
33
|
+
});
|
|
34
|
+
async function render(link: string | null = url) {
|
|
35
|
+
await act(() =>
|
|
36
|
+
root.render(
|
|
37
|
+
<PublicLinkButton
|
|
38
|
+
url={link}
|
|
39
|
+
label="Copy link"
|
|
40
|
+
copiedLabel="Copied"
|
|
41
|
+
errorLabel="Failed"
|
|
42
|
+
manualCopyLabel="Manual link"
|
|
43
|
+
/>
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
async function click() {
|
|
48
|
+
await act(() => container.querySelector('button')!.click());
|
|
49
|
+
}
|
|
50
|
+
it('copies only after an explicit click and announces success', async () => {
|
|
51
|
+
await render();
|
|
52
|
+
expect(copy).not.toHaveBeenCalled();
|
|
53
|
+
expect(container.querySelector('input')).toBeNull();
|
|
54
|
+
await click();
|
|
55
|
+
expect(copy).toHaveBeenCalledWith(url);
|
|
56
|
+
expect(container.querySelector('[role=status]')!.textContent).toBe('Copied');
|
|
57
|
+
});
|
|
58
|
+
it('excludes invalid/private URLs entirely', async () => {
|
|
59
|
+
await render('https://tuturuuu.com/private/settings');
|
|
60
|
+
expect(container.querySelector('button')).toBeNull();
|
|
61
|
+
expect(copy).not.toHaveBeenCalled();
|
|
62
|
+
});
|
|
63
|
+
it('supports manual selection and retry after a clipboard denial', async () => {
|
|
64
|
+
await render();
|
|
65
|
+
copy.mockRejectedValueOnce(new Error('Denied'));
|
|
66
|
+
await click();
|
|
67
|
+
expect(container.querySelector('[role=alert]')!.textContent).toBe('Failed');
|
|
68
|
+
const input = container.querySelector('input')!;
|
|
69
|
+
expect(input.value).toBe(url);
|
|
70
|
+
expect(input.readOnly).toBe(true);
|
|
71
|
+
await act(() => input.focus());
|
|
72
|
+
expect(input.selectionEnd).toBe(url.length);
|
|
73
|
+
await click();
|
|
74
|
+
expect(container.querySelector('input')).toBeNull();
|
|
75
|
+
expect(container.querySelector('[role=status]')!.textContent).toBe('Copied');
|
|
76
|
+
});
|
|
77
|
+
it('provides manual copy when Clipboard API is unavailable', async () => {
|
|
78
|
+
Object.defineProperty(navigator, 'clipboard', {
|
|
79
|
+
configurable: true,
|
|
80
|
+
value: undefined,
|
|
81
|
+
});
|
|
82
|
+
await render();
|
|
83
|
+
await click();
|
|
84
|
+
expect(container.querySelector('input')!.value).toBe(url);
|
|
85
|
+
});
|
|
86
|
+
it('fences rapid duplicate clicks and suppresses stale success after URL replacement', async () => {
|
|
87
|
+
let finish!: () => void;
|
|
88
|
+
copy.mockReturnValue(
|
|
89
|
+
new Promise<void>((resolve) => {
|
|
90
|
+
finish = resolve;
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
await render();
|
|
94
|
+
await act(() => {
|
|
95
|
+
container.querySelector('button')!.click();
|
|
96
|
+
container.querySelector('button')!.click();
|
|
97
|
+
});
|
|
98
|
+
expect(copy).toHaveBeenCalledTimes(1);
|
|
99
|
+
await render('https://tuturuuu.com/u/other');
|
|
100
|
+
await act(() => finish());
|
|
101
|
+
expect(container.querySelector('[role=status]')).toBeNull();
|
|
102
|
+
expect(container.querySelector('input')).toBeNull();
|
|
103
|
+
});
|
|
104
|
+
it('suppresses stale failure after unmount', async () => {
|
|
105
|
+
let fail!: (error: Error) => void;
|
|
106
|
+
copy.mockReturnValue(
|
|
107
|
+
new Promise<void>((_, reject) => {
|
|
108
|
+
fail = reject;
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
await render();
|
|
112
|
+
await act(() => container.querySelector('button')!.click());
|
|
113
|
+
await act(() => root.render(null));
|
|
114
|
+
await act(() => fail(new Error('Denied')));
|
|
115
|
+
expect(container.innerHTML).toBe('');
|
|
116
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { safePublicContentLink } from '@tuturuuu/utils/public-content-link';
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { Button } from './button';
|
|
5
|
+
import { Input } from './input';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
url: string | null;
|
|
9
|
+
label: string;
|
|
10
|
+
copiedLabel: string;
|
|
11
|
+
errorLabel: string;
|
|
12
|
+
manualCopyLabel: string;
|
|
13
|
+
};
|
|
14
|
+
export function PublicLinkButton(props: Props) {
|
|
15
|
+
const url = safePublicContentLink(props.url);
|
|
16
|
+
return url ? <CopyButton key={url} {...props} url={url} /> : null;
|
|
17
|
+
}
|
|
18
|
+
function CopyButton({
|
|
19
|
+
url,
|
|
20
|
+
label,
|
|
21
|
+
copiedLabel,
|
|
22
|
+
errorLabel,
|
|
23
|
+
manualCopyLabel,
|
|
24
|
+
}: Props & { url: string }) {
|
|
25
|
+
const [status, setStatus] = useState<
|
|
26
|
+
'idle' | 'pending' | 'copied' | 'failed'
|
|
27
|
+
>('idle');
|
|
28
|
+
const active = useRef(true),
|
|
29
|
+
busy = useRef(false);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
active.current = true;
|
|
32
|
+
return () => {
|
|
33
|
+
active.current = false;
|
|
34
|
+
};
|
|
35
|
+
}, []);
|
|
36
|
+
return (
|
|
37
|
+
<div className="space-y-2">
|
|
38
|
+
<Button
|
|
39
|
+
variant="outline"
|
|
40
|
+
disabled={status === 'pending'}
|
|
41
|
+
onClick={async () => {
|
|
42
|
+
if (busy.current) return;
|
|
43
|
+
busy.current = true;
|
|
44
|
+
setStatus('pending');
|
|
45
|
+
try {
|
|
46
|
+
if (!navigator.clipboard?.writeText)
|
|
47
|
+
throw new Error('Clipboard unavailable');
|
|
48
|
+
await navigator.clipboard.writeText(url);
|
|
49
|
+
if (active.current) setStatus('copied');
|
|
50
|
+
} catch {
|
|
51
|
+
if (active.current) setStatus('failed');
|
|
52
|
+
} finally {
|
|
53
|
+
busy.current = false;
|
|
54
|
+
}
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
{label}
|
|
58
|
+
</Button>
|
|
59
|
+
{status === 'copied' && (
|
|
60
|
+
<p role="status" className="text-muted-foreground text-sm">
|
|
61
|
+
{copiedLabel}
|
|
62
|
+
</p>
|
|
63
|
+
)}
|
|
64
|
+
{status === 'failed' && (
|
|
65
|
+
<>
|
|
66
|
+
<p role="alert" className="text-sm">
|
|
67
|
+
{errorLabel}
|
|
68
|
+
</p>
|
|
69
|
+
<label className="block space-y-1 text-sm">
|
|
70
|
+
{manualCopyLabel}
|
|
71
|
+
<Input
|
|
72
|
+
readOnly
|
|
73
|
+
value={url}
|
|
74
|
+
onFocus={(event) => event.target.select()}
|
|
75
|
+
/>
|
|
76
|
+
</label>
|
|
77
|
+
</>
|
|
78
|
+
)}
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -132,6 +132,7 @@ export interface RichTextEditorProps {
|
|
|
132
132
|
};
|
|
133
133
|
renderTaskMention?: TaskMentionNodeViewRenderer;
|
|
134
134
|
toolbarLeadingContent?: React.ReactNode;
|
|
135
|
+
toolbarToolsLabel?: string;
|
|
135
136
|
toggleBlockLabel?: string;
|
|
136
137
|
copyLabels?: EditorCopyLabels;
|
|
137
138
|
}
|
|
@@ -164,6 +165,7 @@ export function RichTextEditor({
|
|
|
164
165
|
mentionTranslations,
|
|
165
166
|
renderTaskMention,
|
|
166
167
|
toolbarLeadingContent,
|
|
168
|
+
toolbarToolsLabel,
|
|
167
169
|
toggleBlockLabel,
|
|
168
170
|
copyLabels,
|
|
169
171
|
}: RichTextEditorProps) {
|
|
@@ -651,6 +653,7 @@ export function RichTextEditor({
|
|
|
651
653
|
onImageUpload={onImageUpload}
|
|
652
654
|
onConvertToTask={onConvertToTask}
|
|
653
655
|
leadingContent={toolbarLeadingContent}
|
|
656
|
+
toolsLabel={toolbarToolsLabel}
|
|
654
657
|
toggleBlockLabel={toggleBlockLabel}
|
|
655
658
|
copyLabels={copyLabels}
|
|
656
659
|
/>
|