fix: make pretty & work correctly

This commit is contained in:
Anish Lakhwara 2023-08-02 16:36:28 -07:00
parent 06918c967b
commit 2f26fcefce

View File

@ -29,6 +29,7 @@ type FormEvent =
| { type: "SHOW_FORGOT_PASSWORD" } | { type: "SHOW_FORGOT_PASSWORD" }
| { type: "SUBMIT" } | { type: "SUBMIT" }
| { type: "BACKEND_INITIALIZED" } | { type: "BACKEND_INITIALIZED" }
| { type: "BACKEND_NOT_INITIALIZED" }
| FormSuccessEvent | FormSuccessEvent
| FormErrorEvent; | FormErrorEvent;
@ -63,7 +64,7 @@ const initialContext = {};
const machine = createMachine<FormContext, FormEvent, FormTypestate>( const machine = createMachine<FormContext, FormEvent, FormTypestate>(
{ {
id: "loginForm", id: "loginForm",
initial: "backendInitializing", initial: "signIn",
context: initialContext, context: initialContext,
states: { states: {
["signIn"]: { ["signIn"]: {
@ -76,6 +77,9 @@ const machine = createMachine<FormContext, FormEvent, FormTypestate>(
target: "signingIn", target: "signingIn",
actions: "reset", actions: "reset",
}, },
BACKEND_NOT_INITIALIZED: {
target: "backendInitializing",
},
}, },
}, },
["signingIn"]: { ["signingIn"]: {
@ -133,7 +137,7 @@ const machine = createMachine<FormContext, FormEvent, FormTypestate>(
...(event as FormErrorEvent).detail, ...(event as FormErrorEvent).detail,
})), })),
}, },
}, }
); );
@localized() @localized()
@ -295,11 +299,34 @@ export class LogInPage extends LiteElement {
private renderBackendInitializing() { private renderBackendInitializing() {
return html` return html`
<form @submit=${this.onSubmitLogIn} aria-describedby="formError">
<div class="mb-5"> <div class="mb-5">
<dialog id="backend-initializing" open> <btrix-input
<p> Please wait while the backend initializes </p> id="email"
</dialog> name="username"
label=${msg("Email")}
type="email"
autocomplete="username"
required
>
</btrix-input>
</div> </div>
<div class="mb-5">
<btrix-input
id="password"
name="password"
label=${msg("Password")}
type="password"
autocomplete="current-password"
passwordToggle
required
>
</btrix-input>
<dialog id="backend-initializing" open>
<p>Please wait while the backend initializes</p>
</dialog>
</div>
</form>
`; `;
} }
@ -346,11 +373,10 @@ export class LogInPage extends LiteElement {
async checkBackendInitialized() { async checkBackendInitialized() {
const resp = await fetch("/api/settings"); const resp = await fetch("/api/settings");
if (resp.status === 200) { if (resp.status === 200) {
const Dialog = <HTMLDialogElement>document.getElementById("backend-initializing");
Dialog.close()
this.formStateService.send("BACKEND_INITIALIZED"); this.formStateService.send("BACKEND_INITIALIZED");
} else { } else {
setTimeout(this.checkBackendInitialized, 5000); this.formStateService.send("BACKEND_NOT_INITIALIZED");
setTimeout(() => this.checkBackendInitialized(), 5000);
} }
} }
@ -411,7 +437,7 @@ export class LogInPage extends LiteElement {
type: "SUCCESS", type: "SUCCESS",
detail: { detail: {
successMessage: msg( successMessage: msg(
"Successfully received your request. You will receive an email to reset your password if your email is found in our system.", "Successfully received your request. You will receive an email to reset your password if your email is found in our system."
), ),
}, },
}); });