Skip to content

Commit

Permalink
Merge branch 'dev' into fix/notification-margin
Browse files Browse the repository at this point in the history
  • Loading branch information
incredible-phoenix246 authored Aug 25, 2024
2 parents 2a54789 + e114e25 commit 98acea2
Show file tree
Hide file tree
Showing 49 changed files with 1,044 additions and 792 deletions.
1 change: 0 additions & 1 deletion hng_boilerplate_nextjs_project
Submodule hng_boilerplate_nextjs_project deleted from 8fc1b9
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"test:ci": "vitest --coverage",
"email:dev": "email dev --dir \"./src/email/templates\"",
"email:build": "email build --dir \"./src/email/templates\"",
"email:start": "email start"
"email:start": "email start",
"typecheck": "tsc --project tsconfig.json --noEmit"
},
"dependencies": {
"@hookform/resolvers": "^3.9.0",
Expand Down Expand Up @@ -67,6 +68,7 @@
"react-email": "2.1.5",
"react-hook-form": "^7.52.2",
"react-paginate": "^8.2.0",
"react-toastify": "^10.0.5",
"recharts": "^2.12.7",
"sharp": "^0.33.4",
"swiper": "^11.1.9",
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added public/images/productimage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/actions/notifications/getAllNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import axios from "axios";

import { auth } from "~/lib/auth";
import { getApiUrl } from "../getApiUrl";

const apiUrl = process.env.API_URL;

export const getAllNotifications = async () => {
const apiUrl = await getApiUrl();
const session = await auth();
try {
const response = await axios.get(`${apiUrl}/api/v1/notifications`, {
Expand Down
7 changes: 6 additions & 1 deletion src/actions/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,13 @@ export const getAnalytics = async () => {
},
});

const formattedData = Object.keys(response.data.data).map((key) => ({
month: key,
revenue: response.data.data[key],
}));

return {
data: response.data.data,
data: formattedData,
};
} catch (error) {
return axios.isAxiosError(error) && error.response
Expand Down
1 change: 0 additions & 1 deletion src/actions/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export const getAllProduct = async (org_id: string) => {
);
return {
products: response.data.data,
response: response,
};
} catch (error) {
return axios.isAxiosError(error) && error.response
Expand Down
6 changes: 3 additions & 3 deletions src/actions/socialAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import axios from "axios";

import { AuthResponse, ErrorResponse, Profile } from "~/types";
import { AuthResponse, ErrorResponse } from "~/types";

const apiUrl = process.env.API_URL;

const googleAuth = async (profile: Profile): Promise<AuthResponse> => {
const googleAuth = async (idToken: string): Promise<AuthResponse> => {
try {
const response = await axios.post(`${apiUrl}/api/v1/auth/google`, {
id_token: profile.id_token,
id_token: idToken,
});

return {
Expand Down
71 changes: 34 additions & 37 deletions src/app/(auth-routes)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useEffect, useState, useTransition } from "react";
import { useForm } from "react-hook-form";
import * as z from "zod";

import { loginUser } from "~/actions/login";
import CustomButton from "~/components/common/common-button/common-button";
import { Input } from "~/components/common/input";
import LoadingSpinner from "~/components/miscellaneous/loading-spinner";
Expand All @@ -24,28 +23,22 @@ import {
FormMessage,
} from "~/components/ui/form";
import { useToast } from "~/components/ui/use-toast";
import { useLocalStorage } from "~/hooks/use-local-storage";
import { cn } from "~/lib/utils";
import { LoginSchema } from "~/schemas";
import { Organisation } from "~/types";

const Login = () => {
const t = useTranslations("login");
const router = useRouter();
const { toast } = useToast();
const { status } = useSession();
const [isLoading, startTransition] = useTransition();
const [showPassword, setShowPassword] = useState(false);
const [, setUserOrg] = useLocalStorage<Organisation[]>("user_org", []);

const [currentOrgId, setCurrentOrgId] = useLocalStorage<string | undefined>(
"current_orgid",
"",
);
const { status } = useSession();

if (status === "authenticated") {
router.push("/dashboard");
}
useEffect(() => {
if (status === "authenticated") {
router.push("/dashboard");
}
}, [status, router]);

const form = useForm<z.infer<typeof LoginSchema>>({
resolver: zodResolver(LoginSchema),
Expand All @@ -55,34 +48,37 @@ const Login = () => {
rememberMe: false,
},
});

const onSubmit = async (values: z.infer<typeof LoginSchema>) => {
startTransition(async () => {
await loginUser(values).then(async (data) => {
const { email, password } = values;
const { email, password } = values;

if (data.status === 200) {
setUserOrg(data.organisations);
if (!currentOrgId && data.organisations.length > 0) {
setCurrentOrgId(data.organisations[0].organisation_id);
}
await signIn(
"credentials",
{
email,
password,
redirect: false,
},
{ callbackUrl: "/dashboard" },
);
try {
startTransition(async () => {
const result = await signIn("credentials", {
email,
password,
redirect: false,
});

if (result?.ok) {
router.push("/dashboard");
toast({
title: "Login success",
description: "Redirecting",
});
} else {
toast({
title: "An error occurred",
description: result?.error || "Unknown error",
});
}
toast({
title: data.status === 200 ? "Login success" : "An error occurred",
description: data.status === 200 ? "Redirecting" : data.error,
});
});
});
} catch (error) {
toast({
title: "Login failed",
description:
(error as Error).message || "An error occurred during login",
});
}
};

const togglePasswordVisibility = () => {
Expand All @@ -91,6 +87,7 @@ const Login = () => {
useEffect(() => {
document.title = "Login";
}, []);

return (
<div className="flex min-h-full items-center justify-center px-4 py-10 sm:px-6 lg:px-8">
<div className="w-full max-w-md space-y-6">
Expand All @@ -106,7 +103,7 @@ const Login = () => {
<CustomButton
variant="outline"
isLeftIconVisible={true}
onClick={() => signIn("google", { callbackUrl: "/dashboard" })}
onClick={() => signIn("google", { callbackUrl: "/" })}
icon={
<svg
width="25"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const mockSession: Session = {
last_name: "User",
email: "[email protected]",
image: "path/to/image",
role: "user",
},
access_token: "some-token",
expires: "2100-01-01T00:00:00.000Z",
Expand Down
1 change: 0 additions & 1 deletion src/app/(landing-routes)/blog/comments/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const CommentPage = () => {
last_name: "User",
email: "[email protected]",
image: "path/to/image",
role: "user",
},
access_token: "some-token",
expires: "1",
Expand Down
48 changes: 48 additions & 0 deletions src/app/(landing-routes)/blog/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,62 @@
"use client";

import axios from "axios";
import { useSession } from "next-auth/react";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";

import { getApiUrl } from "~/actions/getApiUrl";
import CustomButton from "~/components/common/common-button/common-button";
import HeroSection from "~/components/extDynamicPages/blogCollection/BlogPageHero";
import BlogCard from "~/components/layouts/BlogCards";
import { useToast } from "~/components/ui/use-toast";
import { blogPosts } from "./data/mock";

const BlogHome = () => {
const router = useRouter();
const { toast } = useToast();
const { data: session } = useSession();
const [, setBlogPost] = useState("");

useEffect(() => {
async function fetchBlog() {
try {
const apiUrl = await getApiUrl();
const token = session?.access_token;
const response = await axios.get(`${apiUrl}/api/v1/blogs`, {
headers: {
Authorization: `Bearer: ${token}`,
},
});
const data = response.data;
setBlogPost(data);
toast({
title:
Array.isArray(data.data) && data.data.length === 0
? "No Blog Post Available"
: "Blog Posts Retrieved",
description:
Array.isArray(data.data) && data.data.length === 0
? "Blog posts are empty"
: "Blog posts retrieved successfully",
variant:
Array.isArray(data.data) && data.data.length === 0
? "destructive"
: "default",
});
} catch (error) {
toast({
title: "Error occured",
description:
error instanceof Error
? error.message
: "An unknown error occurred",
variant: "destructive",
});
}
}
fetchBlog();
}, [session?.access_token, toast]);

return (
<div>
Expand Down
10 changes: 9 additions & 1 deletion src/app/(landing-routes)/contact-us/page.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { SessionProvider } from "next-auth/react";
import { ReactNode } from "react";

import { render } from "~/test/utils";
import Page from "./page";

describe("page tests", () => {
const renderWithSession = (component: ReactNode) => {
return render(
<SessionProvider session={undefined}>{component}</SessionProvider>,
);
};
it("should render correctly", () => {
expect.assertions(1);

render(<Page />);
renderWithSession(<Page />);

expect(true).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
UserRoundCog,
UsersIcon,
} from "lucide-react";
import { useSession } from "next-auth/react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { FC, ForwardRefExoticComponent, RefAttributes } from "react";

import { useOrgContext } from "~/contexts/orgContext";
import { useLocalStorage } from "~/hooks/use-local-storage";

const sideItems = [
{
Expand Down Expand Up @@ -96,10 +96,10 @@ const SettingsSidebar: FC<Iproperties> = ({ sideNavitems = sideItems }) => {
pathname?.split("/").length == 2 ? "general" : pathname?.split("/")[3];
const organizationPath = pathname?.split("/")[4];
const { organizations } = useOrgContext();
const [org_id] = useLocalStorage<string>("current_orgid", "");
const { data: session } = useSession();

const organization = organizations.find(
(org) => org.organisation_id === org_id,
(org) => org.organisation_id === session?.currentOrgId,
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { useState } from "react";

import CustomButton from "~/components/common/common-button/common-button";

interface ToggleSwitchProperties {
label: string;
description: string;
Expand All @@ -21,7 +23,7 @@ const ToggleSwitch: React.FC<ToggleSwitchProperties> = ({
return (
<div className="mb-4 rounded-md border p-6 shadow">
<div className="mb-2 flex items-center justify-between">
<label className="text-2xl text-lg font-semibold">{label}</label>
<label className="text-2xl font-semibold">{label}</label>
<label className="relative inline-block h-8 w-14">
<input
type="checkbox"
Expand Down Expand Up @@ -94,6 +96,14 @@ const Page = () => {
description="Allow us to show you personalized ads based on your interests and browsing behavior. By enabling this feature, you consent to the use of data collected from your interactions within the app and across other platforms to deliver ads that are more relevant to you."
apiEndpoint="/api/toggle-ads"
/>
<div className="mt-6 flex items-center justify-between gap-3 sm:justify-end">
<CustomButton variant="outline" className="font-[500] max-sm:w-full">
Cancel
</CustomButton>
<CustomButton variant="primary" className="font-[500] max-sm:w-full">
Save Changes
</CustomButton>
</div>
</div>
);
};
Expand Down
Loading

0 comments on commit 98acea2

Please sign in to comment.