Skip to content

Commit dbdee2b

Browse files
committed
feat: connect onboarding form to db
1 parent c67d562 commit dbdee2b

File tree

4 files changed

+59
-13
lines changed

4 files changed

+59
-13
lines changed

apps/dashboard/src/@/constants/auth.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const LOGGED_IN_ONLY_PATHS = [
2+
// must be logged in to go through onboarding
3+
"/onboarding",
24
// anything that _starts_ with /dashboard is logged in only
35
"/dashboard",
46
// team pages are logged in only

apps/dashboard/src/@3rdweb-sdk/react/hooks/useApi.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,17 @@ export interface BillingCredit {
259259

260260
interface UseAccountInput {
261261
refetchInterval?:
262-
| number
263-
| false
264-
| ((
265-
query: Query<
266-
Account,
267-
Error,
268-
Account,
269-
readonly ["account", string, "me"]
270-
>,
271-
) => number | false | undefined)
272-
| undefined;
262+
| number
263+
| false
264+
| ((
265+
query: Query<
266+
Account,
267+
Error,
268+
Account,
269+
readonly ["account", string, "me"]
270+
>,
271+
) => number | false | undefined)
272+
| undefined;
273273
}
274274

275275
export function useAccount({ refetchInterval }: UseAccountInput = {}) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { getThirdwebClient } from "@/constants/thirdweb.server";
2+
import { AutoConnect } from "thirdweb/react";
3+
4+
export default function OnboardingLayout({
5+
children,
6+
}: { children: React.ReactNode }) {
7+
const thirdwebClient = getThirdwebClient();
8+
9+
return (
10+
<>
11+
<AutoConnect client={thirdwebClient} />
12+
{children}
13+
</>
14+
);
15+
}

apps/dashboard/src/app/onboarding/page.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import {
2828
useForm,
2929
} from "react-hook-form";
3030
import { FormErrorMessage, FormLabel } from "tw-components";
31+
import { THIRDWEB_ANALYTICS_API_HOST } from "constants/urls";
32+
import { useAccount } from "@3rdweb-sdk/react/hooks/useApi";
33+
import { useRouter } from "next/navigation";
3134

3235
interface FormData {
3336
email: string;
@@ -63,8 +66,10 @@ const RadioGroupItemButton = React.forwardRef<
6366
});
6467

6568
export default function OnboardingPage() {
69+
const accountQuery = useAccount();
6670
const [step, setStep] = useState(1);
6771
const [direction, setDirection] = useState(1);
72+
const router = useRouter();
6873

6974
const {
7075
register,
@@ -80,8 +85,32 @@ export default function OnboardingPage() {
8085
},
8186
});
8287

83-
const onSubmit: SubmitHandler<FormData> = (data) => {
84-
console.log(data);
88+
const onSubmit: SubmitHandler<FormData> = async (data) => {
89+
const res = await fetch(
90+
`${THIRDWEB_ANALYTICS_API_HOST}/v1/preferences/account`,
91+
{
92+
method: "POST",
93+
headers: {
94+
"Content-Type": "application/json",
95+
},
96+
body: JSON.stringify({
97+
accountId: accountQuery.data?.id,
98+
userType: data.userType,
99+
role: data.role,
100+
industry: data.industry,
101+
name: data.name,
102+
email: data.email,
103+
interests: data.interests,
104+
}),
105+
},
106+
);
107+
const json = await res.json();
108+
109+
if (res.status !== 200) {
110+
throw new Error(json.message);
111+
}
112+
113+
router.push("/dashboard");
85114
};
86115

87116
const watchInterests = watch("interests");

0 commit comments

Comments
 (0)