-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretries_product_page.tsx
48 lines (42 loc) · 1.2 KB
/
retries_product_page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { GetServerSideProps } from "next";
import ProductTemplate from "@modules/products/templates";
import { getRegion, getProductByHandle } from "@lib/data/regions";
type Props = {
region: any;
product: any;
countryCode: string;
};
export const getServerSideProps: GetServerSideProps<Props> = async (context) => {
const { countryCode, handle } = context.params!;
try {
// Fetch the region based on the countryCode
const region = await getRegion(countryCode as string);
if (!region) {
return { notFound: true };
}
// Fetch the product based on the handle and region
const product = await getProductByHandle(handle as string, region.id);
if (!product) {
return { notFound: true };
}
return {
props: {
region,
product,
countryCode: countryCode as string,
},
};
} catch (error) {
console.error(`Failed to fetch product or region: ${error instanceof Error ? error.message : error}`);
return { notFound: true };
}
};
export default function ProductPage({ region, product, countryCode }: Props) {
return (
<ProductTemplate
product={product}
region={region}
countryCode={countryCode}
/>
);
}