Skip to content

Commit

Permalink
fix: order detail invoice and other issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 authored and kris-liu-smile committed Nov 22, 2022
1 parent 4bf6407 commit 6874578
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
58 changes: 48 additions & 10 deletions apps/storefront/src/pages/orderDetail/components/OrderAction.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import {
useState,
useContext,
} from 'react'
import {
useNavigate,
} from 'react-router-dom'

import {
Card,
Expand All @@ -14,6 +18,10 @@ import {
format,
} from 'date-fns'

import {
GlobaledContext,
} from '@/shared/global'

import {
OrderDialog,
} from './OrderDialog'
Expand Down Expand Up @@ -76,8 +84,12 @@ const OrderCard = (props: any) => {
infos,
products,
itemKey,
orderId,
currencyInfo,
} = props

const navigate = useNavigate()

const dialogData = [
{
dialogTitle: 'Re-order',
Expand Down Expand Up @@ -121,7 +133,11 @@ const OrderCard = (props: any) => {
} = e.target

if (name === 'viewInvoice') {
// TODO
// TODO:
navigate('/invoiceDetail/1')
} else if (name === 'printInvoice') {
// TODO:
window.open(`/account.php?action=print_invoice&order_id=${orderId}`)
} else if (name === 'return') {
// TODO
} else {
Expand Down Expand Up @@ -185,12 +201,21 @@ const OrderCard = (props: any) => {
<StyledCardActions>
{
buttons && buttons.map((button: any) => (
<Button
{...button}
onClick={(e) => { handleOpenDialog(e) }}
>
{button.value}
</Button>
<>
{
button.isCanShow && (
<Button
value={button.value}
key={button.key}
name={button.name}
variant={button.variant}
onClick={(e) => { handleOpenDialog(e) }}
>
{button.value}
</Button>
)
}
</>
))
}
</StyledCardActions>
Expand All @@ -202,6 +227,7 @@ const OrderCard = (props: any) => {
type={type}
setOpen={setOpen}
itemKey={itemKey}
currencyInfo={currencyInfo}
/>
</Card>
)
Expand All @@ -211,6 +237,11 @@ export const OrderAction = (props: any) => {
const {
detailsData,
} = props
const {
state: {
isB2BUser,
},
} = useContext(GlobaledContext)

const {
money,
Expand All @@ -226,6 +257,7 @@ export const OrderAction = (props: any) => {
},
orderComments,
products,
orderId,
} = detailsData

const getFullPaymentAddress = (billingAddress: any) => {
Expand Down Expand Up @@ -274,18 +306,21 @@ export const OrderAction = (props: any) => {
key: 'Re-Order',
name: 'reOrder',
variant: 'outlined',
isCanShow: true,
},
{
value: 'Return',
key: 'Return',
name: 'return',
variant: 'outlined',
isCanShow: true,
},
{
value: 'ADD TO SHOPPING LIST',
key: 'add-to-shipping-list',
name: 'shippingList',
variant: 'outlined',
isCanShow: isB2BUser,
},
]

Expand All @@ -306,10 +341,11 @@ export const OrderAction = (props: any) => {
subtitle: `Paid in full on ${format(Date.parse(createAt), 'dd MMM yy')}.`,
buttons: [
{
value: 'view invoice',
key: 'viewInvoice',
name: 'viewInvoice',
value: isB2BUser ? 'view invoice' : 'print invoice',
key: 'aboutInvoice',
name: isB2BUser ? 'viewInvoice' : 'printInvoice',
variant: 'outlined',
isCanShow: true,
},
],
infos: {
Expand All @@ -334,6 +370,8 @@ export const OrderAction = (props: any) => {
<OrderCard
key={item.key}
products={products}
orderId={orderId}
currencyInfo={money}
{...item}
itemKey={item.key}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {

interface OrderCheckboxProductProps {
products: any[],
currency?: string,
currencyInfo: any,
getProductQuantity?: (item: OrderProductItem) => number
onProductChange?: (products: OrderProductItem[]) => void
}
Expand Down Expand Up @@ -129,7 +129,7 @@ const mobileItemStyle = {
export const OrderCheckboxProduct = (props: OrderCheckboxProductProps) => {
const {
products,
currency = '$',
currencyInfo,
getProductQuantity = (item) => item.quantity,
onProductChange = () => {},
} = props
Expand Down Expand Up @@ -266,7 +266,7 @@ export const OrderCheckboxProduct = (props: OrderCheckboxProductProps) => {
</FlexItem>
<FlexItem {...itemStyle.default}>
{isMobile && <span>Price: </span>}
{`${currency} ${getProductPrice(product.base_price)}`}
{`${currencyInfo.currency_token} ${getProductPrice(product.base_price)}`}
</FlexItem>
<FlexItem {...itemStyle.qty}>
<TextField
Expand All @@ -284,7 +284,7 @@ export const OrderCheckboxProduct = (props: OrderCheckboxProductProps) => {
</FlexItem>
<FlexItem {...itemStyle.default}>
{isMobile && <span>Cost: </span>}
{`${currency} ${getProductTotals(getProductQuantity(product), product.base_price)}`}
{`${currencyInfo.currency_token} ${getProductTotals(getProductQuantity(product), product.base_price)}`}
</FlexItem>
</Flex>
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface OrderDialogProps<T> {
type?: string,
currentDialogData: any,
itemKey: string,
currencyInfo: any,
}

export const OrderDialog: <T>(props: OrderDialogProps<T>) => ReactElement = ({
Expand All @@ -49,6 +50,7 @@ export const OrderDialog: <T>(props: OrderDialogProps<T>) => ReactElement = ({
currentDialogData,
setOpen,
itemKey,
currencyInfo,
}) => {
const container = useRef<HTMLInputElement | null>(null)
const [isOpenCreateShopping, setOpenCreateShopping] = useState(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,5 @@ export const convertB2BOrderDetails = (data: B2BOrderData) => ({
payment: getPaymentData(data),
orderComments: data.customerMessage,
products: data.products,
orderId: +data.id,
})

0 comments on commit 6874578

Please sign in to comment.