Skip to content

Commit 9f80f9b

Browse files
committed
fix: Update routing for workspace schedule
This was broken as part of #2101. It was a silly mistake, but unfortunate our tests didn't catch it. This is a rare change so unlikely to occur again, so I won't make an issue adding tests.
1 parent 3878e64 commit 9f80f9b

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,33 +142,39 @@ export const workspaceToInitialValues = (
142142
}
143143

144144
export const WorkspaceSchedulePage: React.FC = () => {
145+
const { username: usernameQueryParam, workspace: workspaceQueryParam } = useParams()
145146
const navigate = useNavigate()
146-
const { workspace: workspaceQueryParam } = useParams()
147-
const workspaceId = firstOrItem(workspaceQueryParam, null)
147+
const username = firstOrItem(usernameQueryParam, null)
148+
const workspaceName = firstOrItem(workspaceQueryParam, null)
148149
const [scheduleState, scheduleSend] = useMachine(workspaceSchedule)
149150
const { formErrors, getWorkspaceError, workspace } = scheduleState.context
150151

151152
// Get workspace on mount and whenever workspaceId changes.
152153
// scheduleSend should not change.
153154
useEffect(() => {
154-
workspaceId && scheduleSend({ type: "GET_WORKSPACE", workspaceId })
155-
}, [workspaceId, scheduleSend])
155+
username && workspaceName && scheduleSend({ type: "GET_WORKSPACE", username, workspaceName })
156+
}, [username, workspaceName, scheduleSend])
156157

157-
if (!workspaceId) {
158+
if (!username || !workspaceName) {
158159
navigate("/workspaces")
159160
return null
160161
} else if (scheduleState.matches("idle") || scheduleState.matches("gettingWorkspace") || !workspace) {
161162
return <FullScreenLoader />
162163
} else if (scheduleState.matches("error")) {
163-
return <ErrorSummary error={getWorkspaceError} retry={() => scheduleSend({ type: "GET_WORKSPACE", workspaceId })} />
164+
return (
165+
<ErrorSummary
166+
error={getWorkspaceError}
167+
retry={() => scheduleSend({ type: "GET_WORKSPACE", username, workspaceName })}
168+
/>
169+
)
164170
} else if (scheduleState.matches("presentForm") || scheduleState.matches("submittingSchedule")) {
165171
return (
166172
<WorkspaceScheduleForm
167173
fieldErrors={formErrors}
168174
initialValues={workspaceToInitialValues(workspace, dayjs.tz.guess())}
169175
isLoading={scheduleState.tags.has("loading")}
170176
onCancel={() => {
171-
navigate(`/workspaces/${workspaceId}`)
177+
navigate(`/@${username}/${workspaceName}`)
172178
}}
173179
onSubmit={(values) => {
174180
scheduleSend({
@@ -180,7 +186,7 @@ export const WorkspaceSchedulePage: React.FC = () => {
180186
/>
181187
)
182188
} else if (scheduleState.matches("submitSuccess")) {
183-
navigate(`/workspaces/${workspaceId}`)
189+
navigate(`/@${username}/${workspaceName}`)
184190
return <FullScreenLoader />
185191
} else {
186192
// Theoretically impossible - log and bail

site/src/xServices/workspaceSchedule/workspaceScheduleXService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface WorkspaceScheduleContext {
2626
}
2727

2828
export type WorkspaceScheduleEvent =
29-
| { type: "GET_WORKSPACE"; workspaceId: string }
29+
| { type: "GET_WORKSPACE"; username: string; workspaceName: string }
3030
| {
3131
type: "SUBMIT_SCHEDULE"
3232
autoStart: TypesGen.UpdateWorkspaceAutostartRequest
@@ -132,7 +132,7 @@ export const workspaceSchedule = createMachine(
132132

133133
services: {
134134
getWorkspace: async (_, event) => {
135-
return await API.getWorkspace(event.workspaceId)
135+
return await API.getWorkspaceByOwnerAndName(event.username, event.workspaceName)
136136
},
137137
submitSchedule: async (context, event) => {
138138
if (!context.workspace?.id) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy