-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ildecimo/develop
dev -> main
- Loading branch information
Showing
17 changed files
with
306 additions
and
113 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,24 @@ | ||
import HomePage from '../components/Home'; | ||
import { authorize } from '~/lib/authorize'; | ||
import * as db from '~/lib/db'; | ||
|
||
export default function Page() { | ||
return <HomePage />; | ||
import { fetchAllProducts } from '~/server/bigcommerce-api'; | ||
|
||
import ProductList from '~/components/ProductList'; | ||
|
||
export default async function Page() { | ||
const authorized = authorize(); | ||
|
||
if (!authorized) { | ||
throw new Error('Token is not valid. Try to re-open the app.'); | ||
} | ||
|
||
const accessToken = await db.getStoreToken(authorized.storeHash); | ||
|
||
if (!accessToken) { | ||
throw new Error('Access token not found. Try to re-install the app.'); | ||
} | ||
|
||
const products = await fetchAllProducts(accessToken, authorized.storeHash); | ||
|
||
return <ProductList products={products} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use client'; | ||
|
||
import Loader from '~/components/Loader'; | ||
|
||
export default function Loading() { | ||
return <Loader minHeight="90vh" />; | ||
} |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Link from 'next/link'; | ||
|
||
interface NextLinkProps { | ||
href: string; | ||
children: React.ReactNode | string; | ||
} | ||
|
||
export const NextLink = ({ href, children, ...props }: NextLinkProps) => ( | ||
<Link | ||
className="inline-flex items-center whitespace-nowrap text-blue-700 hover:text-blue-900" | ||
href={href} | ||
{...props} | ||
> | ||
{children} | ||
</Link> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
'use client'; | ||
|
||
import { type SimpleProduct } from 'types'; | ||
|
||
import { Badge, Table } from '@bigcommerce/big-design'; | ||
import Image from 'next/image'; | ||
|
||
import { Breadcrumbs } from '~/components/Breadcrumbs'; | ||
import { NextLink } from '~/components/NextLink'; | ||
import { StarRating } from '~/components/StarRating'; | ||
|
||
import { ArrowLongRightIcon } from '@heroicons/react/20/solid'; | ||
import { convertToUDS } from '~/utils/utils'; | ||
|
||
interface ProductListProps { | ||
products: SimpleProduct[]; | ||
} | ||
|
||
interface ReviewsAverageProps { | ||
product: SimpleProduct; | ||
} | ||
|
||
const ReviewsAverage = ({ product }: ReviewsAverageProps) => { | ||
const { reviews_count, reviews_rating_sum } = product; | ||
|
||
if (reviews_count === 0) { | ||
return ( | ||
<Badge label="no reviews" variant="warning"> | ||
No Reviews | ||
</Badge> | ||
); | ||
} | ||
|
||
const average = reviews_rating_sum / reviews_count; | ||
|
||
return <StarRating rating={average} />; | ||
}; | ||
|
||
const ProductList = ({ products }: ProductListProps) => { | ||
return ( | ||
<div> | ||
<Breadcrumbs> | ||
<Breadcrumbs.Text>All Products</Breadcrumbs.Text> | ||
</Breadcrumbs> | ||
<div className="mt-10"> | ||
<Table | ||
stickyHeader | ||
columns={[ | ||
{ | ||
header: 'Image', | ||
hash: 'image', | ||
render: (product) => ( | ||
<div className="relative h-16 w-16 overflow-hidden rounded-md"> | ||
<Image | ||
alt={product.name} | ||
className="object-cover object-center" | ||
fill | ||
src={ | ||
product.thumbnailImage || | ||
'/images/product-placeholder.png' | ||
} | ||
/> | ||
</div> | ||
), | ||
}, | ||
{ | ||
header: 'Name', | ||
hash: 'name', | ||
render: (product) => product.name, | ||
}, | ||
{ | ||
header: 'Price', | ||
hash: 'price', | ||
render: (product) => convertToUDS(product.price), | ||
}, | ||
{ | ||
header: 'Total Sold', | ||
hash: 'totalSold', | ||
render: (product) => product.total_sold, | ||
}, | ||
{ | ||
header: 'Visible', | ||
hash: 'visible', | ||
render: (product) => | ||
product.is_visible ? ( | ||
<Badge label="yes" variant="success"> | ||
Yes | ||
</Badge> | ||
) : ( | ||
<Badge label="no" variant="danger"> | ||
No | ||
</Badge> | ||
), | ||
}, | ||
{ | ||
header: 'Approved Reviews', | ||
hash: 'approvedReviews', | ||
render: (product) => product.reviews_count, | ||
}, | ||
{ | ||
header: 'Approved Rating', | ||
hash: 'approvedRating', | ||
render: (product) => <ReviewsAverage product={product} />, | ||
}, | ||
{ | ||
header: 'Action', | ||
hash: 'action', | ||
render: (product) => ( | ||
<NextLink href={`/product/${product.id}`}> | ||
Explore <ArrowLongRightIcon className="ml-1 h-4 w-4" /> | ||
</NextLink> | ||
), | ||
}, | ||
]} | ||
items={products} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ProductList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.