-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathonboarding-form.component.tsx
More file actions
40 lines (33 loc) · 1.04 KB
/
onboarding-form.component.tsx
File metadata and controls
40 lines (33 loc) · 1.04 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
import { useEffect, useState } from "react";
import { Form } from "../form";
import { useOnboarding } from "./onboarding-context.hook";
import { useSlashID } from "../../hooks/use-slash-id";
export function OnboardingForm() {
const id = "onboarding-login-form";
// wrapper for the login/signup form
const { state, api } = useOnboarding();
const { isLoading, isAuthenticated } = useSlashID();
const [registered, setRegistered] = useState(false);
useEffect(() => {
if (!registered) {
api.registerStep(id);
setRegistered(true);
}
}, [api, registered]);
if (!registered || state.completionState === "complete") {
return null;
}
if (state.currentStepId !== id) {
return null;
}
// skip this step if the user is already logged in
if (isLoading || isAuthenticated) {
return null;
}
const handleLogin = () => {
// we can keep using the anonymous user as it is the same one that is used for onboarding
api.nextStep();
};
// TODO needs a back button
return <Form onSuccess={handleLogin} />;
}