-
-
Notifications
You must be signed in to change notification settings - Fork 354
/
member-onboarding.tsx
150 lines (133 loc) · 4.22 KB
/
member-onboarding.tsx
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import Button from "@/components/ui/Button";
import TextInput from "@/components/TextInput";
import CenteredForm from "@/layouts/CenteredForm";
import Link from "next/link";
import { useRouter } from "next/router";
import { FormEvent, useState } from "react";
import { toast } from "react-hot-toast";
import getServerSideProps from "@/lib/client/getServerSideProps";
import { Trans, useTranslation } from "next-i18next";
import { useUpdateUser, useUser } from "@/hooks/store/user";
interface FormData {
password: string;
name: string;
}
export default function MemberOnboarding() {
const { t } = useTranslation();
const [submitLoader, setSubmitLoader] = useState(false);
const router = useRouter();
const [form, setForm] = useState<FormData>({
password: "",
name: "",
});
const { data: user = {} } = useUser();
const updateUser = useUpdateUser();
async function submit(event: FormEvent<HTMLFormElement>) {
event.preventDefault();
if (form.password !== "" && form.name !== "" && !submitLoader) {
setSubmitLoader(true);
const load = toast.loading(t("sending_password_recovery_link"));
await updateUser.mutateAsync(
{
...user,
name: form.name,
password: form.password,
},
{
onSuccess: (data) => {
router.push("/dashboard");
},
onSettled: (data, error) => {
setSubmitLoader(false);
toast.dismiss(load);
if (error) {
toast.error(error.message);
} else {
toast.success(t("settings_applied"));
}
},
}
);
} else {
toast.error(t("please_fill_all_fields"));
}
}
return (
<CenteredForm>
<form onSubmit={submit}>
<div className="p-4 mx-auto flex flex-col gap-3 justify-between max-w-[30rem] min-w-80 w-full bg-base-200 rounded-2xl shadow-md border border-neutral-content">
<p className="text-3xl text-center font-extralight">
{t("invitation_accepted")}
</p>
<div className="divider my-0"></div>
<p
style={{
whiteSpace: "pre-line",
}}
>
{t("invitation_desc", {
owner: user?.parentSubscription?.user?.email,
})}
</p>
<div>
<p className="text-sm w-fit font-semibold mb-1">
{t("display_name")}
</p>
<TextInput
autoFocus
placeholder="John Doe"
value={form.name}
className="bg-base-100"
onChange={(e) => setForm({ ...form, name: e.target.value })}
/>
</div>
<div>
<p className="text-sm w-fit font-semibold mb-1">
{t("new_password")}
</p>
<TextInput
type="password"
placeholder="••••••••••••••"
value={form.password}
className="bg-base-100"
onChange={(e) => setForm({ ...form, password: e.target.value })}
/>
</div>
{process.env.NEXT_PUBLIC_STRIPE && (
<div className="text-xs text-neutral mb-3">
<p>
<Trans
i18nKey="sign_up_agreement"
components={[
<Link
href="https://linkwarden.app/tos"
className="font-semibold"
data-testid="terms-of-service-link"
key={0}
/>,
<Link
href="https://linkwarden.app/privacy-policy"
className="font-semibold"
data-testid="privacy-policy-link"
key={1}
/>,
]}
/>
</p>
</div>
)}
<Button
type="submit"
intent="accent"
className="mt-2"
size="full"
loading={submitLoader}
>
{t("continue_to_dashboard")}
</Button>
</div>
</form>
</CenteredForm>
);
}
export { getServerSideProps };