Skip to content

Commit

Permalink
fix: order detail 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 26fed9b commit aa84db7
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 72 deletions.
81 changes: 27 additions & 54 deletions apps/storefront/src/pages/orderDetail/components/OrderAction.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,24 @@
import {
useState,
useEffect,
useContext,
JSXElementConstructor,
ReactElement,
ReactFragment,
ReactPortal,
MouseEvent,
} from 'react'

import {
Card,
CardContent,
Typography,
CardActions,
Button,
Input,
} from '@mui/material'
import styled from '@emotion/styled'

import {
format,
} from 'date-fns'

import {
TableColumnItem,
} from '@/components/B3Table'

import {
OrderDialog,
} from './OrderDialog'

const OrderActionContainer = styled('div')(() => ({

}))
const Test = styled('div')(() => ({
minWidth: '100%',
minHeight: '300px',
}))
const OrderActionContainer = styled('div')(() => ({}))

/// orderCard
const InformationContainer = styled('div')(() => ({
Expand Down Expand Up @@ -66,29 +47,27 @@ const StyledCardActions = styled('div')(() => ({
const ItemContainer = styled('div')((props: any) => ({
display: 'flex',
justifyContent: 'space-between',
fontWeight: props.nameKey === 'Grand Total' ? 700 : 400,
marginBottom: props.infoKey === 'paymentMethod' ? '8px' : 0,
marginTop: props.infoKey === 'address' ? '8px' : 0,
fontWeight: props.nameKey === 'Grand total' ? 700 : 400,

'& p': {
marginTop: 0,
},
}))

const PaymentItemContainer = styled('div')((props: any) => ({
display: 'flex',
justifyContent: 'space-between',
fontWeight: 400,
marginBottom: props.isAddMarginButton && '0.8rem',
}))

const StyledCurrency = styled('div')(() => ({
display: 'flex',
alignItems: 'center',
width: '40%',
justifyContent: 'space-between',

// '& p': {
// marginLeft: '1rem',
// },
}))

// const Subtitle = styled('p')(() => ({

// }))

const OrderCard = (props: any) => {
const {
header,
Expand Down Expand Up @@ -122,13 +101,10 @@ const OrderCard = (props: any) => {

const infoType = typeof infos
const [open, setOpen] = useState<boolean>(false)
const [title, setTitle] = useState<string>('')
const [type, setType] = useState<string>('')
const [currentDialogData, setCurrentDialogData] = useState<any>({})

// const [infoKey, setInfoKey] = useState<string[]>([])
// const [infoValue, setInfoValue] = useState<string[]>([])
let infoKey
let infoKey: any
let infoValue: any
if (infoType !== 'string') {
const {
Expand All @@ -142,7 +118,6 @@ const OrderCard = (props: any) => {
const handleOpenDialog = (e: any) => {
const {
name,
value,
} = e.target

if (name === 'viewInvoice') {
Expand All @@ -151,7 +126,6 @@ const OrderCard = (props: any) => {
// TODO
} else {
setOpen(true)
setTitle(value)
setType(name)

const newDialogData = dialogData.find((data: any) => data.type === name)
Expand All @@ -162,7 +136,6 @@ const OrderCard = (props: any) => {
return (
<Card
sx={{
// minHeight: '300px',
marginBottom: '1rem',
}}
>
Expand All @@ -181,7 +154,7 @@ const OrderCard = (props: any) => {
<>
{
infos.money ? (
infoKey && infoKey.map((key, index) => (
infoKey && infoKey.map((key: string, index: number) => (
<ItemContainer
key={key}
nameKey={key}
Expand All @@ -194,13 +167,13 @@ const OrderCard = (props: any) => {
</ItemContainer>
))
) : (
infoKey && infoKey.map((key: any) => (
<ItemContainer
key={infos.info[key]}
infoKey={key}
infoValue && infoValue.map((value: any, index: number) => (
<PaymentItemContainer
key={value}
isAddMarginButton={(infoKey[index] === 'paymentMethod' || infoKey[index] === 'company')}
>
{infos.info[key]}
</ItemContainer>
{value}
</PaymentItemContainer>
))
)
}
Expand Down Expand Up @@ -264,29 +237,31 @@ export const OrderAction = (props: any) => {
state,
zip,
country,
city,
} = billingAddress
const paymentAddress = {
paymentMethod: `Payment by ${paymentMethod}`,
name: `${firstName} ${lastName}`,
company,
address: `${street1}, `,
address1: `${state} ${zip}, ${country}`,
street: street1,
address: `${city}, ${state} ${zip}, ${country}`,
}

return paymentAddress
}

const handleOrderComments = (value: string) => {
// const comments = value.replace(/\n/g, '<br/>')
const commentsArr = value.split(/\n/g)

const comments: any = commentsArr.filter((item) => !!item.trim()).length > 0 ? {
mes0: 'Comments:',
} : {}
const comments: any = {}

commentsArr.forEach((item, index) => {
if (item.trim().length > 0) {
comments[`mes${index + 1}`] = item
const isHaveTitle = item.trim().includes(':')

const message = isHaveTitle ? item : `Comments: ${item}`

comments[`mes${index}`] = message
}
})

Expand All @@ -299,7 +274,6 @@ export const OrderAction = (props: any) => {
key: 'Re-Order',
name: 'reOrder',
variant: 'outlined',
// onClick: () => handleTest(),
},
{
value: 'Return',
Expand All @@ -319,7 +293,6 @@ export const OrderAction = (props: any) => {
{
header: 'Order summary',
key: 'order-summary',
// subtitle: 'Purchased by John Miles on 13 Oct 22.',
subtitle: `Purchased by ${name} on ${format(+updatedAt * 1000, 'dd MMM yy')}.`,
buttons,
infos: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Typography,
Checkbox,
TextField,
FormControlLabel,
} from '@mui/material'

import {
Expand Down Expand Up @@ -57,6 +58,12 @@ const Flex = styled('div')(({
},
} : {}

// const mobileItemCheckboxStyle = isMobile ? {
// '& #product-item-checkbox': {
// paddingLeft: 0,
// },
// } : {}

const flexWrap = isMobile ? 'wrap' : 'initial'

return {
Expand Down Expand Up @@ -122,6 +129,18 @@ const mobileItemStyle = {
},
}

const StyledProductItemCheckbox = styled(Checkbox)(({
isMobile,
}: any) => {
const mobileItemStyle = isMobile ? {
paddingLeft: 0,
} : {}

return {
...mobileItemStyle,
}
})

export const OrderCheckboxProduct = (props: OrderCheckboxProductProps) => {
const {
products,
Expand Down Expand Up @@ -197,12 +216,23 @@ export const OrderCheckboxProduct = (props: OrderCheckboxProductProps) => {
</Flex>
)
}
{/*

{
isMobile && (
<FormControlLabel
label="Select all products"
control={(
<Checkbox
checked={list.length === products.length}
onChange={handleSelectAllChange}
/>
)}
sx={{
paddingLeft: '0.6rem',
}}
/>
)
} */}
}

{
products.map((product: OrderProductItem) => (
Expand Down Expand Up @@ -236,7 +266,7 @@ export const OrderCheckboxProduct = (props: OrderCheckboxProductProps) => {
</Box>
</FlexItem>
<FlexItem {...itemStyle.default}>
{isMobile && <span>Price:</span>}
{isMobile && <span>Price: </span>}
{`${currency} ${getProductPrice(product.base_price)}`}
</FlexItem>
<FlexItem {...itemStyle.qty}>
Expand All @@ -252,7 +282,7 @@ export const OrderCheckboxProduct = (props: OrderCheckboxProductProps) => {
/>
</FlexItem>
<FlexItem {...itemStyle.default}>
{isMobile && <span>Cost:</span>}
{isMobile && <span>Cost: </span>}
{`${currency} ${getProductTotals(getProductQuantity(product), product.base_price)}`}
</FlexItem>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@ import {
} from './OrderShoppingList'
import CreateShoppingList from './CreateShoppingList'

interface OrderDialogProps {
interface OrderDialogProps<T> {
open: boolean,
confirmText?: string,
setOpen: (open: boolean) => void,
products?: any,
type?: string,
currentDialogData: any,
itemKey: string,
}

export const OrderDialog: (props: OrderDialogProps) => ReactElement = ({
export const OrderDialog: <T>(props: OrderDialogProps<T>) => ReactElement = ({
open,
products,
type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const OrderShoppingList = (props: orderShoppingListProps) => {
textTransform: 'none',
}}
>
+ Create new
+ Create New
</Button>
</DialogContent>

Expand Down
14 changes: 5 additions & 9 deletions apps/storefront/src/pages/orderDetail/shared/B2BOrderData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ export interface B2BOrderData {
[k: string]: any
}

// export interface OrderActionProps {
// [k: string]: any
// }

const getOrderShipping = (data: B2BOrderData) => {
const {
shipments,
Expand Down Expand Up @@ -111,11 +107,11 @@ const getOrderSummary = (data: B2BOrderData) => {
createAt: dateCreated,
name: `${firstName} ${lastName}`,
priceData: {
SubTotal: formatPrice(subtotalExTax || subtotalIncTax || ''),
Shipping: formatPrice(shippingCostExTax || shippingCostIncTax || ''),
HandingFee: formatPrice(handlingCostExTax || handlingCostIncTax || ''),
Tax: formatPrice(totalTax || ''),
'Grand Total': formatPrice(totalExTax || totalIncTax || ''),
'Sub total': subtotalExTax || subtotalIncTax,
Shipping: shippingCostExTax || shippingCostIncTax,
'Handing fee': handlingCostExTax || handlingCostIncTax,
Tax: totalTax,
'Grand total': totalExTax || totalIncTax,
},
}

Expand Down

0 comments on commit aa84db7

Please sign in to comment.