-
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.
feat(common): APPEX-202 implement orders page designs
- Loading branch information
1 parent
63f9dd9
commit 440b28e
Showing
6 changed files
with
157 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import { bigcommerceClient, getSession } from '../../../../lib/auth'; | ||
|
||
export default async function shippingAddressesAndProducts(req: NextApiRequest, res: NextApiResponse) { | ||
const { | ||
query: { orderId }, | ||
method, | ||
} = req; | ||
|
||
try { | ||
const { accessToken, storeHash } = await getSession(req); | ||
const bigcommerce = bigcommerceClient(accessToken, storeHash, 'v2'); | ||
|
||
switch (method) { | ||
case 'GET': { | ||
const shipping_addresses = await bigcommerce.get(`/orders/${orderId}/shipping_addresses`); | ||
const products = await bigcommerce.get(`/orders/${orderId}/products`); | ||
|
||
res.status(200).json({ shipping_addresses, products }); | ||
|
||
break; | ||
} | ||
|
||
default: { | ||
res.setHeader('Allow', ['GET']); | ||
res.status(405).end(`Method ${method} Not Allowed`); | ||
} | ||
} | ||
|
||
} catch (error) { | ||
const { message, response } = error; | ||
res.status(response?.status || 500).json({ message }); | ||
} | ||
} |
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,77 @@ | ||
import { Button, Flex, H1, Panel, StatefulTable, Text } from '@bigcommerce/big-design'; | ||
import { useRouter } from 'next/router'; | ||
|
||
import ErrorMessage from '../../../components/error'; | ||
import Loading from '../../../components/loading'; | ||
import { useShippingAndProductsInfo } from '../../../lib/hooks'; | ||
import { BillingAddress, OrderProduct, ShippingAndProductsInfo } from '../../../types'; | ||
|
||
const InternalOrderPage = (order: ShippingAndProductsInfo) => { | ||
const { shipping_addresses = [], products = [] } = order | ||
const items = shipping_addresses.map(address => { | ||
const addressProducts = products.filter(({ order_address_id }) => order_address_id === address.id); | ||
|
||
return { address, addressProducts } | ||
}); | ||
|
||
const Address = (address: BillingAddress) => ( | ||
<> | ||
<Text margin='none'>{address.first_name} {address.last_name}</Text> | ||
<Text margin='none'>{address.street_1} {address.street_2}</Text> | ||
<Text margin='none'>{address.city}, {address.state} {address.zip}</Text> | ||
</> | ||
); | ||
|
||
const renderOrderProducts = (addressProducts: OrderProduct[]) => ( | ||
<> | ||
{addressProducts.map(product => <Text key={product.id}>{product.name}</Text>)} | ||
</> | ||
); | ||
|
||
const renderOrderProductsQuantities = (addressProducts: OrderProduct[]) => ( | ||
<> | ||
{addressProducts.map(product => <Text key={product.id}>{product.quantity}</Text>)} | ||
</> | ||
); | ||
|
||
return ( | ||
<> | ||
<Flex justifyContent="space-between" marginBottom="medium"> | ||
<H1>Order details</H1> | ||
<Button>Create shipment</Button> | ||
</Flex> | ||
<Panel> | ||
<StatefulTable | ||
columns={[ | ||
{ header: 'Ship to', hash: 'address', render: ({ address }) => <Address {...address} /> }, | ||
{ | ||
header: 'Products', | ||
hash: 'addressProducts', | ||
render: ({ addressProducts }) => renderOrderProducts(addressProducts), | ||
}, | ||
{ | ||
header: 'Quantity', | ||
hash: 'quantity', | ||
render: ({ addressProducts }) => renderOrderProductsQuantities(addressProducts), | ||
}, | ||
]} | ||
items={items} | ||
/> | ||
</Panel> | ||
</> | ||
); | ||
}; | ||
|
||
const OrderPage = () => { | ||
const router = useRouter(); | ||
const { orderId } = router.query; | ||
const { isLoading, order, error }= useShippingAndProductsInfo(parseInt(`${orderId}`, 10)); | ||
|
||
if (isLoading) return <Loading />; | ||
|
||
if (error) return <ErrorMessage error={error} />; | ||
|
||
return <InternalOrderPage {...order} />; | ||
}; | ||
|
||
export default OrderPage; |
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