Skip to content

Commit

Permalink
Update API logging and add product showcase component
Browse files Browse the repository at this point in the history
  • Loading branch information
MuttakinHasib committed Feb 22, 2024
1 parent 6010195 commit ce1980b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 7 deletions.
5 changes: 5 additions & 0 deletions apps/web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const nextConfig = {
},
],
},
logging: {
fetches: {
fullUrl: true,
},
},
};

module.exports = nextConfig;
8 changes: 4 additions & 4 deletions apps/web/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ api.interceptors.response.use(
return response.data;
},
async (error) => {
if (error.response.data.message) {
if (isArray(error.response.data.message)) {
if (error.response?.data?.message) {
if (isArray(error.response?.data?.message)) {
error.response.data.message.forEach((message: string) =>
toast.error(capitalize(message))
);
}
}
if (error.response.status === 401 || error.response.status === 403) {
if (error.response?.status === 401 || error.response?.status === 403) {
// window.location.reload()
}

return Promise.reject(error.response.data);
return Promise.reject(error.response?.data);
}
);

Expand Down
15 changes: 13 additions & 2 deletions apps/web/src/app/(public)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { Slideshow } from "@/components";
import { baseURL } from "@/api";
import { ProductShowCase, Slideshow } from "@/components";
import { PRODUCTS } from "@/constants";
import { IProduct } from "@/types";
import React from "react";

const HomePage = () => {
const getProducts = async (): Promise<IProduct[]> => {
const response = await fetch(baseURL + PRODUCTS + "?");
console.log("🚀 ~ getProducts ~ baseURL:", baseURL);
return await response.json();
};

const HomePage = async () => {
const products = await getProducts();
return (
<React.Fragment>
<Slideshow />
<ProductShowCase title="Popular Product" {...{ products }} />
</React.Fragment>
);
};
Expand Down
9 changes: 9 additions & 0 deletions apps/web/src/app/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use client";

import React from "react";

const ErrorPage = () => {
return <div>ErrorPage</div>;
};

export default ErrorPage;
1 change: 1 addition & 0 deletions apps/web/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from "./loader";
export * from "./ui";
export * from "./breadcrumb";
export * from "./product";
export * from "./showcase";
2 changes: 1 addition & 1 deletion apps/web/src/components/product/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Props {

export const ProductCard = memo(({ product }: Props) => {
return (
<div className="w-[calc((100%-60px)/4)] shadow-box bg-white rounded-sm relative group flex flex-col">
<div className="w-[calc((100%-40px)/3)] xl:w-[calc((100%-60px)/4)] shadow-box bg-white rounded-sm relative group flex flex-col">
<div className="absolute top-0 right-0 z-50 flex flex-col overflow-hidden">
<button
type="button"
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/showcase/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./product.showcase";
27 changes: 27 additions & 0 deletions apps/web/src/components/showcase/product.showcase.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { IProduct } from "@/types";
import React from "react";
import { ProductCard } from "..";

type Props = {
title: string;
products: IProduct[];
};

export const ProductShowCase = (props: Props) => {
const { title, products } = props;

return (
<div className="bg-white py-16">
<div className="container space-y-5">
<div className="flex items-center justify-between pb-2 border-b-2 gap-5 border-gray-100">
<h4 className="text-xl font-bold">{title}</h4>
</div>
<div className="flex flex-wrap">
{products?.map((product) => (
<ProductCard key={product.id} {...{ product }} />
))}
</div>
</div>
</div>
);
};

0 comments on commit ce1980b

Please sign in to comment.