From 15562f8ca886e0669fe7cbc9d80a5b867238e2f7 Mon Sep 17 00:00:00 2001 From: Prudent Bird Date: Mon, 29 Jul 2024 12:14:58 +0100 Subject: [PATCH 1/2] chore: social auth for registration - team kimiko --- src/app/(auth-routes)/register/page.tsx | 133 +++++++++++++++++++----- src/utils/getApiUrl.ts | 11 ++ 2 files changed, 116 insertions(+), 28 deletions(-) create mode 100644 src/utils/getApiUrl.ts diff --git a/src/app/(auth-routes)/register/page.tsx b/src/app/(auth-routes)/register/page.tsx index e5845f651..333dc2db2 100644 --- a/src/app/(auth-routes)/register/page.tsx +++ b/src/app/(auth-routes)/register/page.tsx @@ -2,14 +2,13 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { DialogContent, DialogTitle } from "@radix-ui/react-dialog"; -import Image from "next/image"; import Link from "next/link"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { z } from "zod"; +import CustomButton from "~/components/common/common-button/common-button"; import { DialogDemo } from "~/components/common/Dialog"; -import { Button } from "~/components/ui/button"; import { Form, FormControl, @@ -24,6 +23,7 @@ import { InputOTPGroup, InputOTPSlot, } from "~/components/ui/input-otp"; +import { getApiUrl } from "~/utils/getApiUrl"; const formSchema = z.object({ fullname: z.string().min(2, { @@ -40,6 +40,21 @@ const formSchema = z.object({ type FormData = z.infer; const SignUp = () => { + const [apiUrl, setApiUrl] = useState(""); + + useEffect(() => { + const fetchApiUrl = async () => { + try { + const url = await getApiUrl(); + setApiUrl(url); + } catch (error) { + console.error("Failed to fetch API URL:", error); + } + }; + + fetchApiUrl(); + }, []); + const form = useForm({ resolver: zodResolver(formSchema), }); @@ -53,7 +68,9 @@ const SignUp = () => { })(); }; - const handleSubmit = () => { + const handleSubmit = async () => { + console.log(apiUrl); + form.handleSubmit(handleFormSubmit)(); }; @@ -66,26 +83,77 @@ const SignUp = () => {

- - + + + + + + + } + > + Sign up with Google + + + + + + + + + + + + } + > + Sign up with Facebook +
@@ -157,9 +225,14 @@ const SignUp = () => { )} /> - + { ))} - +

Would you rather use email and password? diff --git a/src/utils/getApiUrl.ts b/src/utils/getApiUrl.ts new file mode 100644 index 000000000..465b50b85 --- /dev/null +++ b/src/utils/getApiUrl.ts @@ -0,0 +1,11 @@ +"use server"; + +export const getApiUrl = async (): Promise => { + const apiUrl = process.env.API_URL; + + if (!apiUrl) { + throw new Error("API_URL environment variable is not defined"); + } + + return apiUrl; +}; \ No newline at end of file From 4eccc7dafcb98abbcb8993996eecbb6f1560a6fe Mon Sep 17 00:00:00 2001 From: Prudent Bird Date: Mon, 29 Jul 2024 12:37:35 +0100 Subject: [PATCH 2/2] chore: fixed lint errors --- src/app/(auth-routes)/register/page.tsx | 14 +++++++++----- src/utils/getApiUrl.ts | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/app/(auth-routes)/register/page.tsx b/src/app/(auth-routes)/register/page.tsx index 333dc2db2..2c4d59ced 100644 --- a/src/app/(auth-routes)/register/page.tsx +++ b/src/app/(auth-routes)/register/page.tsx @@ -23,6 +23,7 @@ import { InputOTPGroup, InputOTPSlot, } from "~/components/ui/input-otp"; +import { useToast } from "~/components/ui/use-toast"; import { getApiUrl } from "~/utils/getApiUrl"; const formSchema = z.object({ @@ -41,19 +42,24 @@ type FormData = z.infer; const SignUp = () => { const [apiUrl, setApiUrl] = useState(""); + const { toast } = useToast(); useEffect(() => { const fetchApiUrl = async () => { try { const url = await getApiUrl(); setApiUrl(url); - } catch (error) { - console.error("Failed to fetch API URL:", error); + } catch { + toast({ + title: "Error", + description: "Failed to fetch API URL", + variant: "destructive", + }); } }; fetchApiUrl(); - }, []); + }, [toast]); const form = useForm({ resolver: zodResolver(formSchema), @@ -69,8 +75,6 @@ const SignUp = () => { }; const handleSubmit = async () => { - console.log(apiUrl); - form.handleSubmit(handleFormSubmit)(); }; diff --git a/src/utils/getApiUrl.ts b/src/utils/getApiUrl.ts index 465b50b85..2579b1996 100644 --- a/src/utils/getApiUrl.ts +++ b/src/utils/getApiUrl.ts @@ -8,4 +8,4 @@ export const getApiUrl = async (): Promise => { } return apiUrl; -}; \ No newline at end of file +};