-
Notifications
You must be signed in to change notification settings - Fork 339
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 bc-chaz/step-5-big-design
feat(common): adds step 5, product list using BigDesign
- Loading branch information
Showing
13 changed files
with
174 additions
and
56 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import { bigcommerceClient, getSession } from '../../../lib/auth'; | ||
|
||
export default async function list(req: NextApiRequest, res: NextApiResponse) { | ||
try { | ||
const { accessToken, storeId } = await getSession(req); | ||
const bigcommerce = bigcommerceClient(accessToken, storeId); | ||
// Optional: pass in API params here | ||
const params = [ | ||
'limit=11', | ||
].join('&'); | ||
|
||
const { data } = await bigcommerce.get(`/catalog/products?${params}`); | ||
res.status(200).json(data); | ||
} catch (error) { | ||
const { message, response } = error; | ||
res.status(response?.status || 500).end(message || 'Authentication failed, please re-install'); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,31 +1,34 @@ | ||
import { Box, Flex, Panel, Text } from '@bigcommerce/big-design'; | ||
import Header from '../components/header'; | ||
import { Box, Flex, H1, H2, H4, Link, Panel } from '@bigcommerce/big-design'; | ||
import styled from 'styled-components'; | ||
import { useProducts } from '../lib/hooks'; | ||
|
||
const Index = () => { | ||
const { summary } = useProducts(); | ||
|
||
return ( | ||
<Panel margin="xxLarge"> | ||
<Header title="Homepage" /> | ||
<Panel header="Homepage"> | ||
{summary && | ||
<Flex> | ||
<Box marginRight="xLarge"> | ||
<Text>Inventory Count</Text> | ||
<Text>{summary.inventory_count}</Text> | ||
</Box> | ||
<Box marginRight="xLarge"> | ||
<Text>Variant Count</Text> | ||
<Text>{summary.variant_count}</Text> | ||
</Box> | ||
<Box> | ||
<Text>Primary Category</Text> | ||
<Text>{summary.primary_category_name}</Text> | ||
</Box> | ||
<StyledBox border="box" borderRadius="normal" marginRight="xLarge" padding="medium"> | ||
<H4>Inventory count</H4> | ||
<H1 marginBottom="none">{summary.inventory_count}</H1> | ||
</StyledBox> | ||
<StyledBox border="box" borderRadius="normal" marginRight="xLarge" padding="medium"> | ||
<H4>Variant count</H4> | ||
<H1 marginBottom="none">{summary.variant_count}</H1> | ||
</StyledBox> | ||
<StyledBox border="box" borderRadius="normal" padding="medium"> | ||
<H4>Primary category</H4> | ||
<H1 marginBottom="none">{summary.primary_category_name}</H1> | ||
</StyledBox> | ||
</Flex> | ||
} | ||
</Panel> | ||
); | ||
}; | ||
|
||
const StyledBox = styled(Box)` | ||
min-width: 10rem; | ||
`; | ||
|
||
export default Index; |
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,55 @@ | ||
import { Button, Dropdown, Panel, Small, StatefulTable, Link as StyledLink } from '@bigcommerce/big-design'; | ||
import { MoreHorizIcon } from '@bigcommerce/big-design-icons'; | ||
import Link from 'next/link'; | ||
import { ReactElement } from 'react'; | ||
import { useProductList } from '../../lib/hooks'; | ||
|
||
const Products = () => { | ||
const { list = [] } = useProductList(); | ||
const tableItems = list.map(({ id, inventory_level: stock, name, price }) => ({ | ||
id, | ||
name, | ||
price, | ||
stock, | ||
})); | ||
|
||
const renderName = (name: string): ReactElement => ( | ||
<Link href="#"> | ||
<StyledLink>{name}</StyledLink> | ||
</Link> | ||
); | ||
|
||
const renderPrice = (price: number): string => ( | ||
new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(price) | ||
); | ||
|
||
const renderStock = (stock: number): ReactElement => (stock > 0 | ||
? <Small>{stock}</Small> | ||
: <Small bold marginBottom="none" color="danger">0</Small> | ||
); | ||
|
||
const renderAction = (): ReactElement => ( | ||
<Dropdown | ||
items={[ { content: 'Edit product', onItemClick: (item) => item, hash: 'edit' } ]} | ||
toggle={<Button iconOnly={<MoreHorizIcon color="secondary60" />} variant="subtle" />} | ||
/> | ||
); | ||
|
||
return ( | ||
<Panel> | ||
<StatefulTable | ||
columns={[ | ||
{ header: 'Product name', hash: 'name', render: ({ name }) => renderName(name), sortKey: 'name' }, | ||
{ header: 'Stock', hash: 'stock', render: ({ stock }) => renderStock(stock), sortKey: 'stock' }, | ||
{ header: 'Price', hash: 'price', render: ({ price }) => renderPrice(price), sortKey: 'price' }, | ||
{ header: 'Action', hideHeader: true, hash: 'id', render: () => renderAction() }, | ||
]} | ||
items={tableItems} | ||
itemName="Products" | ||
stickyHeader | ||
/> | ||
</Panel> | ||
); | ||
}; | ||
|
||
export default 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
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,11 @@ | ||
export interface StoreData { | ||
accessToken?: string; | ||
scope?: string; | ||
storeId: string; | ||
} | ||
|
||
export interface UserData { | ||
email: string; | ||
storeId: string, | ||
username?: string; | ||
} |
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 +1,2 @@ | ||
export * from './auth'; | ||
export * from './firebase'; |