Skip to content

Commit

Permalink
Merge branch 'dev' into HNG-External-static-payment-page
Browse files Browse the repository at this point in the history
  • Loading branch information
Maiqel1 authored Aug 1, 2024
2 parents 0c855c9 + 6c8d857 commit da5498d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/app/(auth-routes)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const Login = () => {
await loginAuth(values).then(async (data) => {
const { email, password } = values;

if (data.status === 200) {
if (data) {
await signIn(
"credentials",
{
Expand All @@ -82,8 +82,8 @@ const Login = () => {
router.push("/dashboard");
}
toast({
title: data.status === 200 ? "login success" : "an error occurred",
description: data.status === 200 ? "routing now" : data.error,
title: data.status === 200 ? "Login success" : "An error occurred",
description: data.status === 200 ? "Redirecting" : data.error,
});
});
});
Expand Down
11 changes: 6 additions & 5 deletions src/app/(auth-routes)/register/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useToast } from "~/components/ui/use-toast";
import { cn } from "~/lib/utils";
import { RegisterSchema } from "~/schemas";
import { getApiUrl } from "~/utils/getApiUrl";
import { registerUser } from "~/utils/register";
import { registerAuth } from "~/utils/registerAuth";

const Register = () => {
const router = useRouter();
Expand Down Expand Up @@ -66,19 +66,20 @@ const Register = () => {

const onSubmit = async (values: z.infer<typeof RegisterSchema>) => {
startTransition(async () => {
await registerUser(values).then(async (data) => {
if (data.status === 201) {
await registerAuth(values).then(async (data) => {
if (data) {
sessionStorage.setItem("temp_token", data.access_token);
router.push("/register/organisation");
}

toast({
title:
data.status === 201
? "Accounted created successfully"
? "Account created successfully"
: "an error occurred",
description: data.status === 201 ? "Continue to login" : data.error,
description: data.status === 201 ? "Redirecting" : data.error,
});
router.push("/register/organisation");
});
});
};
Expand Down
19 changes: 11 additions & 8 deletions src/app/(landing-routes)/career/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,32 @@ import { useEffect, useState } from "react";
import CareerCardParent from "~/components/common/CareerCard";
import { Job } from "~/components/common/CareerCard/Jobs";
import Pagination from "~/components/layouts/pagination/Pagination";
import { getApiUrl } from "~/utils/getApiUrl";
import Nojobs from "./Nojobs";

export default function Career() {
const [allJobs, setAllJobs] = useState<Job[]>([]);
const [baseUrl, setBaseUrl] = useState<string>("");
const [displayedJobs, setDisplayedJobs] = useState<Job[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [currentPage, setCurrentPage] = useState(1);
const pageSize = 6;
const router = useRouter();

useEffect(() => {
getApiUrl().then((url) => setBaseUrl(url));
}, []);

useEffect(() => {
const fetchJobs = async () => {
setIsLoading(true);
try {
const response = await fetch(
`https://deployment.api-nestjs.boilerplate.hng.tech/api/v1/jobs`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
const response = await fetch(`${baseUrl}/api/v1/jobs`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
);
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
Expand Down
27 changes: 15 additions & 12 deletions src/utils/register.ts → src/utils/registerAuth.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use server";

import axios from "axios";
import { cookies } from "next/headers";
import * as z from "zod";

import { OtpSchema, RegisterSchema } from "~/schemas";

const apiUrl = process.env.API_URL;
const team = process.env.TEAM;

export const registerUser = async (values: z.infer<typeof RegisterSchema>) => {
export const registerAuth = async (values: z.infer<typeof RegisterSchema>) => {
const cookie = cookies();
const validatedFields = RegisterSchema.safeParse(values);
if (!validatedFields.success) {
return {
Expand All @@ -20,12 +20,17 @@ export const registerUser = async (values: z.infer<typeof RegisterSchema>) => {
`${apiUrl}/api/v1/auth/register`,
validatedFields.data,
);
return {
team: team,
status: response.status,
data: response.data,
access_token: response.data.access_token,
};
const access_token =
response.data.access_token ?? response.data.data.access_token;

cookie.set("access_token", access_token, {
maxAge: 60 * 60 * 24 * 1,
httpOnly: true,
path: "/",
priority: "high",
});

return response?.data?.user;
} catch (error) {
return axios.isAxiosError(error) && error.response
? {
Expand All @@ -41,10 +46,8 @@ export const registerUser = async (values: z.infer<typeof RegisterSchema>) => {
export const verifyOtp = async (values: z.infer<typeof OtpSchema>) => {
const otp = values.otp;
const token = values.token;
const email = values.email;

const payload =
team === "panther" ? { otp: Number(otp), token: token } : { token, email };
const payload = { otp: Number(otp), token: token };

try {
const response = await axios.post(
Expand Down

0 comments on commit da5498d

Please sign in to comment.