forked from stoatchat/for-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlowCreate.tsx
More file actions
103 lines (92 loc) · 2.75 KB
/
FlowCreate.tsx
File metadata and controls
103 lines (92 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { Trans } from "@lingui-solid/solid/macro";
import { useApi, useClient } from "@revolt/client";
import { CONFIGURATION } from "@revolt/common";
import { useNavigate, useParams } from "@revolt/routing";
import { Button, Row, iconSize } from "@revolt/ui";
import MdArrowBack from "@material-design-icons/svg/filled/arrow_back.svg?component-solid";
import { Show } from "solid-js";
import { FlowTitle } from "./Flow";
import { setFlowCheckEmail } from "./FlowCheck";
import { Fields, Form } from "./Form";
/**
* Flow for creating a new account
*/
export default function FlowCreate() {
const api = useApi();
const getClient = useClient();
const navigate = useNavigate();
const { code } = useParams();
/**
* Create an account
* @param data Form Data
*/
async function create(data: FormData) {
const email = data.get("email") as string;
const password = data.get("password") as string;
const captcha = data.get("captcha") as string;
const invite = data.get("invite") as string;
await api.post("/auth/account/create", {
email,
password,
captcha,
...(invite ? { invite } : {}),
});
// FIXME: should tell client if email was sent
// or if email even needs to be confirmed
// TODO: log straight in if no email confirmation?
setFlowCheckEmail(email);
navigate("/login/check", { replace: true });
}
const isInviteOnly = () => {
const client = getClient();
if (client.configured) {
return client.configuration?.features.invite_only;
}
return false;
};
return (
<>
<FlowTitle subtitle={<Trans>Create an account</Trans>} emoji="wave">
<Trans>Hello!</Trans>
</FlowTitle>
<Form onSubmit={create} captcha={CONFIGURATION.HCAPTCHA_SITEKEY}>
<Fields fields={["email", "password"]} />
<Show when={isInviteOnly()}>
<Fields
fields={[
{ field: "invite", value: code, disabled: code?.length > 0 },
]}
/>
</Show>
<Row justify>
<a href="..">
<Button variant="text">
<MdArrowBack {...iconSize("1.2em")} /> <Trans>Back</Trans>
</Button>
</a>
<Button type="submit">
<Trans>Register</Trans>
</Button>
</Row>
</Form>
{import.meta.env.DEV && (
<div
style={{
position: "fixed",
top: 0,
left: 0,
background: "white",
color: "black",
cursor: "pointer",
}}
onClick={() => {
setFlowCheckEmail("insert@stoat.chat");
navigate("/login/check", { replace: true });
}}
>
Mock Submission
</div>
)}
</>
);
}