diff --git a/package.json b/package.json index 710f70f9f..7d34b4ceb 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,8 @@ "lenis": "^1.1.6", "lucide-react": "^0.400.0", "moment": "^2.30.1", - "next": "14.2.5", - "next-auth": "5.0.0-beta.20", + "next": "^14.2.5", + "next-auth": "5.0.0-beta.19", "next-nprogress-bar": "^2.3.13", "react": "^18", "react-day-picker": "^8.10.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6f0543369..40ad00a6a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -102,7 +102,7 @@ importers: specifier: ^2.30.1 version: 2.30.1 next: - specifier: 14.2.5 + specifier: ^14.2.5 version: 14.2.5(@babel/core@7.24.5)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) next-auth: specifier: 5.0.0-beta.20 diff --git a/src/app/(auth-routes)/register/page.tsx b/src/app/(auth-routes)/register/page.tsx index 9e906bc13..9295f189b 100644 --- a/src/app/(auth-routes)/register/page.tsx +++ b/src/app/(auth-routes)/register/page.tsx @@ -2,10 +2,11 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { DialogContent, DialogTitle } from "@radix-ui/react-dialog"; -import { signIn } from "next-auth/react"; +import axios from "axios"; import Link from "next/link"; +import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; -import { useForm } from "react-hook-form"; +import { SubmitHandler, useForm } from "react-hook-form"; import { z } from "zod"; import CustomButton from "~/components/common/common-button/common-button"; @@ -42,7 +43,10 @@ const formSchema = z.object({ type FormData = z.infer; const SignUp = () => { - const [apiUrl, setApiUrl] = useState(""); + const router = useRouter(); + const [apiUrl, setApiUrl] = useState( + "https://deployment.api-nestjs.boilerplate.hng.tech/api/v1/auth/register", + ); const { toast } = useToast(); useEffect(() => { @@ -50,6 +54,8 @@ const SignUp = () => { try { const url = await getApiUrl(); setApiUrl(url); + // eslint-disable-next-line no-console + console.log("API URL set to:", url); } catch { toast({ title: "Error", @@ -62,23 +68,62 @@ const SignUp = () => { fetchApiUrl(); }, [toast]); + // eslint-disable-next-line prettier/prettier + + const form = useForm({ resolver: zodResolver(formSchema), }); + const [open, setOpen] = useState(false); - const handleFormSubmit = () => { - form.handleSubmit(() => { - if (form.formState.isValid) { - setOpen(true); + const handleSubmit = async (data: FormData) => { + try { + if (!apiUrl) { + throw new Error("API URL is not available"); } - })(); - }; - const handleSubmit = () => { - form.handleSubmit(handleFormSubmit)(); + const nameParts = data.fullname.trim().split(/\s+/); + const first_name = nameParts[0]; + const last_name = nameParts.slice(1).join(""); + + const apiData = { + first_name, + last_name, + email: data.email, + password: data.password, + }; + + const response = await axios.post(`${apiUrl}`, apiData); + if (response.status === 200 || response.status === 201) { + toast({ + title: "Success", + description: "Account created successfully!", + }); + // Redirect to login page or dashboard + router.push("/login"); + } + } catch (error: unknown) { + if (axios.isAxiosError(error)) { + toast({ + title: "Error", + description: + error.response?.data?.message || + "Failed to create account. Please try again.", + variant: "destructive", + }); + } else { + toast({ + title: "Error", + description: "An unexpected error occurred. Please try again.", + variant: "destructive", + }); + } + } }; + const onSubmit: SubmitHandler = (data) => handleSubmit(data); + return (
@@ -92,7 +137,11 @@ const SignUp = () => { isDisabled={!apiUrl} variant="outline" isLeftIconVisible={true} - onClick={() => signIn("google")} + href={ + apiUrl === "" + ? undefined + : `${apiUrl}/api/v1/auth/social/google?provider=google` + } icon={ { {
- { - event.preventDefault(); - handleSubmit(); - }} - > + { )} /> - + Create Account diff --git a/src/app/(landing-routes)/career/[slug]/page.tsx b/src/app/(landing-routes)/career/[slug]/page.tsx index 6d682c50d..f2389d49b 100644 --- a/src/app/(landing-routes)/career/[slug]/page.tsx +++ b/src/app/(landing-routes)/career/[slug]/page.tsx @@ -1,6 +1,7 @@ "use client"; import { Plus } from "lucide-react"; +import Link from "next/link"; import { useEffect, useState } from "react"; import { Breadcrumb } from "~/components/common/breadcrumb"; @@ -43,7 +44,7 @@ const JobDetails = () => {
-
+

@@ -209,17 +210,19 @@ const JobDetails = () => {

-
- } - isLeftIconVisible={isSmallScreen} - isDisabled={false} - className={`h-[50px] w-[250px]`} - > - Apply Now - +
+ + } + isLeftIconVisible={isSmallScreen} + isDisabled={false} + className={`h-[50px] w-[250px]`} + > + Apply Now + +
); diff --git a/src/app/(landing-routes)/help-center/page.tsx b/src/app/(landing-routes)/help-center/page.tsx index 514d7e4b8..f7bc14467 100644 --- a/src/app/(landing-routes)/help-center/page.tsx +++ b/src/app/(landing-routes)/help-center/page.tsx @@ -15,39 +15,39 @@ const HelpCenter = () => { return (
-
+
Help Center -
+

- How can we help You? + How can we help You?

Find advice and answers from our support team

-
- - -
+
+
+ +
@@ -55,12 +55,12 @@ const HelpCenter = () => {
Browse by topics @@ -68,11 +68,11 @@ const HelpCenter = () => {
-
-
+
+

@@ -85,7 +85,7 @@ const HelpCenter = () => { Contact us @@ -96,12 +96,12 @@ const HelpCenter = () => {

-
+
-

+

Didn’t find an answer?

-

+

Contact us for more inquiries and information about our services.

diff --git a/src/components/layouts/pagination/PaginationHook.tsx b/src/components/layouts/pagination/PaginationHook.tsx new file mode 100644 index 000000000..7bab4506d --- /dev/null +++ b/src/components/layouts/pagination/PaginationHook.tsx @@ -0,0 +1,38 @@ +// usePagination.ts +import { useEffect, useState } from "react"; + +interface UsePaginationProperties { + totalItems: number; + itemsPerPage: number; + initialPage?: number; +} + +interface UsePaginationReturn { + currentPage: number; + pageCount: number; + changePage: (page: number) => void; +} + +export function usePagination({ + totalItems, + itemsPerPage, + initialPage = 1, +}: UsePaginationProperties): UsePaginationReturn { + const [currentPage, setCurrentPage] = useState(initialPage); + const [pageCount, setPageCount] = useState(0); + + useEffect(() => { + setPageCount(Math.ceil(totalItems / itemsPerPage)); + }, [totalItems, itemsPerPage]); + + const changePage = (page: number) => { + const pageNumber = Math.max(1, Math.min(page, pageCount)); + setCurrentPage(pageNumber); + }; + + return { + currentPage, + pageCount, + changePage, + }; +}