Compare commits
3 Commits
fd00f83585
...
Fix/Fronte
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b169c11c0 | ||
|
|
35c1a861f5 | ||
|
|
27101bbdd6 |
@@ -1,6 +1,6 @@
|
|||||||
// Path: Frontend/src/components/workspace-home/WorkspaceHome/WorkspaceHome.tsx
|
// Path: Frontend/src/components/workspace-home/WorkspaceHome/WorkspaceHome.tsx
|
||||||
|
|
||||||
import { For, Show, createEffect, createMemo, createSignal, onMount, type JSX } from "solid-js";
|
import { For, Show, createEffect, createMemo, createSignal, type JSX } from "solid-js";
|
||||||
import { Portal } from "solid-js/web";
|
import { Portal } from "solid-js/web";
|
||||||
import { createStore } from "solid-js/store";
|
import { createStore } from "solid-js/store";
|
||||||
import { resolveAPIBase } from "../../../lib/api";
|
import { resolveAPIBase } from "../../../lib/api";
|
||||||
@@ -44,9 +44,6 @@ const bootstrapStepDefinitions: readonly BootstrapStepDefinition[] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const bootstrapCompletionStorageKey = "moku.bootstrap.completed";
|
|
||||||
const isDevelopmentEnvironment = import.meta.env.DEV;
|
|
||||||
|
|
||||||
const defaultInstanceForm = {
|
const defaultInstanceForm = {
|
||||||
protocol: "http",
|
protocol: "http",
|
||||||
access: "local",
|
access: "local",
|
||||||
@@ -58,7 +55,7 @@ const defaultModeForm = {
|
|||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const defaultAdminForm = {
|
const defaultAdminForm = {
|
||||||
displayName: "First admin",
|
displayName: "Admin",
|
||||||
email: "admin@example.com",
|
email: "admin@example.com",
|
||||||
password: "",
|
password: "",
|
||||||
} as const;
|
} as const;
|
||||||
@@ -83,27 +80,6 @@ const initialSubmissionState = (): BootstrapSubmissionState => ({
|
|||||||
error: "",
|
error: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const readBootstrapCompletion = (): boolean => {
|
|
||||||
if (typeof window === "undefined") {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return window.localStorage.getItem(bootstrapCompletionStorageKey) === "true";
|
|
||||||
};
|
|
||||||
|
|
||||||
const writeBootstrapCompletion = (isComplete: boolean): void => {
|
|
||||||
if (typeof window === "undefined") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isComplete) {
|
|
||||||
window.localStorage.setItem(bootstrapCompletionStorageKey, "true");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.localStorage.removeItem(bootstrapCompletionStorageKey);
|
|
||||||
};
|
|
||||||
|
|
||||||
const readResponseBody = async (response: Response): Promise<unknown> => {
|
const readResponseBody = async (response: Response): Promise<unknown> => {
|
||||||
const raw = await response.text();
|
const raw = await response.text();
|
||||||
|
|
||||||
@@ -140,13 +116,6 @@ export const WorkspaceHome = (props: WorkspaceHomeProps): JSX.Element => {
|
|||||||
const [isWizardOpen, setIsWizardOpen] = createSignal(false);
|
const [isWizardOpen, setIsWizardOpen] = createSignal(false);
|
||||||
const [currentStepIndex, setCurrentStepIndex] = createSignal(0);
|
const [currentStepIndex, setCurrentStepIndex] = createSignal(0);
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
const isComplete = readBootstrapCompletion();
|
|
||||||
setIsBootstrapComplete(isComplete);
|
|
||||||
setIsWizardOpen(!isComplete);
|
|
||||||
setIsBootstrapStateResolved(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (modeForm.mode === "personal") {
|
if (modeForm.mode === "personal") {
|
||||||
setStructureForm("departmentName", personalStructureDefaults.departmentName);
|
setStructureForm("departmentName", personalStructureDefaults.departmentName);
|
||||||
@@ -164,29 +133,28 @@ export const WorkspaceHome = (props: WorkspaceHomeProps): JSX.Element => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (!isBootstrapStateResolved()) {
|
const shellStatus = appShellData.status();
|
||||||
|
|
||||||
|
if (shellStatus === "idle" || shellStatus === "loading") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appShellData.status() !== "success") {
|
if (shellStatus !== "success") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const installation = appShellData.installation();
|
const installationAccessor = appShellData.installation;
|
||||||
|
const installation = typeof installationAccessor === "function" ? installationAccessor() : undefined;
|
||||||
const isPersistedBootstrap = installation?.isBootstrapped ?? false;
|
const isPersistedBootstrap = installation?.isBootstrapped ?? false;
|
||||||
|
const wasComplete = isBootstrapComplete();
|
||||||
|
|
||||||
if (isPersistedBootstrap) {
|
setIsBootstrapComplete(isPersistedBootstrap);
|
||||||
return;
|
setIsWizardOpen(!isPersistedBootstrap);
|
||||||
}
|
setIsBootstrapStateResolved(true);
|
||||||
|
|
||||||
if (!isBootstrapComplete() && isWizardOpen()) {
|
if (!isPersistedBootstrap && wasComplete) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
writeBootstrapCompletion(false);
|
|
||||||
setIsBootstrapComplete(false);
|
|
||||||
setIsWizardOpen(true);
|
|
||||||
resetWizardState();
|
resetWizardState();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const sidebarToggleLabel = (): string =>
|
const sidebarToggleLabel = (): string =>
|
||||||
@@ -278,9 +246,13 @@ export const WorkspaceHome = (props: WorkspaceHomeProps): JSX.Element => {
|
|||||||
|
|
||||||
if (isLastStep()) {
|
if (isLastStep()) {
|
||||||
await appShellData.reload();
|
await appShellData.reload();
|
||||||
writeBootstrapCompletion(true);
|
const installationAccessor = appShellData.installation;
|
||||||
setIsBootstrapComplete(true);
|
const installation = typeof installationAccessor === "function" ? installationAccessor() : undefined;
|
||||||
setIsWizardOpen(false);
|
const isPersistedBootstrap = installation?.isBootstrapped ?? false;
|
||||||
|
|
||||||
|
setIsBootstrapComplete(isPersistedBootstrap);
|
||||||
|
setIsWizardOpen(!isPersistedBootstrap);
|
||||||
|
setIsBootstrapStateResolved(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,32 +264,6 @@ export const WorkspaceHome = (props: WorkspaceHomeProps): JSX.Element => {
|
|||||||
void submitCurrentStep();
|
void submitCurrentStep();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDevelopmentReset = async (): Promise<void> => {
|
|
||||||
const response = await fetch(`${apiBase()}/dev/bootstrap/reset`, {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
Accept: "application/json",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const data = await readResponseBody(response);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(
|
|
||||||
typeof data?.message === "string"
|
|
||||||
? data.message
|
|
||||||
: typeof data?.error?.message === "string"
|
|
||||||
? data.error.message
|
|
||||||
: "Failed to reset development bootstrap state.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
writeBootstrapCompletion(false);
|
|
||||||
setIsBootstrapComplete(false);
|
|
||||||
setIsWizardOpen(true);
|
|
||||||
resetWizardState();
|
|
||||||
await appShellData.reload();
|
|
||||||
};
|
|
||||||
|
|
||||||
const statusLabel = (state: BootstrapSubmissionState): string => {
|
const statusLabel = (state: BootstrapSubmissionState): string => {
|
||||||
switch (state.status) {
|
switch (state.status) {
|
||||||
case "submitting":
|
case "submitting":
|
||||||
@@ -379,20 +325,6 @@ export const WorkspaceHome = (props: WorkspaceHomeProps): JSX.Element => {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={isDevelopmentEnvironment && isBootstrapStateResolved()}>
|
|
||||||
<div class={styles.heroActions}>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class={styles.secondaryButton}
|
|
||||||
data-slot="development-bootstrap-reset"
|
|
||||||
onClick={() => {
|
|
||||||
void handleDevelopmentReset();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Reset development bootstrap state
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</Show>
|
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
@@ -500,7 +432,7 @@ export const WorkspaceHome = (props: WorkspaceHomeProps): JSX.Element => {
|
|||||||
type="text"
|
type="text"
|
||||||
value={adminForm.displayName}
|
value={adminForm.displayName}
|
||||||
onInput={(event): void => setAdminForm("displayName", event.currentTarget.value)}
|
onInput={(event): void => setAdminForm("displayName", event.currentTarget.value)}
|
||||||
placeholder="First admin"
|
placeholder="Admin"
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<label class={styles.field}>
|
<label class={styles.field}>
|
||||||
|
|||||||
Reference in New Issue
Block a user