Skip to content

Commit

Permalink
fix: update reorder dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
b3aton committed Jan 3, 2023
1 parent 78f7808 commit 7138b17
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
38 changes: 38 additions & 0 deletions apps/storefront/src/components/B3LinkTipContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
Link,
Box,
} from '@mui/material'

interface B3SuccessTipContentProps{
message: string,
link?: string,
linkText?: string,
}

export const B3LinkTipContent = ({
message,
link,
linkText = 'View',
}: B3SuccessTipContentProps) => (
<Box>
<Box
sx={{
display: 'inline',
marginRight: link ? '20px' : '0',
}}
>
{message}
</Box>
{link && (
<Link
href={link}
sx={{
color: 'inherit',
textDecoration: 'none',
}}
>
{linkText}
</Link>
)}
</Box>
)
4 changes: 4 additions & 0 deletions apps/storefront/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ export {
export {
B3ProductList,
} from './B3ProductList'

export {
B3LinkTipContent,
} from './B3LinkTipContent'
17 changes: 14 additions & 3 deletions apps/storefront/src/pages/orderDetail/components/OrderDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import {
Box,
Typography,

} from '@mui/material'

import {
Expand All @@ -33,6 +32,7 @@ import {
import {
B3CustomForm,
B3Dialog,
B3LinkTipContent,
} from '@/components'

import {
Expand Down Expand Up @@ -141,11 +141,12 @@ export const OrderDialog: (props: OrderDialogProps) => ReactElement = ({
maxQuantity = 0,
minQuantity = 0,
stock = 0,
isStock = '0',
} = variantInfo

const quantity = product?.editQuantity || 1

if (quantity > stock) {
if (isStock === '1' && quantity > stock) {
product.helperText = `${stock} In Stock`
isValid = false
} else if (minQuantity !== 0 && quantity < minQuantity) {
Expand All @@ -166,6 +167,14 @@ export const OrderDialog: (props: OrderDialogProps) => ReactElement = ({
return isValid
}

const successTip = () => (
<B3LinkTipContent
message="Products are added to cart"
link="/cart.php"
linkText="VIEW CART"
/>
)

const handleReorder = async () => {
setIsRequestLoading(true)

Expand Down Expand Up @@ -212,7 +221,9 @@ export const OrderDialog: (props: OrderDialogProps) => ReactElement = ({
snackbar.error(res.detail)
} else {
setOpen(false)
snackbar.success(`${items.length} products were added to cart`)
snackbar.success('', {
jsx: successTip,
})
}
} finally {
setIsRequestLoading(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,13 @@ export const ReAddToCart = (props: ShoppingProductsProps) => {
minQuantity = 0,
stock = 0,
node,
isStock = '0',
} = product
const {
quantity,
} = node

if (quantity > stock) return `${stock} In Stock`
if (isStock === '1' && quantity > stock) return `${stock} In Stock`

if (minQuantity !== 0 && quantity < minQuantity) return `minQuantity is ${minQuantity}`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface ProductsProps {
maxQuantity?: number,
minQuantity?: number,
stock?: number,
isStock?: string,
node: NodeProps
}

Expand Down

0 comments on commit 7138b17

Please sign in to comment.