@peers-app/peers-ui 0.27.3 → 0.27.4
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/dist/screens/network-viewer/network-viewer-ipc.d.ts +3 -1
- package/dist/screens/network-viewer/network-viewer-ipc.js +6 -0
- package/dist/screens/network-viewer/sync-recovery.js +103 -1
- package/dist/screens/variables/variable-details.js +2 -1
- package/dist/tabs-layout/network-status-indicator.js +26 -12
- package/dist/tabs-layout/use-network-status.d.ts +6 -1
- package/dist/tabs-layout/use-network-status.js +27 -4
- package/package.json +9 -3
- package/.claude/settings.local.json +0 -34
- package/.github/README.md +0 -52
- package/.github/workflows/delete-all-artifacts.yml +0 -49
- package/.github/workflows/publish.yml +0 -51
- package/babel.config.js +0 -7
- package/biome.json +0 -198
- package/dist/app-updates/app-updates-consumer.test.d.ts +0 -1
- package/dist/app-updates/app-updates-consumer.test.js +0 -56
- package/dist/app-updates/app-updates-settings.test.d.ts +0 -1
- package/dist/app-updates/app-updates-settings.test.js +0 -93
- package/dist/app-updates/remote-app-update-panel.test.d.ts +0 -1
- package/dist/app-updates/remote-app-update-panel.test.js +0 -165
- package/dist/components/access-level-field.test.d.ts +0 -1
- package/dist/components/access-level-field.test.js +0 -28
- package/dist/components/message-logs/tool-access-approval-card.test.d.ts +0 -1
- package/dist/components/message-logs/tool-access-approval-card.test.js +0 -102
- package/dist/components/responsive-section-nav.test.d.ts +0 -1
- package/dist/components/responsive-section-nav.test.js +0 -45
- package/dist/globals-hash.test.d.ts +0 -1
- package/dist/globals-hash.test.js +0 -16
- package/dist/hooks/use-observable-state.test.d.ts +0 -1
- package/dist/hooks/use-observable-state.test.js +0 -64
- package/dist/hooks/use-observable.test.d.ts +0 -1
- package/dist/hooks/use-observable.test.js +0 -191
- package/dist/hooks/use-rows.test.d.ts +0 -1
- package/dist/hooks/use-rows.test.js +0 -175
- package/dist/hooks/use-tool.test.d.ts +0 -1
- package/dist/hooks/use-tool.test.js +0 -190
- package/dist/host-shell/host-shell-consumer.test.d.ts +0 -1
- package/dist/host-shell/host-shell-consumer.test.js +0 -28
- package/dist/root-layout/root-layout-host.test.d.ts +0 -1
- package/dist/root-layout/root-layout-host.test.js +0 -86
- package/dist/screens/account/account-screen.test.d.ts +0 -1
- package/dist/screens/account/account-screen.test.js +0 -51
- package/dist/screens/assistants/assistant-config.test.d.ts +0 -1
- package/dist/screens/assistants/assistant-config.test.js +0 -57
- package/dist/screens/contacts/contact-list.test.d.ts +0 -1
- package/dist/screens/contacts/contact-list.test.js +0 -48
- package/dist/screens/device-pairing/device-pairing.test.d.ts +0 -1
- package/dist/screens/device-pairing/device-pairing.test.js +0 -119
- package/dist/screens/devices/devices-list.test.d.ts +0 -1
- package/dist/screens/devices/devices-list.test.js +0 -53
- package/dist/screens/groups/group-list.test.d.ts +0 -1
- package/dist/screens/groups/group-list.test.js +0 -38
- package/dist/screens/identity/identity-routes.test.d.ts +0 -1
- package/dist/screens/identity/identity-routes.test.js +0 -51
- package/dist/screens/identity/identity-screen.test.d.ts +0 -1
- package/dist/screens/identity/identity-screen.test.js +0 -103
- package/dist/screens/invites/accept-invite.test.d.ts +0 -1
- package/dist/screens/invites/accept-invite.test.js +0 -103
- package/dist/screens/invites/activity-view.test.d.ts +0 -1
- package/dist/screens/invites/activity-view.test.js +0 -108
- package/dist/screens/invites/invite-classify.test.d.ts +0 -1
- package/dist/screens/invites/invite-classify.test.js +0 -115
- package/dist/screens/network-viewer/network-viewer-ipc.test.d.ts +0 -1
- package/dist/screens/network-viewer/network-viewer-ipc.test.js +0 -61
- package/dist/screens/network-viewer/network-viewer.section.test.d.ts +0 -1
- package/dist/screens/network-viewer/network-viewer.section.test.js +0 -63
- package/dist/screens/network-viewer/sync-recovery.test.d.ts +0 -1
- package/dist/screens/network-viewer/sync-recovery.test.js +0 -104
- package/dist/screens/packages/package-helpers.test.d.ts +0 -1
- package/dist/screens/packages/package-helpers.test.js +0 -53
- package/dist/screens/packages/package-runtime-status.test.d.ts +0 -1
- package/dist/screens/packages/package-runtime-status.test.js +0 -50
- package/dist/screens/packages/packages-ipc.test.d.ts +0 -1
- package/dist/screens/packages/packages-ipc.test.js +0 -43
- package/dist/screens/settings/settings-page.test.d.ts +0 -1
- package/dist/screens/settings/settings-page.test.js +0 -19
- package/dist/screens/tools/tool-access-ipc.test.d.ts +0 -1
- package/dist/screens/tools/tool-access-ipc.test.js +0 -40
- package/dist/screens/tools/tool-catalog-ipc.test.d.ts +0 -1
- package/dist/screens/tools/tool-catalog-ipc.test.js +0 -52
- package/dist/tabs-layout/network-status-indicator.test.d.ts +0 -1
- package/dist/tabs-layout/network-status-indicator.test.js +0 -665
- package/dist/tabs-layout/tabs-state.test.d.ts +0 -1
- package/dist/tabs-layout/tabs-state.test.js +0 -110
- package/dist/tabs-layout/use-network-status.test.d.ts +0 -1
- package/dist/tabs-layout/use-network-status.test.js +0 -45
- package/dist/ui-router/ui-loader.test.d.ts +0 -1
- package/dist/ui-router/ui-loader.test.js +0 -91
- package/jest.config.js +0 -25
- package/release-guard.js +0 -10
- package/src/app-updates/app-update-controls.tsx +0 -73
- package/src/app-updates/app-updates-consumer.test.ts +0 -83
- package/src/app-updates/app-updates-consumer.ts +0 -121
- package/src/app-updates/app-updates-settings.test.tsx +0 -109
- package/src/app-updates/app-updates-settings.tsx +0 -136
- package/src/app-updates/remote-app-update-panel.test.tsx +0 -205
- package/src/app-updates/remote-app-update-panel.tsx +0 -210
- package/src/app-updates/use-app-update-status.ts +0 -16
- package/src/command-palette/command-palette-ui.tsx +0 -564
- package/src/command-palette/command-palette.ts +0 -242
- package/src/components/access-level-field.test.tsx +0 -32
- package/src/components/access-level-field.tsx +0 -68
- package/src/components/checkbox.tsx +0 -25
- package/src/components/group-switcher.tsx +0 -526
- package/src/components/input-date.tsx +0 -29
- package/src/components/input-number.tsx +0 -83
- package/src/components/input.tsx +0 -25
- package/src/components/inverse-lazy-list.tsx +0 -107
- package/src/components/io-schema-values.tsx +0 -103
- package/src/components/io-schema.tsx +0 -259
- package/src/components/lazy-list.tsx +0 -115
- package/src/components/list-screen.tsx +0 -126
- package/src/components/loading-indicator.tsx +0 -7
- package/src/components/markdown-editor/autolink-plugin.tsx +0 -29
- package/src/components/markdown-editor/editor-inline.tsx +0 -9
- package/src/components/markdown-editor/editor.tsx +0 -158
- package/src/components/markdown-editor/markdown-plugin.tsx +0 -202
- package/src/components/markdown-editor/mention-node.ts +0 -204
- package/src/components/markdown-editor/mentions-plugin.tsx +0 -354
- package/src/components/markdown-editor/move-line-plugin.tsx +0 -186
- package/src/components/markdown-editor/select-line-boundary-plugin.tsx +0 -95
- package/src/components/markdown-editor/theme.ts +0 -46
- package/src/components/markdown-editor/toolbar.tsx +0 -269
- package/src/components/markdown-with-mentions.tsx +0 -198
- package/src/components/message-logs/message-logs.tsx +0 -523
- package/src/components/message-logs/tool-access-approval-card.test.tsx +0 -127
- package/src/components/message-logs/tool-access-approval-card.tsx +0 -178
- package/src/components/messages/avatar.tsx +0 -171
- package/src/components/messages/channel-message-list.tsx +0 -189
- package/src/components/messages/channel-view.tsx +0 -92
- package/src/components/messages/message-compose.tsx +0 -192
- package/src/components/messages/message-display.tsx +0 -231
- package/src/components/messages/thread-message-list.tsx +0 -135
- package/src/components/qr-scanner.tsx +0 -180
- package/src/components/responsive-section-nav.test.tsx +0 -88
- package/src/components/responsive-section-nav.tsx +0 -92
- package/src/components/router.tsx +0 -175
- package/src/components/save-button.tsx +0 -134
- package/src/components/sortable-list.tsx +0 -130
- package/src/components/tabs.tsx +0 -76
- package/src/components/tooltip.tsx +0 -43
- package/src/components/trust-level-badge.tsx +0 -44
- package/src/components/trust-level-dropdown.tsx +0 -136
- package/src/components/typeahead.tsx +0 -357
- package/src/globals-hash.test.ts +0 -19
- package/src/globals.tsx +0 -226
- package/src/hooks/index.ts +0 -8
- package/src/hooks/use-host-contract.ts +0 -75
- package/src/hooks/use-observable-state.test.tsx +0 -101
- package/src/hooks/use-observable-state.ts +0 -29
- package/src/hooks/use-observable.test.tsx +0 -258
- package/src/hooks/use-observable.ts +0 -67
- package/src/hooks/use-on-screen.ts +0 -24
- package/src/hooks/use-promise.ts +0 -34
- package/src/hooks/use-rows.test.tsx +0 -196
- package/src/hooks/use-rows.ts +0 -120
- package/src/hooks/use-subscription.ts +0 -24
- package/src/hooks/use-tool.test.tsx +0 -225
- package/src/hooks/use-tool.ts +0 -116
- package/src/host-shell/host-shell-consumer.test.ts +0 -32
- package/src/host-shell/host-shell-consumer.ts +0 -53
- package/src/index.tsx +0 -42
- package/src/mention-configs.ts +0 -185
- package/src/operator-console/operator-console-state.ts +0 -119
- package/src/operator-console/operator-console.tsx +0 -233
- package/src/peers-services-registration.ts +0 -6
- package/src/root-layout/global-overlays.ts +0 -50
- package/src/root-layout/layout-picker.tsx +0 -47
- package/src/root-layout/layouts/full-screen-layout.tsx +0 -144
- package/src/root-layout/layouts/tabs-with-console-layout.tsx +0 -260
- package/src/root-layout/root-layout-host.test.tsx +0 -108
- package/src/root-layout/root-layout-host.tsx +0 -147
- package/src/root-layout/root-layout-registry.ts +0 -51
- package/src/root-layout/root-layout-state.ts +0 -55
- package/src/root-layout/root-layout.ts +0 -32
- package/src/screens/account/account-screen.test.tsx +0 -65
- package/src/screens/account/account-screen.tsx +0 -942
- package/src/screens/assistants/assistant-config.test.tsx +0 -54
- package/src/screens/assistants/assistant-config.tsx +0 -121
- package/src/screens/assistants/assistant-details.tsx +0 -89
- package/src/screens/assistants/assistant-info.tsx +0 -66
- package/src/screens/assistants/assistant-list.tsx +0 -145
- package/src/screens/assistants/assistant-tools.tsx +0 -82
- package/src/screens/console-logs/console-logs-list.tsx +0 -374
- package/src/screens/console-logs/log-display.tsx +0 -137
- package/src/screens/console-logs/log-filters.tsx +0 -64
- package/src/screens/console-logs/mobile-log-card.tsx +0 -161
- package/src/screens/console-logs/resizable-table-header.tsx +0 -110
- package/src/screens/contacts/contact-details.tsx +0 -123
- package/src/screens/contacts/contact-list.test.tsx +0 -59
- package/src/screens/contacts/contact-list.tsx +0 -286
- package/src/screens/contacts/index.ts +0 -2
- package/src/screens/data-explorer/data-explorer.tsx +0 -633
- package/src/screens/data-explorer/index.ts +0 -6
- package/src/screens/data-explorer/query-executor.tsx +0 -520
- package/src/screens/device-pairing/device-pairing.test.tsx +0 -143
- package/src/screens/device-pairing/device-pairing.tsx +0 -461
- package/src/screens/device-pairing/identity-ipc.ts +0 -25
- package/src/screens/device-pairing/index.ts +0 -2
- package/src/screens/device-pairing/use-device-pairing-state.ts +0 -15
- package/src/screens/devices/devices-list.test.tsx +0 -68
- package/src/screens/devices/devices-list.tsx +0 -365
- package/src/screens/devices/index.ts +0 -1
- package/src/screens/groups/group-details.tsx +0 -160
- package/src/screens/groups/group-invite-panel.tsx +0 -311
- package/src/screens/groups/group-list.test.tsx +0 -44
- package/src/screens/groups/group-list.tsx +0 -317
- package/src/screens/groups/group-members.tsx +0 -343
- package/src/screens/groups/index.ts +0 -3
- package/src/screens/identity/identity-routes.test.ts +0 -70
- package/src/screens/identity/identity-routes.ts +0 -301
- package/src/screens/identity/identity-screen.test.tsx +0 -138
- package/src/screens/identity/identity-screen.tsx +0 -282
- package/src/screens/identity/index.ts +0 -2
- package/src/screens/identity/invite-contact-panel.tsx +0 -45
- package/src/screens/identity/profile-invite.tsx +0 -93
- package/src/screens/invites/accept-invite.test.tsx +0 -115
- package/src/screens/invites/accept-invite.tsx +0 -318
- package/src/screens/invites/activity-view.test.tsx +0 -127
- package/src/screens/invites/activity-view.tsx +0 -162
- package/src/screens/invites/index.ts +0 -6
- package/src/screens/invites/invite-capture.ts +0 -104
- package/src/screens/invites/invite-classify.test.ts +0 -129
- package/src/screens/invites/invite-share.tsx +0 -104
- package/src/screens/invites/invites-ipc.ts +0 -25
- package/src/screens/invites/pending-invites-list.tsx +0 -256
- package/src/screens/network-viewer/connection-troubleshooter.tsx +0 -395
- package/src/screens/network-viewer/cpu-usage-graph.tsx +0 -294
- package/src/screens/network-viewer/device-details-modal.tsx +0 -339
- package/src/screens/network-viewer/group-details-modal.tsx +0 -421
- package/src/screens/network-viewer/index.ts +0 -8
- package/src/screens/network-viewer/network-viewer-ipc.test.ts +0 -72
- package/src/screens/network-viewer/network-viewer-ipc.ts +0 -39
- package/src/screens/network-viewer/network-viewer-section.ts +0 -12
- package/src/screens/network-viewer/network-viewer.section.test.tsx +0 -68
- package/src/screens/network-viewer/network-viewer.tsx +0 -708
- package/src/screens/network-viewer/remote-logs-panel.tsx +0 -190
- package/src/screens/network-viewer/sync-recovery.test.tsx +0 -114
- package/src/screens/network-viewer/sync-recovery.tsx +0 -461
- package/src/screens/network-viewer/usage-graph.tsx +0 -455
- package/src/screens/packages/local-folder-grants-panel.tsx +0 -290
- package/src/screens/packages/local-folders-ipc.ts +0 -28
- package/src/screens/packages/package-details.tsx +0 -166
- package/src/screens/packages/package-helpers.test.ts +0 -57
- package/src/screens/packages/package-helpers.ts +0 -137
- package/src/screens/packages/package-info.tsx +0 -354
- package/src/screens/packages/package-list.tsx +0 -519
- package/src/screens/packages/package-network-panel.tsx +0 -82
- package/src/screens/packages/package-new-local.tsx +0 -100
- package/src/screens/packages/package-runtime-status.test.tsx +0 -58
- package/src/screens/packages/package-runtime-status.tsx +0 -68
- package/src/screens/packages/package-versions.tsx +0 -298
- package/src/screens/packages/packages-ipc.test.ts +0 -47
- package/src/screens/packages/packages-ipc.ts +0 -125
- package/src/screens/peer-types/peer-type-details.tsx +0 -172
- package/src/screens/peer-types/peer-type-list.tsx +0 -64
- package/src/screens/search/global-search.tsx +0 -406
- package/src/screens/settings/color-mode-dropdown.tsx +0 -82
- package/src/screens/settings/settings-page.test.tsx +0 -24
- package/src/screens/settings/settings-page.tsx +0 -426
- package/src/screens/setup-user.tsx +0 -355
- package/src/screens/tools/tool-access-ipc.test.ts +0 -55
- package/src/screens/tools/tool-access-ipc.ts +0 -27
- package/src/screens/tools/tool-catalog-ipc.test.ts +0 -52
- package/src/screens/tools/tool-catalog-ipc.ts +0 -51
- package/src/screens/tools/tool-details.tsx +0 -52
- package/src/screens/tools/tool-info.tsx +0 -45
- package/src/screens/tools/tool-list.tsx +0 -106
- package/src/screens/tools/tool-schema.tsx +0 -44
- package/src/screens/tools/tool-test-details.tsx +0 -89
- package/src/screens/tools/tool-test-list.tsx +0 -73
- package/src/screens/variables/variable-details.tsx +0 -289
- package/src/screens/variables/variable-list.tsx +0 -110
- package/src/screens/welcome-modal.tsx +0 -294
- package/src/screens/workflows/workflow-details.tsx +0 -115
- package/src/screens/workflows/workflow-info.tsx +0 -22
- package/src/screens/workflows/workflow-instructions.tsx +0 -134
- package/src/screens/workflows/workflow-list.tsx +0 -117
- package/src/setupTests.ts +0 -38
- package/src/system-apps/assistants.app.ts +0 -7
- package/src/system-apps/console-logs.app.ts +0 -7
- package/src/system-apps/data-explorer.app.ts +0 -8
- package/src/system-apps/identity.app.ts +0 -9
- package/src/system-apps/index.ts +0 -77
- package/src/system-apps/mobile-settings.app.ts +0 -7
- package/src/system-apps/network-viewer.app.ts +0 -8
- package/src/system-apps/packages.app.ts +0 -7
- package/src/system-apps/search.app.ts +0 -8
- package/src/system-apps/settings.app.ts +0 -7
- package/src/system-apps/threads.app.ts +0 -7
- package/src/system-apps/tools.app.ts +0 -7
- package/src/system-apps/types.app.ts +0 -7
- package/src/system-apps/variables.app.ts +0 -7
- package/src/system-apps/workflows.app.ts +0 -7
- package/src/tabs-layout/network-status-indicator.test.tsx +0 -799
- package/src/tabs-layout/network-status-indicator.tsx +0 -756
- package/src/tabs-layout/tabs-layout.tsx +0 -857
- package/src/tabs-layout/tabs-state.test.ts +0 -152
- package/src/tabs-layout/tabs-state.ts +0 -587
- package/src/tabs-layout/use-network-status.test.tsx +0 -58
- package/src/tabs-layout/use-network-status.ts +0 -68
- package/src/ui-defaults/index.ts +0 -2
- package/src/ui-defaults/list-screen.tsx +0 -94
- package/src/ui-defaults/markdown-field.tsx +0 -87
- package/src/ui-router/routes-loader.ts +0 -193
- package/src/ui-router/ui-loader.test.tsx +0 -108
- package/src/ui-router/ui-loader.tsx +0 -606
- package/src/utils.ts +0 -95
- package/tsconfig.json +0 -18
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Captures an inbound invite token from the page URL or a desktop `peers://` open-url event
|
|
3
|
-
* and holds it (tab-scoped) until the signed-in UI can route to the Accept screen.
|
|
4
|
-
*
|
|
5
|
-
* Tokens travel only in URL fragments and are stripped from the address bar immediately so
|
|
6
|
-
* startup route restoration never persists them.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { extractInviteTokenText, observable } from "@peers-app/peers-sdk";
|
|
10
|
-
|
|
11
|
-
/** sessionStorage key for a captured token awaiting the Accept screen. */
|
|
12
|
-
export const PENDING_INVITE_STORAGE_KEY = "peers.pendingInviteToken";
|
|
13
|
-
|
|
14
|
-
/** Fires whenever a new token is captured, so a mounted app can navigate immediately. */
|
|
15
|
-
export const inviteCaptured = observable<string | undefined>(undefined);
|
|
16
|
-
|
|
17
|
-
type IpcRendererLike = {
|
|
18
|
-
on: (channel: string, listener: (event: unknown, ...args: unknown[]) => void) => void;
|
|
19
|
-
removeAllListeners: (channel: string) => void;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Pull a token out of a URL fragment or deep link if one is present.
|
|
24
|
-
* Accepts `#invite=<token>`, `https://peers.app/i#<token>`, and `peers://i#<token>`.
|
|
25
|
-
*/
|
|
26
|
-
export function inviteTokenFromUrl(url: string): string | undefined {
|
|
27
|
-
const hash = url.indexOf("#");
|
|
28
|
-
if (hash < 0) {
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
const before = url.slice(0, hash);
|
|
32
|
-
const fragment = url.slice(hash + 1);
|
|
33
|
-
const isInviteFragment = fragment.startsWith("invite=");
|
|
34
|
-
const isLandingPage = /^peers:\/\/i\/?$/.test(before) || /^https?:\/\/[^/]+\/i\/?$/.test(before);
|
|
35
|
-
if (!isInviteFragment && !isLandingPage) {
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
return extractInviteTokenText(url);
|
|
40
|
-
} catch {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Store a token for the Accept screen and notify listeners. */
|
|
46
|
-
export function stashPendingInvite(token: string, storage: Storage = sessionStorage): void {
|
|
47
|
-
storage.setItem(PENDING_INVITE_STORAGE_KEY, token);
|
|
48
|
-
inviteCaptured(token);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Read the stored token without consuming it. */
|
|
52
|
-
export function peekPendingInvite(storage: Storage = sessionStorage): string | undefined {
|
|
53
|
-
return storage.getItem(PENDING_INVITE_STORAGE_KEY) ?? undefined;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Read and clear the stored token. */
|
|
57
|
-
export function consumePendingInvite(storage: Storage = sessionStorage): string | undefined {
|
|
58
|
-
const token = peekPendingInvite(storage);
|
|
59
|
-
storage.removeItem(PENDING_INVITE_STORAGE_KEY);
|
|
60
|
-
return token;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Capture `#invite=<token>` from the current location, strip it from the URL, and stash it.
|
|
65
|
-
* Safe to call repeatedly; returns the captured token when one was present.
|
|
66
|
-
*/
|
|
67
|
-
export function captureInviteFromLocation(
|
|
68
|
-
locationLike: Pick<Location, "href" | "pathname" | "search"> = window.location,
|
|
69
|
-
historyLike: Pick<History, "replaceState" | "state"> = window.history,
|
|
70
|
-
storage: Storage = sessionStorage,
|
|
71
|
-
): string | undefined {
|
|
72
|
-
const token = inviteTokenFromUrl(locationLike.href);
|
|
73
|
-
if (!token) {
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
historyLike.replaceState(
|
|
77
|
-
historyLike.state ?? null,
|
|
78
|
-
"",
|
|
79
|
-
`${locationLike.pathname}${locationLike.search}`,
|
|
80
|
-
);
|
|
81
|
-
stashPendingInvite(token, storage);
|
|
82
|
-
return token;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Listen for `peers://` links forwarded by the Electron main process (`peers-open-url`).
|
|
87
|
-
* No-op outside Electron. Returns an unsubscribe function.
|
|
88
|
-
*/
|
|
89
|
-
export function listenForOpenUrlInvites(): () => void {
|
|
90
|
-
const ipc = (window as Window & { ipcRenderer?: IpcRendererLike }).ipcRenderer;
|
|
91
|
-
if (!ipc) {
|
|
92
|
-
return () => {};
|
|
93
|
-
}
|
|
94
|
-
ipc.on("peers-open-url", (_event, url) => {
|
|
95
|
-
if (typeof url !== "string") {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const token = inviteTokenFromUrl(url);
|
|
99
|
-
if (token) {
|
|
100
|
-
stashPendingInvite(token);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
return () => ipc.removeAllListeners("peers-open-url");
|
|
104
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import type { IInvite } from "@peers-app/peers-sdk";
|
|
2
|
-
import { actionsForInvite, classifyInvite, describeInviteRow } from "./pending-invites-list";
|
|
3
|
-
|
|
4
|
-
function invite(
|
|
5
|
-
partial: Partial<IInvite> & Pick<IInvite, "inviteId" | "direction" | "type" | "mode">,
|
|
6
|
-
): IInvite {
|
|
7
|
-
return {
|
|
8
|
-
status: "pending",
|
|
9
|
-
epoch: 1,
|
|
10
|
-
createdAt: new Date("2026-01-01T00:00:00Z"),
|
|
11
|
-
expiresAt: new Date("2026-02-01T00:00:00Z"),
|
|
12
|
-
...partial,
|
|
13
|
-
} as IInvite;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
describe("classifyInvite", () => {
|
|
17
|
-
const counterpart = {
|
|
18
|
-
userId: "abcdefghijklmnopqrstuvwxy",
|
|
19
|
-
publicKey: "pk",
|
|
20
|
-
publicBoxKey: "box",
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
it("puts received decisions in attention", () => {
|
|
24
|
-
const profileRequest = invite({
|
|
25
|
-
inviteId: "1",
|
|
26
|
-
direction: "in",
|
|
27
|
-
type: "contact",
|
|
28
|
-
mode: "profile",
|
|
29
|
-
counterpart,
|
|
30
|
-
parentInviteId: "profileinvite0000000000001",
|
|
31
|
-
});
|
|
32
|
-
const directGroupInvite = invite({
|
|
33
|
-
inviteId: "2",
|
|
34
|
-
direction: "in",
|
|
35
|
-
type: "group",
|
|
36
|
-
mode: "direct",
|
|
37
|
-
counterpart,
|
|
38
|
-
});
|
|
39
|
-
const joinRequest = invite({
|
|
40
|
-
inviteId: "3",
|
|
41
|
-
direction: "in",
|
|
42
|
-
type: "group",
|
|
43
|
-
mode: "approve",
|
|
44
|
-
counterpart,
|
|
45
|
-
parentInviteId: "groupinvite00000000000001",
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
expect(classifyInvite(profileRequest)).toBe("attention");
|
|
49
|
-
expect(actionsForInvite(profileRequest)).toEqual(["accept", "decline"]);
|
|
50
|
-
expect(classifyInvite(directGroupInvite)).toBe("attention");
|
|
51
|
-
expect(actionsForInvite(directGroupInvite)).toEqual(["accept", "decline"]);
|
|
52
|
-
expect(classifyInvite(joinRequest)).toBe("attention");
|
|
53
|
-
expect(actionsForInvite(joinRequest)).toEqual(["approve", "deny"]);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("keeps locally initiated requests and unsupported device rows waiting", () => {
|
|
57
|
-
const contactRequest = invite({
|
|
58
|
-
inviteId: "4",
|
|
59
|
-
direction: "in",
|
|
60
|
-
type: "contact",
|
|
61
|
-
mode: "profile",
|
|
62
|
-
counterpart,
|
|
63
|
-
recipientUserId: counterpart.userId,
|
|
64
|
-
});
|
|
65
|
-
const groupRequest = invite({
|
|
66
|
-
inviteId: "5",
|
|
67
|
-
direction: "in",
|
|
68
|
-
type: "group",
|
|
69
|
-
mode: "approve",
|
|
70
|
-
counterpart,
|
|
71
|
-
recipientUserId: counterpart.userId,
|
|
72
|
-
});
|
|
73
|
-
const outbound = invite({
|
|
74
|
-
inviteId: "6",
|
|
75
|
-
direction: "out",
|
|
76
|
-
type: "group",
|
|
77
|
-
mode: "open",
|
|
78
|
-
});
|
|
79
|
-
const device = invite({
|
|
80
|
-
inviteId: "7",
|
|
81
|
-
direction: "in",
|
|
82
|
-
type: "device",
|
|
83
|
-
mode: "direct",
|
|
84
|
-
counterpart,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
expect(classifyInvite(contactRequest)).toBe("waiting");
|
|
88
|
-
expect(actionsForInvite(contactRequest)).toEqual([]);
|
|
89
|
-
expect(classifyInvite(groupRequest)).toBe("waiting");
|
|
90
|
-
expect(actionsForInvite(groupRequest)).toEqual([]);
|
|
91
|
-
expect(classifyInvite(outbound)).toBe("waiting");
|
|
92
|
-
expect(actionsForInvite(outbound)).toEqual(["revoke"]);
|
|
93
|
-
expect(classifyInvite(device)).toBe("waiting");
|
|
94
|
-
expect(actionsForInvite(device)).toEqual([]);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("puts terminal rows in history", () => {
|
|
98
|
-
expect(
|
|
99
|
-
classifyInvite(
|
|
100
|
-
invite({
|
|
101
|
-
inviteId: "8",
|
|
102
|
-
direction: "in",
|
|
103
|
-
type: "contact",
|
|
104
|
-
mode: "contact",
|
|
105
|
-
status: "accepted",
|
|
106
|
-
}),
|
|
107
|
-
),
|
|
108
|
-
).toBe("history");
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("describes an open join as automatic rather than approval-gated", () => {
|
|
112
|
-
const openJoin = invite({
|
|
113
|
-
inviteId: "openjoinrequest0000000001",
|
|
114
|
-
direction: "in",
|
|
115
|
-
type: "group",
|
|
116
|
-
mode: "open",
|
|
117
|
-
counterpart: { ...counterpart, displayName: "Ada" },
|
|
118
|
-
recipientUserId: counterpart.userId,
|
|
119
|
-
groupName: "Neighbors",
|
|
120
|
-
deliveryState: "queued",
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
expect(describeInviteRow(openJoin)).toEqual({
|
|
124
|
-
title: "Joining Neighbors",
|
|
125
|
-
detail: "Completing automatically; no approval is required.",
|
|
126
|
-
});
|
|
127
|
-
expect(classifyInvite(openJoin)).toBe("waiting");
|
|
128
|
-
});
|
|
129
|
-
});
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { copyToClipboard, type ICreatedInvite } from "@peers-app/peers-sdk";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import QRCode from "react-qr-code";
|
|
4
|
-
|
|
5
|
-
/** Props for {@link InviteShare}. */
|
|
6
|
-
export interface InviteShareProps {
|
|
7
|
-
invite: ICreatedInvite;
|
|
8
|
-
/** Short line under the heading explaining what accepting grants. */
|
|
9
|
-
description?: string;
|
|
10
|
-
/** Body text used by the native share sheet; defaults to a generic line. */
|
|
11
|
-
shareText?: string;
|
|
12
|
-
onDone?: () => void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function canNativeShare(): boolean {
|
|
16
|
-
return typeof navigator !== "undefined" && typeof navigator.share === "function";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Presents an issued invite as a QR code plus copyable link and token. The QR encodes the
|
|
21
|
-
* landing-page URL so phone cameras, the in-app scanner, and the desktop handler all work.
|
|
22
|
-
*/
|
|
23
|
-
export function InviteShare(props: InviteShareProps) {
|
|
24
|
-
const { invite } = props;
|
|
25
|
-
const [copied, setCopied] = useState<"link" | "token" | undefined>(undefined);
|
|
26
|
-
const expires = new Date(invite.token.expiresAt);
|
|
27
|
-
|
|
28
|
-
const copy = async (what: "link" | "token") => {
|
|
29
|
-
await copyToClipboard(what === "link" ? invite.url : invite.encoded);
|
|
30
|
-
setCopied(what);
|
|
31
|
-
window.setTimeout(() => setCopied(undefined), 1500);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const share = async () => {
|
|
35
|
-
try {
|
|
36
|
-
await navigator.share({
|
|
37
|
-
title: "Peers invite",
|
|
38
|
-
text: props.shareText ?? "Join me on Peers:",
|
|
39
|
-
url: invite.url,
|
|
40
|
-
});
|
|
41
|
-
} catch {
|
|
42
|
-
// User dismissed the share sheet; nothing to do.
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
return (
|
|
47
|
-
<div className="text-center" style={{ maxWidth: 440, margin: "0 auto" }}>
|
|
48
|
-
{props.description ? <p className="text-muted">{props.description}</p> : null}
|
|
49
|
-
<div className="d-inline-block bg-white rounded p-3 mb-2">
|
|
50
|
-
<QRCode value={invite.url} size={200} aria-label="Invite QR code" />
|
|
51
|
-
</div>
|
|
52
|
-
<p className="small text-muted mb-3">
|
|
53
|
-
Expires {expires.toLocaleString()}
|
|
54
|
-
{invite.token.uses === "unlimited" ? " · reusable" : " · single use"}
|
|
55
|
-
</p>
|
|
56
|
-
<div className="input-group input-group-sm mb-2">
|
|
57
|
-
<input
|
|
58
|
-
className="form-control font-monospace"
|
|
59
|
-
readOnly
|
|
60
|
-
value={invite.url}
|
|
61
|
-
aria-label="Invite link"
|
|
62
|
-
onFocus={(event) => event.currentTarget.select()}
|
|
63
|
-
/>
|
|
64
|
-
<button type="button" className="btn btn-outline-primary" onClick={() => void copy("link")}>
|
|
65
|
-
{copied === "link" ? "Copied" : "Copy link"}
|
|
66
|
-
</button>
|
|
67
|
-
</div>
|
|
68
|
-
<details className="text-start small mb-3">
|
|
69
|
-
<summary className="text-muted" style={{ cursor: "pointer" }}>
|
|
70
|
-
No camera or link? Share the code text instead
|
|
71
|
-
</summary>
|
|
72
|
-
<div className="input-group input-group-sm mt-2">
|
|
73
|
-
<input
|
|
74
|
-
className="form-control font-monospace"
|
|
75
|
-
readOnly
|
|
76
|
-
value={invite.encoded}
|
|
77
|
-
aria-label="Invite code"
|
|
78
|
-
onFocus={(event) => event.currentTarget.select()}
|
|
79
|
-
/>
|
|
80
|
-
<button
|
|
81
|
-
type="button"
|
|
82
|
-
className="btn btn-outline-secondary"
|
|
83
|
-
onClick={() => void copy("token")}
|
|
84
|
-
>
|
|
85
|
-
{copied === "token" ? "Copied" : "Copy"}
|
|
86
|
-
</button>
|
|
87
|
-
</div>
|
|
88
|
-
</details>
|
|
89
|
-
<div className="d-flex gap-2 justify-content-center">
|
|
90
|
-
{canNativeShare() ? (
|
|
91
|
-
<button type="button" className="btn btn-primary" onClick={() => void share()}>
|
|
92
|
-
<i className="bi bi-share me-1" />
|
|
93
|
-
Share…
|
|
94
|
-
</button>
|
|
95
|
-
) : null}
|
|
96
|
-
{props.onDone ? (
|
|
97
|
-
<button type="button" className="btn btn-outline-secondary" onClick={props.onDone}>
|
|
98
|
-
Done
|
|
99
|
-
</button>
|
|
100
|
-
) : null}
|
|
101
|
-
</div>
|
|
102
|
-
</div>
|
|
103
|
-
);
|
|
104
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getInvitesContractDefinition,
|
|
3
|
-
getUserContext,
|
|
4
|
-
hostContractConsumer,
|
|
5
|
-
type IInvitesConsumer,
|
|
6
|
-
} from "@peers-app/peers-sdk";
|
|
7
|
-
|
|
8
|
-
const invites = hostContractConsumer<IInvitesConsumer>(getInvitesContractDefinition(), {
|
|
9
|
-
dataContextId: async () => (await getUserContext()).userId,
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Return the typed local-host consumer for the System Invites contract.
|
|
14
|
-
*
|
|
15
|
-
* The consumer is cached per host transport and rebuilt if the transport is replaced
|
|
16
|
-
* (for example after a socket reconnect).
|
|
17
|
-
*/
|
|
18
|
-
export async function getInvitesConsumer(): Promise<IInvitesConsumer> {
|
|
19
|
-
return invites.get();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Shorthand for `(await getInvitesConsumer()).tools`. */
|
|
23
|
-
export async function inviteTools(): Promise<IInvitesConsumer["tools"]> {
|
|
24
|
-
return (await getInvitesConsumer()).tools;
|
|
25
|
-
}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getRoleLabel,
|
|
3
|
-
getUserContext,
|
|
4
|
-
type IInvite,
|
|
5
|
-
type InviteStatus,
|
|
6
|
-
Invites,
|
|
7
|
-
} from "@peers-app/peers-sdk";
|
|
8
|
-
import { useCallback, useEffect, useState } from "react";
|
|
9
|
-
import { inviteTools } from "./invites-ipc";
|
|
10
|
-
|
|
11
|
-
/** Filtered invite rows plus whether any non-pending row exists for the same type and group. */
|
|
12
|
-
export interface IInviteRowQuery {
|
|
13
|
-
/** Rows matching the status filter, newest first. */
|
|
14
|
-
rows: IInvite[];
|
|
15
|
-
/** True when at least one matching invite is not pending. */
|
|
16
|
-
hasHistory: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Subscribe to the personal `Invites` table.
|
|
21
|
-
*
|
|
22
|
-
* @param filter Type, group, and statuses to include. Statuses default to pending.
|
|
23
|
-
* @returns Matching rows and whether any non-pending row exists, or `undefined` while loading.
|
|
24
|
-
*/
|
|
25
|
-
export function useInviteRows(filter: {
|
|
26
|
-
type?: IInvite["type"];
|
|
27
|
-
groupId?: string;
|
|
28
|
-
statuses?: InviteStatus[];
|
|
29
|
-
}): IInviteRowQuery | undefined {
|
|
30
|
-
const [query, setQuery] = useState<IInviteRowQuery | undefined>(undefined);
|
|
31
|
-
const statuses = filter.statuses ?? ["pending"];
|
|
32
|
-
const statusKey = statuses.join(",");
|
|
33
|
-
|
|
34
|
-
const refresh = useCallback(async () => {
|
|
35
|
-
const userContext = await getUserContext();
|
|
36
|
-
const table = Invites(userContext.userDataContext);
|
|
37
|
-
const all = await table.list({
|
|
38
|
-
...(filter.type ? { type: filter.type } : {}),
|
|
39
|
-
...(filter.groupId ? { groupId: filter.groupId } : {}),
|
|
40
|
-
});
|
|
41
|
-
const wanted = new Set(statusKey.split(","));
|
|
42
|
-
setQuery({
|
|
43
|
-
rows: all
|
|
44
|
-
.filter((row) => wanted.has(row.status))
|
|
45
|
-
.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()),
|
|
46
|
-
hasHistory: all.some((row) => row.status !== "pending"),
|
|
47
|
-
});
|
|
48
|
-
}, [filter.type, filter.groupId, statusKey]);
|
|
49
|
-
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
let disposed = false;
|
|
52
|
-
let dispose: (() => void) | undefined;
|
|
53
|
-
void refresh();
|
|
54
|
-
void getUserContext().then((userContext) => {
|
|
55
|
-
if (disposed) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const sub = Invites(userContext.userDataContext).dataChanged.subscribe(() => void refresh());
|
|
59
|
-
dispose = () => {
|
|
60
|
-
sub.unsubscribe();
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
return () => {
|
|
64
|
-
disposed = true;
|
|
65
|
-
dispose?.();
|
|
66
|
-
};
|
|
67
|
-
}, [refresh]);
|
|
68
|
-
|
|
69
|
-
return query;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function counterpartLabel(row: IInvite): string {
|
|
73
|
-
return row.counterpart?.displayName || row.counterpart?.userId || "Someone";
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Human summary of what a row is, from the local user's point of view. */
|
|
77
|
-
export function describeInviteRow(row: IInvite): { title: string; detail: string } {
|
|
78
|
-
const who = counterpartLabel(row);
|
|
79
|
-
const role = row.role !== undefined ? getRoleLabel(row.role) : undefined;
|
|
80
|
-
const group = row.groupName ?? "a group";
|
|
81
|
-
if (row.type === "device") {
|
|
82
|
-
return {
|
|
83
|
-
title: row.direction === "in" ? `Device request from ${who}` : `Device invite for ${who}`,
|
|
84
|
-
detail: "Device admission actions are not available yet.",
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
if (row.type === "contact") {
|
|
88
|
-
if (row.direction === "in") {
|
|
89
|
-
if (row.recipientUserId) {
|
|
90
|
-
return {
|
|
91
|
-
title: `Connection request to ${who}`,
|
|
92
|
-
detail: "Waiting for them to confirm.",
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return { title: `${who} wants to connect`, detail: "Accept to add them as a contact." };
|
|
96
|
-
}
|
|
97
|
-
if (row.counterpart) {
|
|
98
|
-
return { title: `Contact invite to ${who}`, detail: "Waiting for them to accept." };
|
|
99
|
-
}
|
|
100
|
-
return {
|
|
101
|
-
title: row.mode === "profile" ? "Your profile QR" : "Contact invite link",
|
|
102
|
-
detail: row.mode === "profile" ? "Reusable; regenerate to revoke." : "Not used yet.",
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
if (row.direction === "in") {
|
|
106
|
-
if (row.recipientUserId) {
|
|
107
|
-
if (row.mode === "open") {
|
|
108
|
-
return {
|
|
109
|
-
title: `Joining ${group}`,
|
|
110
|
-
detail: "Completing automatically; no approval is required.",
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
return { title: `Request to join ${group}`, detail: `Waiting for ${who} to approve.` };
|
|
114
|
-
}
|
|
115
|
-
if (row.mode === "direct") {
|
|
116
|
-
return {
|
|
117
|
-
title: `${who} invited you to ${group}`,
|
|
118
|
-
detail: role ? `You would join as ${role}.` : "",
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
title: `${who} wants to join ${group}`,
|
|
123
|
-
detail: role ? `Requested as ${role}. Approve or deny.` : "Approve or deny.",
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
if (row.mode === "direct") {
|
|
127
|
-
return { title: `Invited ${who} to ${group}`, detail: "Waiting for them to accept." };
|
|
128
|
-
}
|
|
129
|
-
if (row.counterpart) {
|
|
130
|
-
return {
|
|
131
|
-
title: `${who} wants to join ${group}`,
|
|
132
|
-
detail: role ? `Requested as ${role}. Approve or deny.` : "Approve or deny.",
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
return {
|
|
136
|
-
title: `${group} invite link`,
|
|
137
|
-
detail: `${row.mode === "open" ? "Open" : "Approval required"}${role ? ` · ${role}` : ""}`,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/** Which Activity bucket a row belongs in. */
|
|
142
|
-
export type InviteBucket = "attention" | "waiting" | "history";
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Group an invite by what the signed-in user can do with it.
|
|
146
|
-
*
|
|
147
|
-
* Pending rows that need a decision are `attention`. Pending rows waiting on
|
|
148
|
-
* someone else, including links the user issued, are `waiting`.
|
|
149
|
-
*
|
|
150
|
-
* @param row - Invite row from the personal Invites table.
|
|
151
|
-
*/
|
|
152
|
-
export function classifyInvite(row: IInvite): InviteBucket {
|
|
153
|
-
if (row.status !== "pending") {
|
|
154
|
-
return "history";
|
|
155
|
-
}
|
|
156
|
-
return actionsForInvite(row).some((action) => action !== "revoke") ? "attention" : "waiting";
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/** Action that the local user can take on an Activity row. */
|
|
160
|
-
export type InviteRowAction = "accept" | "decline" | "approve" | "deny" | "revoke";
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Return actions that are valid from the local user's perspective.
|
|
164
|
-
*
|
|
165
|
-
* Inbound rows with `recipientUserId` were initiated locally and are waiting
|
|
166
|
-
* for that recipient. Actionable profile requests and join requests omit it.
|
|
167
|
-
*/
|
|
168
|
-
export function actionsForInvite(row: IInvite): InviteRowAction[] {
|
|
169
|
-
if (row.status !== "pending" || row.type === "device") {
|
|
170
|
-
return [];
|
|
171
|
-
}
|
|
172
|
-
if (row.direction === "out") {
|
|
173
|
-
return ["revoke"];
|
|
174
|
-
}
|
|
175
|
-
if (row.recipientUserId) {
|
|
176
|
-
return [];
|
|
177
|
-
}
|
|
178
|
-
if (row.direction === "in") {
|
|
179
|
-
if (row.type === "contact" || row.mode === "direct") {
|
|
180
|
-
return ["accept", "decline"];
|
|
181
|
-
}
|
|
182
|
-
if (row.type === "group" && row.mode === "approve" && row.counterpart) {
|
|
183
|
-
return ["approve", "deny"];
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return [];
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const ACTION_LABELS: Record<InviteRowAction, { text: string; className: string }> = {
|
|
190
|
-
accept: { text: "Accept", className: "btn-primary" },
|
|
191
|
-
decline: { text: "Decline", className: "btn-outline-secondary" },
|
|
192
|
-
approve: { text: "Approve", className: "btn-primary" },
|
|
193
|
-
deny: { text: "Deny", className: "btn-outline-secondary" },
|
|
194
|
-
revoke: { text: "Revoke", className: "btn-outline-danger" },
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
/** One invite row and the actions its direction and status allow. */
|
|
198
|
-
export function InviteRow({ row }: { row: IInvite }) {
|
|
199
|
-
const [busy, setBusy] = useState<InviteRowAction | undefined>(undefined);
|
|
200
|
-
const [error, setError] = useState("");
|
|
201
|
-
const { title, detail } = describeInviteRow(row);
|
|
202
|
-
|
|
203
|
-
const run = async (action: InviteRowAction) => {
|
|
204
|
-
setBusy(action);
|
|
205
|
-
setError("");
|
|
206
|
-
try {
|
|
207
|
-
const tools = await inviteTools();
|
|
208
|
-
const input = { inviteId: row.inviteId };
|
|
209
|
-
if (action === "accept") await tools.acceptInvite(input);
|
|
210
|
-
else if (action === "decline") await tools.declineInvite(input);
|
|
211
|
-
else if (action === "approve") await tools.approveJoinRequest(input);
|
|
212
|
-
else if (action === "deny") await tools.denyJoinRequest(input);
|
|
213
|
-
else await tools.revokeInvite(input);
|
|
214
|
-
} catch (err) {
|
|
215
|
-
setError((err as Error).message || "Could not update the invite.");
|
|
216
|
-
} finally {
|
|
217
|
-
setBusy(undefined);
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
return (
|
|
222
|
-
<div className="list-group-item">
|
|
223
|
-
<div className="d-flex justify-content-between align-items-center gap-2 flex-wrap">
|
|
224
|
-
<div className="flex-grow-1">
|
|
225
|
-
<div className="fw-semibold">
|
|
226
|
-
<span className="badge text-bg-light border me-2 text-capitalize">{row.type}</span>
|
|
227
|
-
{title}
|
|
228
|
-
</div>
|
|
229
|
-
{detail ? <small className="text-muted d-block">{detail}</small> : null}
|
|
230
|
-
{row.deliveryState === "queued" ? (
|
|
231
|
-
<small className="text-warning d-block">
|
|
232
|
-
Waiting for a route; Peers will retry automatically
|
|
233
|
-
</small>
|
|
234
|
-
) : null}
|
|
235
|
-
{row.status !== "pending" ? (
|
|
236
|
-
<small className="text-muted d-block text-capitalize">{row.status}</small>
|
|
237
|
-
) : null}
|
|
238
|
-
</div>
|
|
239
|
-
<div className="d-flex gap-1">
|
|
240
|
-
{actionsForInvite(row).map((action) => (
|
|
241
|
-
<button
|
|
242
|
-
key={action}
|
|
243
|
-
type="button"
|
|
244
|
-
className={`btn btn-sm ${ACTION_LABELS[action].className}`}
|
|
245
|
-
disabled={busy !== undefined}
|
|
246
|
-
onClick={() => void run(action)}
|
|
247
|
-
>
|
|
248
|
-
{busy === action ? "…" : ACTION_LABELS[action].text}
|
|
249
|
-
</button>
|
|
250
|
-
))}
|
|
251
|
-
</div>
|
|
252
|
-
</div>
|
|
253
|
-
{error ? <div className="alert alert-danger py-1 px-2 small mt-2 mb-0">{error}</div> : null}
|
|
254
|
-
</div>
|
|
255
|
-
);
|
|
256
|
-
}
|