Skip to content

Commit

Permalink
fix: order List Function
Browse files Browse the repository at this point in the history
  • Loading branch information
kris liu authored and kris-liu-smile committed Nov 22, 2022
1 parent aa84db7 commit bc7f7b1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
13 changes: 7 additions & 6 deletions apps/storefront/src/pages/order/Order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
getInitFilter,
FilterSearchProps,
getFilterMoreData,
currencySymbol,
} from './config'

import {
Expand Down Expand Up @@ -88,11 +89,11 @@ const sortByList: Array<SortByListProps> = [
},
{
name: 'Lowest Price',
id: '-totalIncTax',
id: 'totalIncTax',
},
{
name: 'Highest Price',
id: 'totalIncTax',
id: '-totalIncTax',
},
]

Expand All @@ -106,7 +107,7 @@ const sortByConfigData = {
sortByList,
sortByItemName,
sortByLabel: 'Sort by',
defaultValue: '',
defaultValue: 'createdAt',
isFirstSelect: false,
w: 150,
}
Expand Down Expand Up @@ -234,12 +235,12 @@ const Order = ({
{
key: 'poNumber',
title: 'PO / Reference',
render: (item: ListItem, index: number) => (<Box onClick={() => goToDetail(item, index)}>{item.poNumber ? item.poNumber : '-'}</Box>),
render: (item: ListItem) => (<Box>{item.poNumber ? item.poNumber : '-'}</Box>),
},
{
key: 'totalIncTax',
title: 'Grand total',
render: (item: ListItem) => (`${item.totalIncTax && '$'}${item.totalIncTax}`),
render: (item: ListItem) => (`${currencySymbol(item.money)}${item.totalIncTax}`),
},
{
key: 'status',
Expand All @@ -260,7 +261,7 @@ const Order = ({
{
key: 'createdAt',
title: 'Created on',
render: (item: ListItem) => format(+item.createdAt, 'dd MMM yy'),
render: (item: ListItem) => format(+item.createdAt * 1000, 'dd MMM yy'),
},
]

Expand Down
9 changes: 8 additions & 1 deletion apps/storefront/src/pages/order/OrderItemCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import {
OrderStatus,
} from './components/OrderStatus'

import {
currencySymbol,
} from './config'

interface ListItem {
[key: string]: string
}
Expand Down Expand Up @@ -54,6 +58,8 @@ export const OrderItemCard = (props: OrderItemCardProps) => {

const navigate = useNavigate()

console.log(JSON.parse(item.money))

const goToDetail = (item: ListItem) => {
navigate(`/orderDetail/${item.orderId}`, {
state: {
Expand Down Expand Up @@ -111,6 +117,7 @@ export const OrderItemCard = (props: OrderItemCardProps) => {
minHeight: '1.43em',
}}
>
{currencySymbol(item.money)}
{item.totalIncTax}
</Typography>

Expand All @@ -130,7 +137,7 @@ export const OrderItemCard = (props: OrderItemCardProps) => {
{`by ${item.firstName} ${item.lastName}`}
</Typography>
<Typography>
{format(+item.createdAt, 'dd MMM yy')}
{format(+item.createdAt * 1000, 'dd MMM yy')}
</Typography>
</Box>
</CardContent>
Expand Down
14 changes: 14 additions & 0 deletions apps/storefront/src/pages/order/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,17 @@ export const getInitFilter = (isCompanyOrder: boolean, isB2BUser: boolean): Part

return isB2BUser ? b2bFilterSearch : bcFilterSearch
}

export const currencySymbol = (currencyItem: string) => {
try {
if (currencyItem) {
const currencyToken = JSON.parse(JSON.parse(currencyItem))?.currency_token || ''

return currencyToken
}

return ''
} catch (e) {
return ''
}
}
8 changes: 4 additions & 4 deletions apps/storefront/src/pages/order/shared/getOrderStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const orderStatusCode: OrderStatusConfig = {
2: 'Shipped',
3: 'Partially Shipped',
4: 'Refunded',
5: 'Canceled',
5: 'Cancelled',
6: 'Declined',
7: 'Awaiting Payment',
8: 'Awaiting Pickup',
Expand All @@ -25,7 +25,7 @@ const orderStatusColor: OrderStatusConfig = {
Disputed: '#916CF6',
Refunded: '#F4CC46',
Declined: '#7A6041',
Canceled: '#000000',
Cancelled: '#000000',
Shipped: '#C4DD6C',
Completed: '#C4DD6C',
'Partially Shipped': '#516FAE',
Expand All @@ -43,7 +43,7 @@ const orderStatusTextColor: OrderStatusConfig = {
Disputed: '#FFFFFF',
Refunded: 'rgba(0, 0, 0, 0.87)',
Declined: '#FFFFFF',
Canceled: '#FFFFFF',
Cancelled: '#FFFFFF',
Shipped: 'rgba(0, 0, 0, 0.87)',
Completed: 'rgba(0, 0, 0, 0.87)',
'Partially Shipped': '#FFFFFF',
Expand All @@ -62,7 +62,7 @@ const orderStatusText: OrderStatusConfig = {
Disputed: 'Disputed',
Refunded: 'Refunded',
Declined: 'Declined',
Canceled: 'Canceled',
Cancelled: 'Cancelled',
Shipped: 'Shipped',
Completed: 'Completed',
'Partially Shipped': 'Partially Shipped',
Expand Down

0 comments on commit bc7f7b1

Please sign in to comment.