Skip to content

Commit 917047e

Browse files
committed
refactor a bit
1 parent b5e7fcf commit 917047e

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

site/src/pages/CreateWorkspacePage/CreateWorkspacePage.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ const CreateWorkspacePage: FC = () => {
4141
const [searchParams, setSearchParams] = useSearchParams();
4242
const { experiments } = useDashboard();
4343

44-
const mode = getWorkspaceMode(searchParams);
4544
const customVersionId = searchParams.get("version") ?? undefined;
4645
const defaultName = searchParams.get("name");
4746
const disabledParams = searchParams.get("disable_params")?.split(",");
48-
// `?mode=auto` is set, but a prerequisite was not met, and so has been disabled.
49-
const [isAutoCreateTainted, setIsAutoCreateTainted] = useState(false);
47+
const [mode, setMode] = useState(() => getWorkspaceMode(searchParams));
5048

5149
const queryClient = useQueryClient();
5250
const autoCreateWorkspaceMutation = useMutation(
@@ -136,16 +134,25 @@ const CreateWorkspacePage: FC = () => {
136134
externalAuth?.every((auth) => auth.optional || auth.authenticated),
137135
);
138136

139-
if (!isLoadingExternalAuth && !hasAllRequiredExternalAuth) {
137+
let autoStartReady =
138+
mode === "auto" &&
139+
(!autofillEnabled || userParametersQuery.isSuccess) &&
140+
hasAllRequiredExternalAuth;
141+
142+
// `mode=auto` was set, but a prequisite has failed, and so auto-mode should be abandoned.
143+
if (
144+
mode === "auto" &&
145+
!isLoadingExternalAuth &&
146+
!hasAllRequiredExternalAuth
147+
) {
140148
// Prevent suddenly resuming auto-mode if the user connects to all of the required
141149
// external auth providers.
142-
setIsAutoCreateTainted(true);
150+
setMode("form");
151+
// Ensure this is always false, so that we don't ever let `automateWorkspaceCreation`
152+
// fire when we're trying to disable it.
153+
autoStartReady = false;
143154
}
144-
const autoStartReady =
145-
mode === "auto" &&
146-
(!autofillEnabled || userParametersQuery.isSuccess) &&
147-
hasAllRequiredExternalAuth &&
148-
!isAutoCreateTainted;
155+
149156
useEffect(() => {
150157
if (autoStartReady) {
151158
void automateWorkspaceCreation();

0 commit comments

Comments
 (0)