moi-computer 0.12.1-next.2 → 0.12.1-next.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/bunfig.toml +1 -5
- package/client/api/app-config.ts +1 -2
- package/client/api/app-ui-keys.ts +3 -1
- package/client/api/http.ts +4 -1
- package/client/api/workspace-keys.ts +3 -3
- package/client/app/app-provider.tsx +22 -2
- package/client/app/app-router.tsx +6 -0
- package/client/app/routes/home-route.tsx +14 -0
- package/client/app/routes/onboarding-route.tsx +11 -0
- package/client/app/routes/settings-route.tsx +10 -0
- package/client/app/routes/workspace-route.tsx +21 -19
- package/client/app/shell/sidebar-layout.tsx +34 -53
- package/client/components/shared/screen-shell.tsx +23 -0
- package/client/components/shared/ultrafast-icon.tsx +61 -0
- package/client/components/shared/workspace-icon.tsx +2 -2
- package/client/features/account/account-menu.tsx +96 -0
- package/client/features/account/account-provider.tsx +142 -0
- package/client/features/account/account-test-utils.tsx +294 -0
- package/client/features/account/api.ts +142 -0
- package/client/features/account/identity.ts +23 -0
- package/client/features/app-settings/api.ts +33 -0
- package/client/features/app-settings/general-settings.tsx +39 -0
- package/client/features/app-settings/profile-settings.tsx +95 -0
- package/client/features/app-settings/settings-page.tsx +48 -0
- package/client/features/app-settings/settings-section.tsx +26 -0
- package/client/features/app-settings/users-settings.tsx +195 -0
- package/client/features/chat/applet-chat-intents.ts +4 -20
- package/client/features/chat/chat-send.ts +17 -13
- package/client/features/chat/composer/model-order.ts +8 -4
- package/client/features/chat/composer/model-picker.tsx +88 -34
- package/client/features/chat/composer/use-workspace-composer-state.tsx +11 -3
- package/client/features/chat/composer/use-workspace-skill-updates.ts +1 -1
- package/client/features/chat/connection/chat-frames.ts +3 -15
- package/client/features/chat/messages/chat-empty-state.tsx +1 -4
- package/client/features/chat/messages/fork-history.ts +5 -5
- package/client/features/chat/messages/turn-view.tsx +3 -12
- package/client/features/chat/messages/user-message-bubble.tsx +63 -0
- package/client/features/chat/sessions/api.ts +121 -80
- package/client/features/chat/sessions/browser-tab-state.ts +14 -12
- package/client/features/chat/sessions/chat-selector.tsx +5 -6
- package/client/features/chat/sessions/use-selected-session.ts +172 -257
- package/client/features/chat/use-chat.ts +14 -19
- package/client/features/collab/applet-api.ts +15 -14
- package/client/features/collab/components/cursors.tsx +61 -24
- package/client/features/collab/components/presence-avatars.tsx +25 -12
- package/client/features/collab/components/presence-frame.tsx +20 -24
- package/client/features/collab/components/presence-group.tsx +15 -7
- package/client/features/collab/components/user-avatar-group.tsx +21 -8
- package/client/features/collab/components/user-avatar.tsx +38 -7
- package/client/features/collab/components/user.tsx +31 -12
- package/client/features/collab/users.ts +0 -5
- package/client/features/collab/workspace-users-menu.tsx +4 -4
- package/client/features/demo/demo-dialog.tsx +11 -3
- package/client/features/dev/collab/collab-playground.tsx +7 -7
- package/client/features/dev/collab/local-user-settings.tsx +7 -53
- package/client/features/dev/dev-index-page.tsx +5 -0
- package/client/features/dev/dev-routes.tsx +2 -0
- package/client/features/dev/harness-debug-page.tsx +3 -3
- package/client/features/dev/onboarding-preview-page.tsx +76 -0
- package/client/features/dev/workspace-setup-mocks.ts +16 -14
- package/client/features/dev/workspace-setup-preview.tsx +11 -17
- package/client/features/harness/api.ts +45 -15
- package/client/features/harness/device-login-steps.tsx +9 -3
- package/client/features/harness/harness-login-panel.tsx +228 -0
- package/client/features/harness/harness-presentation.ts +15 -0
- package/client/features/harness/harness-selector.tsx +119 -0
- package/client/features/harness/use-harness-login.ts +77 -0
- package/client/features/home/home-page.tsx +7 -7
- package/client/features/onboarding/agent-setup-step.tsx +57 -0
- package/client/features/onboarding/api.ts +42 -0
- package/client/features/onboarding/onboarding-idea-disk.tsx +129 -0
- package/client/features/onboarding/onboarding-page.tsx +32 -0
- package/client/features/onboarding/onboarding-screen.tsx +20 -0
- package/client/features/onboarding/onboarding-status.tsx +24 -0
- package/client/features/onboarding/workspace-setup-step.tsx +239 -0
- package/client/features/overview/default/registry.tsx +2 -2
- package/client/features/overview/default/views-widget.tsx +6 -5
- package/client/features/overview/overview.tsx +9 -11
- package/client/features/overview/widget-canvas.tsx +1 -1
- package/client/features/overview/workspace-name.tsx +2 -2
- package/client/features/update/update-control.tsx +1 -1
- package/client/features/views/api.ts +69 -16
- package/client/features/views/pending-view-screen.tsx +30 -9
- package/client/features/views/use-view-actions.ts +19 -20
- package/client/features/views/view-presentation.ts +2 -2
- package/client/features/views/view-submission.ts +28 -41
- package/client/features/workspace/add/api.ts +3 -23
- package/client/features/workspace/add/create-workspace-dialog.tsx +11 -7
- package/client/features/workspace/add/import-workspace-dialog.tsx +3 -3
- package/client/features/workspace/add/workspace-agent-options.ts +11 -12
- package/client/features/workspace/add/workspace-agent-selector.tsx +3 -132
- package/client/features/workspace/api.ts +32 -36
- package/client/features/workspace/harness-transition.ts +88 -0
- package/client/features/{settings → workspace/settings}/api.ts +1 -34
- package/client/features/{settings → workspace/settings}/connectors-settings.tsx +3 -3
- package/client/features/{settings → workspace/settings}/environment-settings.tsx +3 -3
- package/client/features/{settings → workspace/settings}/general-settings.tsx +77 -3
- package/client/features/{settings → workspace/settings}/use-env-vars.ts +1 -1
- package/client/features/{settings → workspace/settings}/workspace-icon-picker.tsx +3 -3
- package/client/features/workspace/setup/workspace-login-state.tsx +37 -156
- package/client/features/workspace/setup/workspace-recovery-states.tsx +0 -12
- package/client/features/workspace/setup/workspace-setup.tsx +34 -14
- package/client/features/workspace/setup/workspace-welcome-state.tsx +2 -2
- package/client/features/workspace/use-workspace-navigation.ts +25 -9
- package/client/features/workspace/workspace-content.tsx +11 -8
- package/client/features/workspace/workspace-frame.tsx +2 -1
- package/client/features/workspace/workspace-layout-context.tsx +5 -2
- package/client/features/workspace/workspace-menu.tsx +12 -8
- package/client/features/workspace/workspace-pending-screen.tsx +10 -10
- package/client/features/workspace/workspace-presentation.tsx +5 -13
- package/client/features/workspace/workspace-state.ts +169 -0
- package/client/features/workspace/workspace-tabs.tsx +22 -2
- package/client/index.css +2 -0
- package/client/index.tsx +3 -3
- package/client/lib/flags.ts +1 -1
- package/client/lib/{app-icon-registry.ts → identity-icon-registry.ts} +10 -14
- package/client/lib/user-display-name.ts +6 -0
- package/client/main.tsx +4 -1
- package/client/runtime/workspace-events.ts +21 -4
- package/client/runtime/workspace-theme.ts +9 -0
- package/client/tailwind-config.ts +43 -0
- package/dist/chunk-0mjzg20x.js +2 -0
- package/dist/chunk-2y59vrxg.js +5 -0
- package/dist/chunk-58dyt9bk.js +2 -0
- package/dist/chunk-5aj040e5.css +1 -0
- package/dist/{chunk-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
- package/dist/chunk-71fn6rmj.js +546 -0
- package/dist/chunk-7yg1m8hx.js +2 -0
- package/dist/chunk-825hys3h.js +1 -0
- package/dist/chunk-9bb8m9rx.js +2 -0
- package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
- package/dist/chunk-g0tcwqxc.js +1 -0
- package/dist/chunk-n0nab26d.js +1 -0
- package/dist/chunk-nf2wkvf9.js +14 -0
- package/dist/chunk-v88n1bay.js +74 -0
- package/dist/index.html +1 -1
- package/lib/harness-instructions.ts +1 -1
- package/lib/{app-icons.ts → identity-icons.ts} +6 -7
- package/lib/onboarding.ts +41 -0
- package/lib/speed-mode.ts +5 -0
- package/lib/types.ts +72 -63
- package/lib/view-build-directives.ts +1 -2
- package/lib/workspace-icon.ts +2 -2
- package/lib/workspace-layout.ts +1 -1
- package/lib/workspace-name.ts +15 -12
- package/package.json +9 -8
- package/server/README.md +27 -25
- package/server/api/harnesses.ts +31 -8
- package/server/api/index.ts +164 -131
- package/server/api/onboarding.ts +46 -0
- package/server/app-config.ts +23 -24
- package/server/app-settings.ts +6 -2
- package/server/applets/config.ts +5 -5
- package/server/applets/views.ts +19 -17
- package/server/cli/commands/init.ts +3 -3
- package/server/cli/commands/skill.ts +16 -17
- package/server/cli/commands/start.ts +8 -34
- package/server/cli/server.ts +18 -6
- package/server/collab/config.ts +1 -2
- package/server/collab/manager.ts +4 -1
- package/server/collab/skill/index.ts +1 -1
- package/server/control.ts +3 -3
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +24 -8
- package/server/harness/acp/session.ts +8 -4
- package/server/harness/auth.ts +14 -17
- package/server/harness/claude-code/NOTES.md +4 -3
- package/server/harness/claude-code/index.ts +2 -0
- package/server/harness/claude-code/models.ts +2 -20
- package/server/harness/claude-code/run-action.ts +123 -0
- package/server/harness/claude-code/session-title.ts +5 -7
- package/server/harness/claude-code/session.ts +24 -16
- package/server/harness/codex/NOTES.md +14 -9
- package/server/harness/codex/adapter.ts +14 -17
- package/server/harness/codex/index.ts +2 -0
- package/server/harness/codex/run-action.ts +93 -0
- package/server/harness/codex/session-title.ts +6 -8
- package/server/harness/codex/session.ts +11 -11
- package/server/harness/command.ts +45 -0
- package/server/harness/executable.ts +5 -0
- package/server/harness/fork.ts +6 -4
- package/server/harness/install.ts +49 -0
- package/server/harness/openclaw/session.ts +1 -2
- package/server/harness/run-action.ts +85 -0
- package/server/harness/session-title.ts +0 -46
- package/server/harness/types.ts +26 -2
- package/server/onboarding/brief.ts +29 -0
- package/server/onboarding/ideas.ts +48 -0
- package/server/onboarding/jobs.ts +291 -0
- package/server/onboarding/prompt.md +49 -0
- package/server/sessions/archive.ts +5 -14
- package/server/sessions/config.ts +17 -16
- package/server/sessions/lifecycle.ts +15 -13
- package/server/sessions/pending-views.ts +79 -108
- package/server/sessions/selected.ts +75 -161
- package/server/sessions/store.ts +40 -113
- package/server/sessions/view-sessions.ts +128 -111
- package/server/skills/locations.ts +82 -0
- package/server/skills/lock.ts +29 -0
- package/server/skills/template.ts +36 -25
- package/server/skills/update.ts +52 -5
- package/server/skills/version.ts +17 -22
- package/server/skills/workspace.ts +121 -0
- package/server/web.ts +23 -8
- package/server/workspace-state/file.ts +177 -0
- package/server/workspace-state/index.ts +162 -0
- package/server/workspace-state/legacy-migration.ts +79 -0
- package/server/workspace-state/lock.ts +42 -0
- package/server/workspace-state/types.ts +16 -0
- package/server/workspaces/change-harness.ts +88 -0
- package/server/workspaces/harness-transition.ts +29 -0
- package/server/workspaces/init.ts +29 -16
- package/server/workspaces/layout.ts +3 -0
- package/server/workspaces/registry.ts +58 -10
- package/{workspace/.claude/skills/moi-workspace → skill}/SKILL.md +7 -5
- package/{workspace/.claude/skills/moi-workspace → skill}/references/COLLAB.md +4 -8
- package/skill/references/DESIGN.md +148 -0
- package/{workspace/.claude/skills/moi-workspace → skill}/references/SCRATCHPAD.md +2 -2
- package/{workspace/.claude/skills/moi-workspace → skill}/references/UI-COMPONENTS.md +3 -0
- package/ui-components/badge.tsx +1 -1
- package/client/accept-hmr-dependencies.ts +0 -22
- package/client/features/workspace/setup/workspace-setup-panel.tsx +0 -18
- package/dist/chunk-00rh9df4.js +0 -2
- package/dist/chunk-4nh7y1hq.css +0 -1
- package/dist/chunk-am4agx6v.js +0 -2
- package/dist/chunk-d7cbm65e.js +0 -2
- package/dist/chunk-hbpdv7vd.js +0 -1
- package/dist/chunk-hmka9rt5.js +0 -2
- package/dist/chunk-hvh9f5h0.js +0 -14
- package/dist/chunk-mjjregkn.js +0 -10
- package/dist/chunk-pcnahct1.js +0 -5
- package/dist/chunk-rt30jbcm.js +0 -1
- package/dist/chunk-vt6zybej.js +0 -2
- package/dist/chunk-wbkwf6cc.js +0 -68
- package/dist/chunk-xjyfyz64.js +0 -1
- package/dist/chunk-y8nbwp21.js +0 -546
- package/dist/chunk-ysfdcew7.js +0 -1
- package/lib/experimental.ts +0 -14
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +0 -157
- /package/client/features/{settings → workspace/settings}/icon-picker-options.ts +0 -0
- /package/client/features/{settings → workspace/settings}/settings-layout.tsx +0 -0
- /package/client/features/{settings → workspace/settings}/workspace-settings-dialog.tsx +0 -0
- /package/{workspace/.claude/skills/moi-workspace → skill}/references/INTENTS.md +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { createContext, useContext, useEffect, useState, useSyncExternalStore } from 'react'
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
3
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
4
|
+
import { useAppConfig } from '@/client/api/app-config'
|
|
5
|
+
import {
|
|
6
|
+
getCurrentUser,
|
|
7
|
+
getCurrentUserSource,
|
|
8
|
+
setLocalUser,
|
|
9
|
+
subscribeCurrentUserStore,
|
|
10
|
+
publishUsers
|
|
11
|
+
} from '@/client/features/collab/host-state'
|
|
12
|
+
import {
|
|
13
|
+
accountKeys,
|
|
14
|
+
CloudApiError,
|
|
15
|
+
sessionQuery,
|
|
16
|
+
teamQuery,
|
|
17
|
+
updateCloudName,
|
|
18
|
+
signOutCloud
|
|
19
|
+
} from './api'
|
|
20
|
+
import type { CloudSession } from './api'
|
|
21
|
+
import { syncCloudIdentity } from './identity'
|
|
22
|
+
|
|
23
|
+
function useAccountState() {
|
|
24
|
+
const { environment, demo } = useAppConfig()
|
|
25
|
+
const cloud = environment === 'cloud'
|
|
26
|
+
const profile = useSyncExternalStore(subscribeCurrentUserStore, getCurrentUser, getCurrentUser)
|
|
27
|
+
const source = useSyncExternalStore(
|
|
28
|
+
subscribeCurrentUserStore,
|
|
29
|
+
getCurrentUserSource,
|
|
30
|
+
getCurrentUserSource
|
|
31
|
+
)
|
|
32
|
+
const qc = useQueryClient()
|
|
33
|
+
const session = useQuery({ ...sessionQuery, enabled: cloud && !demo })
|
|
34
|
+
const registered = cloud && !demo && !!session.data && !session.data.user.isAnonymous
|
|
35
|
+
const team = useQuery({ ...teamQuery(session.data?.user.id), enabled: registered })
|
|
36
|
+
const [removingMemberIds, setRemovingMemberIds] = useState<string[]>([])
|
|
37
|
+
|
|
38
|
+
const signOut = useMutation({
|
|
39
|
+
mutationFn: signOutCloud,
|
|
40
|
+
onSuccess: async () => {
|
|
41
|
+
await qc.cancelQueries({ queryKey: accountKeys.all })
|
|
42
|
+
publishUsers({ users: [] })
|
|
43
|
+
qc.setQueryData(accountKeys.session, null)
|
|
44
|
+
qc.removeQueries({ queryKey: accountKeys.team })
|
|
45
|
+
window.location.assign('/cloud/login')
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!cloud || demo || !session.isSuccess || signOut.isPending || signOut.isSuccess) return
|
|
50
|
+
syncCloudIdentity(session.data, registered ? team.data : undefined)
|
|
51
|
+
}, [
|
|
52
|
+
cloud,
|
|
53
|
+
demo,
|
|
54
|
+
session.data,
|
|
55
|
+
session.isSuccess,
|
|
56
|
+
registered,
|
|
57
|
+
team.data,
|
|
58
|
+
signOut.isPending,
|
|
59
|
+
signOut.isSuccess
|
|
60
|
+
])
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (team.error instanceof CloudApiError && team.error.status === 401)
|
|
63
|
+
void qc.invalidateQueries({ queryKey: accountKeys.session })
|
|
64
|
+
}, [team.error, qc])
|
|
65
|
+
|
|
66
|
+
async function saveName(value: string) {
|
|
67
|
+
const name = value.trim()
|
|
68
|
+
if (!name || name.length > 80) throw new Error('Enter a name of up to 80 characters')
|
|
69
|
+
if (cloud) {
|
|
70
|
+
if (!registered) throw new Error('Sign in to change your name')
|
|
71
|
+
await qc.cancelQueries({ queryKey: accountKeys.session })
|
|
72
|
+
await updateCloudName(name).catch(error => {
|
|
73
|
+
if (error instanceof CloudApiError && error.status === 401)
|
|
74
|
+
void qc.invalidateQueries({ queryKey: accountKeys.session })
|
|
75
|
+
throw error
|
|
76
|
+
})
|
|
77
|
+
const latestSession = qc.getQueryData<CloudSession>(accountKeys.session)
|
|
78
|
+
if (
|
|
79
|
+
!latestSession ||
|
|
80
|
+
latestSession.user.id !== session.data!.user.id ||
|
|
81
|
+
latestSession.user.isAnonymous
|
|
82
|
+
)
|
|
83
|
+
throw new Error('Your account changed. Reload Moi to try again.')
|
|
84
|
+
const next: CloudSession = { user: { ...latestSession.user, name } }
|
|
85
|
+
qc.setQueryData(accountKeys.session, next)
|
|
86
|
+
syncCloudIdentity(next, team.data)
|
|
87
|
+
void qc.invalidateQueries({ queryKey: accountKeys.team })
|
|
88
|
+
return name
|
|
89
|
+
}
|
|
90
|
+
const localProfile = getCurrentUser()
|
|
91
|
+
if (getCurrentUserSource() !== 'local' || !localProfile || localProfile.id !== profile?.id)
|
|
92
|
+
throw new Error('This profile is managed by your sign-in provider')
|
|
93
|
+
setLocalUser({ ...localProfile, name })
|
|
94
|
+
return name
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function getStatus() {
|
|
98
|
+
if (demo) return 'signed-out'
|
|
99
|
+
if (!cloud) return profile ? 'ready' : 'error'
|
|
100
|
+
if (session.isPending) return 'loading'
|
|
101
|
+
if (session.isError) return 'error'
|
|
102
|
+
if (!registered) return 'signed-out'
|
|
103
|
+
if (profile?.id === session.data?.user.id && source === 'external') return 'ready'
|
|
104
|
+
return 'loading'
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
cloud,
|
|
109
|
+
demo: demo || (cloud && session.data?.user.isAnonymous === true),
|
|
110
|
+
profile,
|
|
111
|
+
status: getStatus(),
|
|
112
|
+
email: registered ? session.data?.user.email : undefined,
|
|
113
|
+
canEdit: cloud ? registered : source === 'local',
|
|
114
|
+
registered,
|
|
115
|
+
team,
|
|
116
|
+
removingMemberIds,
|
|
117
|
+
setRemovingMemberIds,
|
|
118
|
+
saveName,
|
|
119
|
+
signOut,
|
|
120
|
+
retry: () => {
|
|
121
|
+
if (!cloud) {
|
|
122
|
+
window.location.reload()
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
void session.refetch()
|
|
126
|
+
if (registered) void team.refetch()
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
type AccountState = ReturnType<typeof useAccountState>
|
|
132
|
+
const AccountContext = createContext<AccountState | undefined>(undefined)
|
|
133
|
+
type AccountProviderProps = { children: ReactNode }
|
|
134
|
+
export function AccountProvider({ children }: AccountProviderProps) {
|
|
135
|
+
const account = useAccountState()
|
|
136
|
+
return <AccountContext value={account}>{children}</AccountContext>
|
|
137
|
+
}
|
|
138
|
+
export function useAccount() {
|
|
139
|
+
const account = useContext(AccountContext)
|
|
140
|
+
if (!account) throw new Error('AccountProvider is required')
|
|
141
|
+
return account
|
|
142
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { expect, spyOn } from 'bun:test'
|
|
2
|
+
import { act, useLayoutEffect } from 'react'
|
|
3
|
+
import type { ReactNode } from 'react'
|
|
4
|
+
import * as layoutEffect from '@base-ui/utils/useIsoLayoutEffect'
|
|
5
|
+
import { Router } from 'wouter'
|
|
6
|
+
import { memoryLocation } from 'wouter/memory-location'
|
|
7
|
+
import { parseHTML } from 'linkedom'
|
|
8
|
+
import { QueryClient, QueryClientProvider, notifyManager } from '@tanstack/react-query'
|
|
9
|
+
import * as config from '@/client/api/app-config'
|
|
10
|
+
import { publishUsers } from '@/client/features/collab/host-state'
|
|
11
|
+
import { AccountProvider, useAccount } from './account-provider'
|
|
12
|
+
import { sessionQuery, teamQuery } from './api'
|
|
13
|
+
import type { CloudSession, CloudTeam } from './api'
|
|
14
|
+
|
|
15
|
+
const session: CloudSession = {
|
|
16
|
+
user: { id: 'me', name: 'Alex', email: 'alex@example.com', isAnonymous: false }
|
|
17
|
+
}
|
|
18
|
+
export const ownerTeam: CloudTeam = {
|
|
19
|
+
id: 'team',
|
|
20
|
+
name: 'Team',
|
|
21
|
+
role: 'owner',
|
|
22
|
+
members: [
|
|
23
|
+
{
|
|
24
|
+
id: 'member-me',
|
|
25
|
+
userId: 'me',
|
|
26
|
+
name: 'Alex',
|
|
27
|
+
email: 'alex@example.com',
|
|
28
|
+
role: 'owner',
|
|
29
|
+
me: true
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: 'member-ada',
|
|
33
|
+
userId: 'ada',
|
|
34
|
+
name: 'Ada',
|
|
35
|
+
email: 'ada@example.com',
|
|
36
|
+
role: 'admin',
|
|
37
|
+
me: false
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
invitations: [
|
|
41
|
+
{ id: 'invite-1', email: 'grace@example.com', role: 'admin', expiresAt: '2030-01-01' }
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
let cleanup = async () => {}
|
|
45
|
+
export const cleanupAccount = () => cleanup()
|
|
46
|
+
|
|
47
|
+
export type AccountFixtureOptions = {
|
|
48
|
+
children?: ReactNode
|
|
49
|
+
role?: string
|
|
50
|
+
anonymous?: boolean
|
|
51
|
+
signedOut?: boolean
|
|
52
|
+
demo?: boolean
|
|
53
|
+
failTeam?: boolean
|
|
54
|
+
environment?: 'local' | 'cloud'
|
|
55
|
+
failSession?: boolean
|
|
56
|
+
loadingSession?: boolean
|
|
57
|
+
pendingMutation?: boolean
|
|
58
|
+
pendingMutationPaths?: string[]
|
|
59
|
+
injected?: boolean
|
|
60
|
+
loadingTeam?: boolean
|
|
61
|
+
}
|
|
62
|
+
export async function mountAccount({
|
|
63
|
+
children = <AccountProbe />,
|
|
64
|
+
role = 'owner',
|
|
65
|
+
anonymous = false,
|
|
66
|
+
signedOut = false,
|
|
67
|
+
demo = false,
|
|
68
|
+
failTeam = false,
|
|
69
|
+
environment = 'cloud',
|
|
70
|
+
failSession = false,
|
|
71
|
+
loadingSession = false,
|
|
72
|
+
pendingMutation = false,
|
|
73
|
+
pendingMutationPaths = [],
|
|
74
|
+
injected = true,
|
|
75
|
+
loadingTeam = false
|
|
76
|
+
}: AccountFixtureOptions = {}) {
|
|
77
|
+
const { window, document } = parseHTML('<html><body><div id="root"></div></body></html>')
|
|
78
|
+
Object.defineProperty(document, 'oninput', { value: null, configurable: true })
|
|
79
|
+
const navigations: string[] = []
|
|
80
|
+
Object.defineProperty(window, 'location', {
|
|
81
|
+
configurable: true,
|
|
82
|
+
value: {
|
|
83
|
+
assign: (href: string) => navigations.push(href),
|
|
84
|
+
replace: (href: string) => navigations.push(href)
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
const globals = {
|
|
88
|
+
window,
|
|
89
|
+
document,
|
|
90
|
+
HTMLElement: window.HTMLElement,
|
|
91
|
+
Element: window.Element,
|
|
92
|
+
requestAnimationFrame: (callback: FrameRequestCallback) =>
|
|
93
|
+
Number(setTimeout(() => callback(performance.now()), 0)),
|
|
94
|
+
cancelAnimationFrame: (id: number) => clearTimeout(id),
|
|
95
|
+
getComputedStyle: (element: HTMLElement) =>
|
|
96
|
+
new Proxy(element.style, { get: (style, key) => Reflect.get(style, key) ?? '' }),
|
|
97
|
+
Node: window.Node,
|
|
98
|
+
KeyboardEvent: class extends window.Event {},
|
|
99
|
+
FocusEvent: class extends window.Event {},
|
|
100
|
+
MouseEvent: class extends window.Event {},
|
|
101
|
+
IS_REACT_ACT_ENVIRONMENT: true
|
|
102
|
+
}
|
|
103
|
+
const descriptors = new Map(
|
|
104
|
+
Object.keys(globals).map(key => [key, Object.getOwnPropertyDescriptor(globalThis, key)])
|
|
105
|
+
)
|
|
106
|
+
for (const [key, value] of Object.entries(globals))
|
|
107
|
+
Object.defineProperty(globalThis, key, { configurable: true, value })
|
|
108
|
+
// Base UI was imported before this fixture installed a DOM. Enable its browser effects.
|
|
109
|
+
const layoutEffectSpy = spyOn(layoutEffect, 'useIsoLayoutEffect').mockImplementation(
|
|
110
|
+
useLayoutEffect
|
|
111
|
+
)
|
|
112
|
+
const configSpy = spyOn(config, 'useAppConfig').mockReturnValue({
|
|
113
|
+
environment,
|
|
114
|
+
demo,
|
|
115
|
+
collab: false,
|
|
116
|
+
demoInstallUrl: '/'
|
|
117
|
+
})
|
|
118
|
+
let cloudSession: CloudSession = signedOut
|
|
119
|
+
? null
|
|
120
|
+
: { user: { ...session!.user, isAnonymous: anonymous } }
|
|
121
|
+
let team: CloudTeam = structuredClone({ ...ownerTeam, role })
|
|
122
|
+
const failures = { signOut: false, mutation: false, team: failTeam, session: failSession }
|
|
123
|
+
const mutationRequest = Promise.withResolvers<void>()
|
|
124
|
+
const teamResponse = Promise.withResolvers<Response>()
|
|
125
|
+
const calls: { path: string; body?: Record<string, unknown> }[] = []
|
|
126
|
+
const fetchSpy = spyOn(globalThis, 'fetch').mockImplementation(
|
|
127
|
+
Object.assign(
|
|
128
|
+
async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
129
|
+
const path = String(input)
|
|
130
|
+
const body = init?.body
|
|
131
|
+
? (JSON.parse(String(init.body)) as Record<string, string>)
|
|
132
|
+
: undefined
|
|
133
|
+
calls.push({ path, body })
|
|
134
|
+
if (path.endsWith('/get-session')) {
|
|
135
|
+
if (loadingSession) return new Promise<Response>(() => {})
|
|
136
|
+
return failures.session
|
|
137
|
+
? Response.json({ error: 'Session unavailable' }, { status: 503 })
|
|
138
|
+
: Response.json(cloudSession)
|
|
139
|
+
}
|
|
140
|
+
if (path.endsWith('/organization')) {
|
|
141
|
+
if (loadingTeam) return teamResponse.promise
|
|
142
|
+
return failures.team
|
|
143
|
+
? Response.json({ error: 'Team unavailable' }, { status: 503 })
|
|
144
|
+
: Response.json(team)
|
|
145
|
+
}
|
|
146
|
+
if (path.endsWith('/sign-out')) {
|
|
147
|
+
if (failures.signOut)
|
|
148
|
+
return Response.json({ error: 'Try signing out again.' }, { status: 503 })
|
|
149
|
+
cloudSession = null
|
|
150
|
+
return Response.json({ success: true })
|
|
151
|
+
}
|
|
152
|
+
if (
|
|
153
|
+
pendingMutation &&
|
|
154
|
+
(pendingMutationPaths.length === 0 ||
|
|
155
|
+
pendingMutationPaths.some(suffix => path.endsWith(suffix)))
|
|
156
|
+
)
|
|
157
|
+
await mutationRequest.promise
|
|
158
|
+
if (failures.mutation)
|
|
159
|
+
return Response.json({ error: 'Only the owner can do that.' }, { status: 403 })
|
|
160
|
+
if (path === '/api/settings') return Response.json({ autoUpdateSkills: false, ...body })
|
|
161
|
+
if (path.endsWith('/profile')) {
|
|
162
|
+
cloudSession = { user: { ...session!.user, name: body!.name! } }
|
|
163
|
+
team.members[0]!.name = body!.name!
|
|
164
|
+
return Response.json({ success: true, name: body!.name })
|
|
165
|
+
}
|
|
166
|
+
if (path.endsWith('/members/remove'))
|
|
167
|
+
team.members = team.members.filter(member => member.id !== body!.memberId)
|
|
168
|
+
if (path.endsWith('/cancel')) team.invitations = []
|
|
169
|
+
if (path.endsWith('/invite'))
|
|
170
|
+
team.invitations.push({
|
|
171
|
+
id: 'invite-new',
|
|
172
|
+
email: body!.email!,
|
|
173
|
+
role: 'admin',
|
|
174
|
+
expiresAt: '2030-01-01'
|
|
175
|
+
})
|
|
176
|
+
return Response.json({ success: true })
|
|
177
|
+
},
|
|
178
|
+
{ preconnect: fetch.preconnect }
|
|
179
|
+
)
|
|
180
|
+
)
|
|
181
|
+
const qc = new QueryClient({
|
|
182
|
+
defaultOptions: { queries: { retry: false }, mutations: { retry: false } }
|
|
183
|
+
})
|
|
184
|
+
if (!failSession && !loadingSession)
|
|
185
|
+
qc.setQueryData(sessionQuery.queryKey, structuredClone(cloudSession))
|
|
186
|
+
if (!failTeam && !loadingTeam)
|
|
187
|
+
qc.setQueryData(teamQuery(cloudSession?.user.id).queryKey, structuredClone(team))
|
|
188
|
+
publishUsers({ users: [] })
|
|
189
|
+
if (injected)
|
|
190
|
+
publishUsers({
|
|
191
|
+
me: 'me',
|
|
192
|
+
users: [
|
|
193
|
+
{
|
|
194
|
+
id: 'me',
|
|
195
|
+
name: 'Alex',
|
|
196
|
+
email: 'alex@example.com',
|
|
197
|
+
color: 'blue',
|
|
198
|
+
avatar: 'https://example.com/avatar.png'
|
|
199
|
+
},
|
|
200
|
+
{ id: 'ada', name: 'Ada', email: 'ada@example.com', color: 'cyan' }
|
|
201
|
+
]
|
|
202
|
+
})
|
|
203
|
+
const { createRoot } = await import('react-dom/client')
|
|
204
|
+
const root = createRoot(document.getElementById('root')!)
|
|
205
|
+
notifyManager.setNotifyFunction(callback => {
|
|
206
|
+
act(callback)
|
|
207
|
+
})
|
|
208
|
+
const location = memoryLocation({ path: '/settings', record: true })
|
|
209
|
+
await act(async () =>
|
|
210
|
+
root.render(
|
|
211
|
+
<QueryClientProvider client={qc}>
|
|
212
|
+
<Router hook={location.hook}>
|
|
213
|
+
<AccountProvider>{children}</AccountProvider>
|
|
214
|
+
</Router>
|
|
215
|
+
</QueryClientProvider>
|
|
216
|
+
)
|
|
217
|
+
)
|
|
218
|
+
async function settle() {
|
|
219
|
+
await act(async () => {
|
|
220
|
+
await new Promise(resolve => setTimeout(resolve, 5))
|
|
221
|
+
})
|
|
222
|
+
}
|
|
223
|
+
cleanup = async () => {
|
|
224
|
+
await act(async () => root.unmount())
|
|
225
|
+
qc.clear()
|
|
226
|
+
publishUsers({ users: [] })
|
|
227
|
+
layoutEffectSpy.mockRestore()
|
|
228
|
+
configSpy.mockRestore()
|
|
229
|
+
fetchSpy.mockRestore()
|
|
230
|
+
notifyManager.setNotifyFunction(callback => callback())
|
|
231
|
+
for (const [key, descriptor] of descriptors) {
|
|
232
|
+
if (descriptor) Object.defineProperty(globalThis, key, descriptor)
|
|
233
|
+
else Reflect.deleteProperty(globalThis, key)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return {
|
|
237
|
+
document,
|
|
238
|
+
window,
|
|
239
|
+
calls,
|
|
240
|
+
failures,
|
|
241
|
+
mutationRequest,
|
|
242
|
+
teamResponse,
|
|
243
|
+
qc,
|
|
244
|
+
navigations,
|
|
245
|
+
location,
|
|
246
|
+
settle,
|
|
247
|
+
async click(label: string) {
|
|
248
|
+
const button = [...document.querySelectorAll<HTMLElement>('button, [role="menuitem"]')].find(
|
|
249
|
+
button => button.getAttribute('aria-label') === label || button.textContent === label
|
|
250
|
+
)
|
|
251
|
+
expect(button).toBeDefined()
|
|
252
|
+
await act(async () => {
|
|
253
|
+
const event = new window.Event('mousedown', { bubbles: true, cancelable: true })
|
|
254
|
+
Object.defineProperty(event, 'button', { value: 0 })
|
|
255
|
+
button!.dispatchEvent(event)
|
|
256
|
+
button!.click()
|
|
257
|
+
})
|
|
258
|
+
await settle()
|
|
259
|
+
},
|
|
260
|
+
async type(input: HTMLInputElement, value: string) {
|
|
261
|
+
await act(async () => {
|
|
262
|
+
input.type = input.id === 'invite-email' ? 'email' : 'text'
|
|
263
|
+
// React may have loaded before a DOM in the full suite; also exercise its
|
|
264
|
+
// legacy input-event fallback through real focus and keyboard events.
|
|
265
|
+
Object.assign(input, { attachEvent() {}, detachEvent() {} })
|
|
266
|
+
input.dispatchEvent(new window.Event('focusin', { bubbles: true }))
|
|
267
|
+
Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')!.set!.call(
|
|
268
|
+
input,
|
|
269
|
+
value
|
|
270
|
+
)
|
|
271
|
+
input.dispatchEvent(new window.Event('input', { bubbles: true }))
|
|
272
|
+
input.dispatchEvent(new window.Event('keyup', { bubbles: true }))
|
|
273
|
+
})
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
type AccountProbeProps = { children?: ReactNode }
|
|
279
|
+
export function AccountProbe({ children }: AccountProbeProps) {
|
|
280
|
+
const account = useAccount()
|
|
281
|
+
return (
|
|
282
|
+
<>
|
|
283
|
+
<p data-account-status>{account.status}</p>
|
|
284
|
+
<p data-account-name>{account.profile?.name}</p>
|
|
285
|
+
{account.status === 'ready' && children}
|
|
286
|
+
{account.registered && (
|
|
287
|
+
<button disabled={account.signOut.isPending} onClick={() => account.signOut.mutate()}>
|
|
288
|
+
Sign out
|
|
289
|
+
</button>
|
|
290
|
+
)}
|
|
291
|
+
{account.signOut.error && <p role="alert">{account.signOut.error.message}</p>}
|
|
292
|
+
</>
|
|
293
|
+
)
|
|
294
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { queryOptions } from '@tanstack/react-query'
|
|
2
|
+
import { jsonRequest } from '@/client/api/http'
|
|
3
|
+
import { isRecord, isUserProfile } from '@/lib/collab/protocol'
|
|
4
|
+
|
|
5
|
+
export type CloudSession = {
|
|
6
|
+
user: { id: string; email: string; name: string; isAnonymous: boolean }
|
|
7
|
+
} | null
|
|
8
|
+
export type TeamMember = {
|
|
9
|
+
id: string
|
|
10
|
+
userId: string
|
|
11
|
+
email: string
|
|
12
|
+
name: string
|
|
13
|
+
role: string
|
|
14
|
+
me: boolean
|
|
15
|
+
}
|
|
16
|
+
export type TeamInvitation = { id: string; email: string; role: string; expiresAt: string }
|
|
17
|
+
export type CloudTeam = {
|
|
18
|
+
id: string
|
|
19
|
+
name: string
|
|
20
|
+
role: string
|
|
21
|
+
members: TeamMember[]
|
|
22
|
+
invitations: TeamInvitation[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const accountKeys = {
|
|
26
|
+
all: ['account'] as const,
|
|
27
|
+
session: ['account', 'session'] as const,
|
|
28
|
+
team: ['account', 'team'] as const
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class CloudApiError extends Error {
|
|
32
|
+
constructor(
|
|
33
|
+
message: string,
|
|
34
|
+
readonly status: number
|
|
35
|
+
) {
|
|
36
|
+
super(message)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function cloudRequest(path: string, init?: RequestInit): Promise<Response> {
|
|
41
|
+
const response = await fetch(`/cloud/api/auth/${path}`, { ...init, credentials: 'same-origin' })
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
const body: unknown = await response.json().catch(() => undefined)
|
|
44
|
+
const message = isRecord(body)
|
|
45
|
+
? [body.error, body.message].find(
|
|
46
|
+
(value): value is string => typeof value === 'string' && value.trim().length > 0
|
|
47
|
+
)
|
|
48
|
+
: undefined
|
|
49
|
+
throw new CloudApiError(
|
|
50
|
+
message ?? 'Couldn’t complete this request. Try again.',
|
|
51
|
+
response.status
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
return response
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function validProfile(id: unknown, name: unknown, email: unknown): boolean {
|
|
58
|
+
return (
|
|
59
|
+
typeof id === 'string' &&
|
|
60
|
+
id === id.trim() &&
|
|
61
|
+
typeof name === 'string' &&
|
|
62
|
+
typeof email === 'string' &&
|
|
63
|
+
isUserProfile({ id, name: name.trim() || undefined, email, color: 'blue' })
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function parseSession(value: unknown): CloudSession {
|
|
68
|
+
if (value === null) return null
|
|
69
|
+
if (
|
|
70
|
+
!isRecord(value) ||
|
|
71
|
+
!isRecord(value.user) ||
|
|
72
|
+
!validProfile(value.user.id, value.user.name, value.user.email) ||
|
|
73
|
+
typeof value.user.isAnonymous !== 'boolean'
|
|
74
|
+
)
|
|
75
|
+
throw new Error('Invalid account response')
|
|
76
|
+
return value as NonNullable<CloudSession>
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function parseTeam(value: unknown): CloudTeam {
|
|
80
|
+
if (
|
|
81
|
+
!isRecord(value) ||
|
|
82
|
+
typeof value.id !== 'string' ||
|
|
83
|
+
typeof value.name !== 'string' ||
|
|
84
|
+
typeof value.role !== 'string' ||
|
|
85
|
+
!Array.isArray(value.members) ||
|
|
86
|
+
!Array.isArray(value.invitations) ||
|
|
87
|
+
!value.members.every(
|
|
88
|
+
member =>
|
|
89
|
+
isRecord(member) &&
|
|
90
|
+
typeof member.id === 'string' &&
|
|
91
|
+
validProfile(member.userId, member.name, member.email) &&
|
|
92
|
+
typeof member.role === 'string' &&
|
|
93
|
+
typeof member.me === 'boolean'
|
|
94
|
+
) ||
|
|
95
|
+
!value.invitations.every(
|
|
96
|
+
invitation =>
|
|
97
|
+
isRecord(invitation) &&
|
|
98
|
+
validProfile(invitation.id, '', invitation.email) &&
|
|
99
|
+
typeof invitation.role === 'string' &&
|
|
100
|
+
typeof invitation.expiresAt === 'string' &&
|
|
101
|
+
Number.isFinite(Date.parse(invitation.expiresAt))
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
throw new Error('Invalid users response')
|
|
105
|
+
const team = value as CloudTeam
|
|
106
|
+
if (
|
|
107
|
+
new Set(team.members.map(member => member.userId)).size !== team.members.length ||
|
|
108
|
+
new Set(team.members.map(member => member.id)).size !== team.members.length ||
|
|
109
|
+
new Set(team.invitations.map(invitation => invitation.id)).size !== team.invitations.length
|
|
110
|
+
)
|
|
111
|
+
throw new Error('Invalid users response')
|
|
112
|
+
return team
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export const sessionQuery = queryOptions({
|
|
116
|
+
queryKey: accountKeys.session,
|
|
117
|
+
queryFn: async ({ signal }) => {
|
|
118
|
+
const response = await cloudRequest('get-session', { signal })
|
|
119
|
+
return parseSession(await response.json())
|
|
120
|
+
},
|
|
121
|
+
retry: false,
|
|
122
|
+
staleTime: 30_000
|
|
123
|
+
})
|
|
124
|
+
export const teamQuery = (userId?: string) =>
|
|
125
|
+
queryOptions({
|
|
126
|
+
queryKey: [...accountKeys.team, userId],
|
|
127
|
+
queryFn: async ({ signal }) => {
|
|
128
|
+
const response = await cloudRequest('organization', { signal })
|
|
129
|
+
return parseTeam(await response.json())
|
|
130
|
+
},
|
|
131
|
+
retry: false,
|
|
132
|
+
staleTime: 30_000
|
|
133
|
+
})
|
|
134
|
+
export const updateCloudName = (name: string) =>
|
|
135
|
+
cloudRequest('profile', jsonRequest('POST', { name }))
|
|
136
|
+
export const signOutCloud = () => cloudRequest('sign-out', jsonRequest('POST'))
|
|
137
|
+
export const inviteMember = (email: string) =>
|
|
138
|
+
cloudRequest('invite', jsonRequest('POST', { email }))
|
|
139
|
+
export const cancelInvitation = (id: string) =>
|
|
140
|
+
cloudRequest(`invitation/${encodeURIComponent(id)}/cancel`, jsonRequest('POST'))
|
|
141
|
+
export const removeMember = (memberId: string) =>
|
|
142
|
+
cloudRequest('members/remove', jsonRequest('POST', { memberId }))
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getCurrentUser, getDirectory, publishUsers } from '@/client/features/collab/host-state'
|
|
2
|
+
import type { CloudSession, CloudTeam } from './api'
|
|
3
|
+
|
|
4
|
+
// The session identifies the viewer. Keep the injected directory until the team
|
|
5
|
+
// request resolves, and preserve known avatar and color information by user id.
|
|
6
|
+
export function syncCloudIdentity(session: CloudSession, team?: CloudTeam): void {
|
|
7
|
+
if (!session || session.user.isAnonymous) {
|
|
8
|
+
publishUsers({ users: [] })
|
|
9
|
+
return
|
|
10
|
+
}
|
|
11
|
+
const { id, name, email } = session.user
|
|
12
|
+
const sameAccount = getCurrentUser()?.id === id
|
|
13
|
+
const known = new Map((getDirectory() ?? []).map(user => [user.id, user]))
|
|
14
|
+
const users =
|
|
15
|
+
team?.members.map(user => ({
|
|
16
|
+
...known.get(user.userId),
|
|
17
|
+
id: user.userId,
|
|
18
|
+
name: user.name,
|
|
19
|
+
email: user.email
|
|
20
|
+
})) ?? (sameAccount ? [...known.values()] : [])
|
|
21
|
+
const profile = { ...known.get(id), id, name, email }
|
|
22
|
+
publishUsers({ me: id, users: [...users.filter(user => user.id !== id), profile] })
|
|
23
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { jsonRequest, requestJson } from '@/client/api/http'
|
|
3
|
+
import { useWorkspaceEvent } from '@/client/runtime/use-workspace-events'
|
|
4
|
+
import type { AppSettings } from '@/lib/types'
|
|
5
|
+
|
|
6
|
+
export const appSettingsKey = ['app-settings'] as const
|
|
7
|
+
|
|
8
|
+
export function useAppSettings() {
|
|
9
|
+
const queryClient = useQueryClient()
|
|
10
|
+
// Another client can change settings; the server broadcasts the new value
|
|
11
|
+
// over the live-events socket so every open client stays in sync.
|
|
12
|
+
useWorkspaceEvent(event => {
|
|
13
|
+
if (event.type === 'settings:updated') {
|
|
14
|
+
queryClient.setQueryData<AppSettings>(appSettingsKey, event.settings)
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
return useQuery<AppSettings>({
|
|
18
|
+
queryKey: appSettingsKey,
|
|
19
|
+
queryFn: () => requestJson('/api/settings'),
|
|
20
|
+
staleTime: 30_000
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function useSaveAppSettings() {
|
|
25
|
+
const queryClient = useQueryClient()
|
|
26
|
+
return useMutation<AppSettings, Error, Partial<AppSettings>>({
|
|
27
|
+
mutationFn: patch =>
|
|
28
|
+
requestJson('/api/settings', jsonRequest('PATCH', patch), 'Failed to save settings'),
|
|
29
|
+
onSuccess: next => {
|
|
30
|
+
queryClient.setQueryData<AppSettings>(appSettingsKey, next)
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useLocation } from 'wouter'
|
|
2
|
+
import { Button } from '@/client/components/ui/button'
|
|
3
|
+
import {
|
|
4
|
+
Field,
|
|
5
|
+
FieldContent,
|
|
6
|
+
FieldDescription,
|
|
7
|
+
FieldGroup,
|
|
8
|
+
FieldTitle
|
|
9
|
+
} from '@/ui-components/field'
|
|
10
|
+
import { useSaveAppSettings } from './api'
|
|
11
|
+
import { SettingsSection } from './settings-section'
|
|
12
|
+
|
|
13
|
+
export function GeneralSettings() {
|
|
14
|
+
const save = useSaveAppSettings()
|
|
15
|
+
const [, navigate] = useLocation()
|
|
16
|
+
return (
|
|
17
|
+
<SettingsSection title="General">
|
|
18
|
+
<FieldGroup>
|
|
19
|
+
<Field orientation="responsive">
|
|
20
|
+
<FieldContent>
|
|
21
|
+
<FieldTitle>Restart onboarding</FieldTitle>
|
|
22
|
+
<FieldDescription>Go through the onboarding without logging out</FieldDescription>
|
|
23
|
+
</FieldContent>
|
|
24
|
+
<Button
|
|
25
|
+
variant="secondary"
|
|
26
|
+
aria-label="Restart onboarding"
|
|
27
|
+
disabled={save.isPending}
|
|
28
|
+
onClick={() =>
|
|
29
|
+
save.mutate({ showOnboarding: true }, { onSuccess: () => navigate('/onboarding') })
|
|
30
|
+
}
|
|
31
|
+
>
|
|
32
|
+
{save.isPending ? 'Opening…' : 'Restart'}
|
|
33
|
+
</Button>
|
|
34
|
+
</Field>
|
|
35
|
+
</FieldGroup>
|
|
36
|
+
{save.isError && <p role="alert">Couldn’t restart onboarding. Try again</p>}
|
|
37
|
+
</SettingsSection>
|
|
38
|
+
)
|
|
39
|
+
}
|