Show sign up confirmation message (#42)

closes #41
This commit is contained in:
sua yoo 2021-12-02 10:28:22 -08:00 committed by GitHub
parent 081d6f8519
commit 9d7596589b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 4 deletions

View File

@ -1,6 +1,8 @@
import type { TemplateResult } from "lit"; import type { TemplateResult } from "lit";
import { state } from "lit/decorators.js"; import { state, query } from "lit/decorators.js";
import { ifDefined } from "lit/directives/if-defined.js";
import { msg, localized } from "@lit/localize"; import { msg, localized } from "@lit/localize";
import type { SlDialog } from "@shoelace-style/shoelace";
import "./shoelace"; import "./shoelace";
import { LocalePicker } from "./components/locale-picker"; import { LocalePicker } from "./components/locale-picker";
@ -32,6 +34,12 @@ const ROUTES = {
"archive-info-tab": "/archive/:aid/:tab", "archive-info-tab": "/archive/:aid/:tab",
} as const; } as const;
type DialogContent = {
label?: TemplateResult | string;
body?: TemplateResult | string;
noHeader?: boolean;
};
/** /**
* @event navigate * @event navigate
* @event notify * @event notify
@ -51,12 +59,18 @@ export class App extends LiteElement {
userInfo?: CurrentUser; userInfo?: CurrentUser;
@state() @state()
viewState!: ViewState & { private viewState!: ViewState & {
aid?: string; aid?: string;
// TODO common tab type // TODO common tab type
tab?: "running" | "finished" | "configs"; tab?: "running" | "finished" | "configs";
}; };
@state()
private globalDialogContent: DialogContent = {};
@query("#globalDialog")
private globalDialog!: SlDialog;
constructor() { constructor() {
super(); super();
@ -155,6 +169,14 @@ export class App extends LiteElement {
<bt-locale-picker></bt-locale-picker> <bt-locale-picker></bt-locale-picker>
</footer> </footer>
</div> </div>
<sl-dialog
id="globalDialog"
?no-header=${this.globalDialogContent?.noHeader === true}
label=${ifDefined(this.globalDialogContent?.label)}
@sl-after-hide=${() => (this.globalDialogContent = {})}
>${this.globalDialogContent?.body}</sl-dialog
>
`; `;
} }
@ -320,7 +342,12 @@ export class App extends LiteElement {
} }
onLoggedIn( onLoggedIn(
event: CustomEvent<{ api?: boolean; auth: string; username: string }> event: CustomEvent<{
api?: boolean;
firstLogin?: boolean;
auth: string;
username: string;
}>
) { ) {
const { detail } = event; const { detail } = event;
this.authState = { this.authState = {
@ -332,6 +359,10 @@ export class App extends LiteElement {
if (!detail.api) { if (!detail.api) {
this.navigate(ROUTES.myAccount); this.navigate(ROUTES.myAccount);
} }
if (detail.firstLogin) {
this.onFirstLogin({ email: detail.username });
}
} }
onNeedLogin(event?: CustomEvent<{ api: boolean }>) { onNeedLogin(event?: CustomEvent<{ api: boolean }>) {
@ -410,6 +441,41 @@ export class App extends LiteElement {
getUserInfo() { getUserInfo() {
return this.apiFetch("/users/me", this.authState!); return this.apiFetch("/users/me", this.authState!);
} }
private showDialog(content: DialogContent) {
this.globalDialogContent = content;
this.globalDialog.show();
}
private closeDialog() {
this.globalDialog.hide();
}
private onFirstLogin({ email }: { email: string }) {
this.showDialog({
label: "Welcome to Browsertrix Cloud",
noHeader: true,
body: html`
<div class="grid gap-4 text-center">
<p class="mt-8 text-2xl font-medium">Welcome to Browsertrix Cloud!</p>
<p>
A confirmation email was sent to: <br />
<strong>${email}</strong>.
</p>
<p class="max-w-xs mx-auto">
Click the link in your email to confirm your email address.
</p>
</div>
<div class="mb-4 mt-8 text-center">
<sl-button type="primary" @click=${() => this.closeDialog()}
>Got it, go to dashboard</sl-button
>
</div>
`,
});
}
} }
customElements.define("bt-alert", Alert); customElements.define("bt-alert", Alert);

View File

@ -183,7 +183,7 @@ export class SignUp extends LiteElement {
const data = await resp.json(); const data = await resp.json();
if (data.token_type === "bearer" && data.access_token) { if (data.token_type === "bearer" && data.access_token) {
const auth = "Bearer " + data.access_token; const auth = "Bearer " + data.access_token;
const detail = { auth, username: email }; const detail = { auth, username: email, firstLogin: true };
this.dispatchEvent(new CustomEvent("logged-in", { detail })); this.dispatchEvent(new CustomEvent("logged-in", { detail }));
} else { } else {
throw new Error("Unknown authorization type"); throw new Error("Unknown authorization type");

View File

@ -6,6 +6,7 @@ import { setBasePath } from "@shoelace-style/shoelace/dist/utilities/base-path.j
import "@shoelace-style/shoelace/dist/themes/light.css"; import "@shoelace-style/shoelace/dist/themes/light.css";
import "@shoelace-style/shoelace/dist/components/alert/alert"; import "@shoelace-style/shoelace/dist/components/alert/alert";
import "@shoelace-style/shoelace/dist/components/button/button"; import "@shoelace-style/shoelace/dist/components/button/button";
import "@shoelace-style/shoelace/dist/components/dialog/dialog";
import "@shoelace-style/shoelace/dist/components/form/form"; import "@shoelace-style/shoelace/dist/components/form/form";
import "@shoelace-style/shoelace/dist/components/icon/icon"; import "@shoelace-style/shoelace/dist/components/icon/icon";
import "@shoelace-style/shoelace/dist/components/input/input"; import "@shoelace-style/shoelace/dist/components/input/input";