diff --git a/apps/storefront/src/App.tsx b/apps/storefront/src/App.tsx index 55bb2cf8..7a17cfee 100644 --- a/apps/storefront/src/App.tsx +++ b/apps/storefront/src/App.tsx @@ -185,6 +185,8 @@ export default function App() { // background login enter judgment if (!href.includes('checkout')) { setOpenApp(!(customerId && !window.location.hash)) + } else { + showPageMask(false) } } diff --git a/apps/storefront/src/components/B3Tip.tsx b/apps/storefront/src/components/B3Tip.tsx index c7343a7a..ebd4c1ec 100644 --- a/apps/storefront/src/components/B3Tip.tsx +++ b/apps/storefront/src/components/B3Tip.tsx @@ -11,7 +11,7 @@ import { } from '@/shared/global/context/config' interface B3TipProps extends TipMessagesProps { - handleItemClose?: (id: number | string) => void, + handleItemClose: (id: number | string) => void, handleAllClose: () => void, } @@ -41,13 +41,13 @@ export const B3Tip = ({ width: '100%', alignItems: 'center', '& button[title="Close"]': { - display: `${handleItemClose ? 'block' : 'none'}`, + display: `${msg.isClose ? 'block' : 'none'}`, }, }} variant="filled" key={msg.id} severity={msg.type} - onClose={() => handleItemClose && handleItemClose(msg.id)} + onClose={() => msg.isClose && handleItemClose(msg.id)} > {msg?.title && {msg.title}} { diff --git a/apps/storefront/src/components/layout/B3LayoutTip.tsx b/apps/storefront/src/components/layout/B3LayoutTip.tsx index 9ee09a1a..3d13a104 100644 --- a/apps/storefront/src/components/layout/B3LayoutTip.tsx +++ b/apps/storefront/src/components/layout/B3LayoutTip.tsx @@ -33,6 +33,10 @@ const B3LayoutTip = () => { window.tipDispatch = dispatch }, []) + // useEffect(() => { + // window.b3Tipmessage = tipMessage?.msgs || [] + // }, [tipMessage]) + const setMsgs = (msgs: [] | Array = []) => { dispatch({ type: 'common', @@ -56,7 +60,6 @@ const B3LayoutTip = () => { autoHideDuration = 3000, vertical = `${isMobile ? 'top' : 'top'}`, horizontal = 'right', - isClose = false, } = tipMessage return ( @@ -65,7 +68,8 @@ const B3LayoutTip = () => { msgs={msgs} handleAllClose={setMsgs} autoHideDuration={autoHideDuration} - handleItemClose={isClose ? handleClose : undefined} + handleItemClose={handleClose} + // handleItemClose={isClose ? handleClose : undefined} vertical={vertical} horizontal={horizontal} /> diff --git a/apps/storefront/src/index.d.ts b/apps/storefront/src/index.d.ts index e9847beb..33383437 100644 --- a/apps/storefront/src/index.d.ts +++ b/apps/storefront/src/index.d.ts @@ -9,6 +9,5 @@ declare interface CustomFieldStringItems { declare interface Window { tipDispatch: DispatchProps + b3Tipmessage: any } - -// declare module '@mui-treasury/components/chatMsg/ChatMsg' diff --git a/apps/storefront/src/pages/orderDetail/components/CreateShoppingList.tsx b/apps/storefront/src/pages/orderDetail/components/CreateShoppingList.tsx index 30e8eb38..b2eec332 100644 --- a/apps/storefront/src/pages/orderDetail/components/CreateShoppingList.tsx +++ b/apps/storefront/src/pages/orderDetail/components/CreateShoppingList.tsx @@ -34,6 +34,10 @@ import { ThemeFrameContext, } from '@/components/ThemeFrame' +import { + GlobaledContext, +} from '@/shared/global' + import { createB2BShoppingList, } from '@/shared/service/b2b' @@ -80,6 +84,12 @@ const CreateShoppingList = ({ const [loading, setLoading] = useState(false) + const { + state: { + role, + }, + } = useContext(GlobaledContext) + const { control, handleSubmit, @@ -107,7 +117,7 @@ const CreateShoppingList = ({ } const createShoppingData = { ...data, - status: 0, + status: +role === 2 ? 30 : 0, } await createB2BShoppingList(createShoppingData) setLoading(false) diff --git a/apps/storefront/src/pages/quickorder/Quickorder.tsx b/apps/storefront/src/pages/quickorder/Quickorder.tsx index 4120a06a..e741d530 100644 --- a/apps/storefront/src/pages/quickorder/Quickorder.tsx +++ b/apps/storefront/src/pages/quickorder/Quickorder.tsx @@ -58,6 +58,9 @@ const Quickorder = () => { { diff --git a/apps/storefront/src/pages/quickorder/components/QuickorderTable.tsx b/apps/storefront/src/pages/quickorder/components/QuickorderTable.tsx index 63fdd2ce..cc021f3a 100644 --- a/apps/storefront/src/pages/quickorder/components/QuickorderTable.tsx +++ b/apps/storefront/src/pages/quickorder/components/QuickorderTable.tsx @@ -178,6 +178,7 @@ const QuickorderTable = ({ const handleSearchProduct = async (q: string) => { setSearch({ + ...search, q, }) } @@ -456,7 +457,7 @@ const QuickorderTable = ({ - {/* */} + { role !== 100 && diff --git a/apps/storefront/src/pages/quote/components/FileUpload.tsx b/apps/storefront/src/pages/quote/components/FileUpload.tsx index a558712b..7b298933 100644 --- a/apps/storefront/src/pages/quote/components/FileUpload.tsx +++ b/apps/storefront/src/pages/quote/components/FileUpload.tsx @@ -119,6 +119,7 @@ interface FileUploadProps { fileList: FileObjects[], allowUpload?: boolean, onDelete?: (id: string) => void, + limitUploadFn?: () => boolean, isEndLoadding?: boolean, } @@ -133,6 +134,7 @@ const FileUpload = (props: FileUploadProps, ref: Ref) => { tips = 'You can add up to 3 files,not bigger that 2MB each.', maxFileSize = 2097152, // 2MB fileNumber = 3, + limitUploadFn, acceptedFiles = FILE_UPLOAD_ACCEPT_TYPE, onchange = noop, fileList = [], @@ -196,7 +198,11 @@ const FileUpload = (props: FileUploadProps, ref: Ref) => { const handleChange = async (files: File[]) => { const file = files.length > 0 ? files[0] : null - if (file && fileList.length >= fileNumber) { + if (file && limitUploadFn && limitUploadFn()) { + return + } + + if (!limitUploadFn && file && fileList.length >= fileNumber) { snackbar.error(`You can add up to ${fileNumber} files`) return } diff --git a/apps/storefront/src/pages/quote/components/Message.tsx b/apps/storefront/src/pages/quote/components/Message.tsx index 4ca2bb89..e5b15d54 100644 --- a/apps/storefront/src/pages/quote/components/Message.tsx +++ b/apps/storefront/src/pages/quote/components/Message.tsx @@ -17,7 +17,9 @@ import { import { format, + formatDistanceStrict, } from 'date-fns' + import { updateB2BQuote, updateBCQuote, @@ -54,17 +56,21 @@ interface MsgsProps { } interface CustomerMessageProps { - msg: MessageProps + msg: MessageProps, + isEndMessage?: boolean, + isCustomer?: boolean, } -const CustomerMessage = ({ +const ChatMessage = ({ msg, + isEndMessage, + isCustomer, }: CustomerMessageProps) => ( { @@ -92,7 +98,7 @@ const CustomerMessage = ({ height: '34px', lineHeight: '34px', padding: '0 10px', - background: 'rgba(25, 118, 210, 0.3)', + background: `${isCustomer ? 'rgba(25, 118, 210, 0.3)' : 'rgba(0, 0, 0, 0.12)'}`, borderRadius: '18px', m: '1px', }} @@ -106,6 +112,25 @@ const CustomerMessage = ({ {msg.message} + { + isEndMessage && ( + + {`Sent ${formatDistanceStrict(new Date((msg.sendTime || 0) * 1000), new Date(), { + addSuffix: true, + })}`} + + + ) + } ) } @@ -113,65 +138,13 @@ const CustomerMessage = ({ ) -const SalesRepMessage = ({ - msg, -}: CustomerMessageProps) => ( - - { - msg?.role && ( - - {msg.role} - - ) - } - - { - msg?.message && ( - - - - {msg.message} - - - - ) - } - - -) +interface DateMessageProps { + msg: MessageProps, +} const DateMessage = ({ msg, -}: CustomerMessageProps) => ( +}: DateMessageProps) => ( { - messages.map((item: MessageProps) => ( + messages.map((item: MessageProps, index: number) => ( - { - item.isCustomer && - } - { - !item.isCustomer && - } + { item.date && } diff --git a/apps/storefront/src/pages/quote/components/QuoteAttachment.tsx b/apps/storefront/src/pages/quote/components/QuoteAttachment.tsx index 6cbdd4d3..21d61f9c 100644 --- a/apps/storefront/src/pages/quote/components/QuoteAttachment.tsx +++ b/apps/storefront/src/pages/quote/components/QuoteAttachment.tsx @@ -17,6 +17,7 @@ import { import { B3LStorage, + snackbar, } from '@/utils' import { @@ -69,7 +70,6 @@ export const QuoteAttachment = (props: QuoteAttachmentProps) => { const uploadRef = useRef(null) useEffect(() => { - console.log(defaultFileList) if (status === 0) { const { fileInfo = [], @@ -153,6 +153,15 @@ export const QuoteAttachment = (props: QuoteAttachmentProps) => { } } + const limitUploadFn = () => { + const customerFiles = fileList.filter((file: FileObjects) => file?.title && file.title.includes('by customer')) + if (customerFiles.length >= 3) { + snackbar.error('You can add up to 3 files') + return true + } + return false + } + return ( @@ -162,6 +171,7 @@ export const QuoteAttachment = (props: QuoteAttachmentProps) => { ref={uploadRef} isEndLoadding fileList={fileList} + limitUploadFn={limitUploadFn} onchange={handleChange} onDelete={handleDelete} allowUpload={allowUpload} diff --git a/apps/storefront/src/pages/quote/components/QuoteNote.tsx b/apps/storefront/src/pages/quote/components/QuoteNote.tsx index 24ada5a4..b9db2b14 100644 --- a/apps/storefront/src/pages/quote/components/QuoteNote.tsx +++ b/apps/storefront/src/pages/quote/components/QuoteNote.tsx @@ -46,11 +46,20 @@ export const QuoteNote = () => { return ( - + + + Your message will be sent after submitting a quote + { }, minQuantity = 0, maxQuantity = 0, + isStock, + stock, } = product const quantityNumber = parseInt(`${quantity}`, 10) || 0 @@ -274,6 +276,9 @@ export const ReAddToCart = (props: ShoppingProductsProps) => { } else if (maxQuantity !== 0 && quantityNumber > maxQuantity) { product.node.quantity = maxQuantity } + if (isStock !== '0' && stock && quantity > stock) { + product.node.quantity = stock + } }) setValidateFailureProducts(newProduct) diff --git a/apps/storefront/src/shared/global/context/config.ts b/apps/storefront/src/shared/global/context/config.ts index 42680a36..bb5636cc 100644 --- a/apps/storefront/src/shared/global/context/config.ts +++ b/apps/storefront/src/shared/global/context/config.ts @@ -22,6 +22,9 @@ export interface MsgsProps { jsx?: () => ReactElement, id: string | number, type: AlertTip + isClose?: boolean, + vertical?: 'top' | 'bottom' + horizontal?: 'left' | 'right' | 'center' } export interface TipMessagesProps{ msgs?: Array | [], diff --git a/apps/storefront/src/shared/service/b2b/graphql/quote.ts b/apps/storefront/src/shared/service/b2b/graphql/quote.ts index 6021ef74..307d7014 100644 --- a/apps/storefront/src/shared/service/b2b/graphql/quote.ts +++ b/apps/storefront/src/shared/service/b2b/graphql/quote.ts @@ -117,7 +117,7 @@ const getAddresses = (companyId: number) => `{ const quoteCreate = (data: CustomFieldItems) => `mutation{ quoteCreate(quoteData: { - notes: "${data.notes}", + message: "${data.message}", legalTerms: "${data.legalTerms}", totalAmount: "${data.totalAmount}", grandTotal: "${data.grandTotal}", diff --git a/apps/storefront/src/utils/b3Product.ts b/apps/storefront/src/utils/b3Product.ts index a8526f4b..9ccf3d3b 100644 --- a/apps/storefront/src/utils/b3Product.ts +++ b/apps/storefront/src/utils/b3Product.ts @@ -57,7 +57,6 @@ const addQuoteDraftProduce = async (quoteListitem: CustomFieldItems, qty: number const index = b2bQuoteDraftList.findIndex((item: QuoteListitemProps) => item?.node?.variantSku === quoteListitem.node.variantSku) if (index !== -1) { - console.log(b2bQuoteDraftList[index].node.optionList, b2bQuoteDraftList[index]) // TODO optionList compare const oldOptionList = JSON.parse(b2bQuoteDraftList[index].node.optionList) diff --git a/apps/storefront/src/utils/b3Tip.ts b/apps/storefront/src/utils/b3Tip.ts index bf1357d1..74a3e8d1 100644 --- a/apps/storefront/src/utils/b3Tip.ts +++ b/apps/storefront/src/utils/b3Tip.ts @@ -1,6 +1,7 @@ import { ReactElement, } from 'react' + import { v1 as uuid, } from 'uuid' @@ -11,8 +12,12 @@ interface SnackbarItemProps { isClose?: boolean, } +interface SnackbarMessageProps extends SnackbarItemProps { + message: string, +} + interface SnackbarProps { - [key: string]: (message: string, options?: SnackbarItemProps) => void + [key: string]: (message: string | SnackbarMessageProps[], options?: SnackbarItemProps) => void } const snackbar: SnackbarProps = {} @@ -20,20 +25,22 @@ const variants = ['error', 'success', 'info', 'warning'] variants.forEach((variant) => { snackbar[variant] = (message, options) => { + const msgs = [ + { + isClose: options?.isClose || false, + id: uuid(), + type: variant, + msg: message || `${variant} without any info.`, + jsx: options?.jsx, + }, + ] + window.tipDispatch({ type: 'common', payload: { tipMessage: { autoHideDuration: options?.duration || 3000, - isClose: options?.isClose || false, - msgs: [ - { - id: uuid(), - type: variant, - msg: message || `${variant} without any info.`, - jsx: options?.jsx, - }, - ], + msgs, }, }, }) diff --git a/packages/hooks/useB3AppOpen.ts b/packages/hooks/useB3AppOpen.ts index a63ca11f..61e8459d 100644 --- a/packages/hooks/useB3AppOpen.ts +++ b/packages/hooks/useB3AppOpen.ts @@ -39,17 +39,16 @@ export const useB3AppOpen = (initOpenState: OpenPageState) => { } useLayoutEffect(() => { - if (globalB3['dom.openB3Checkout'] && document.getElementById(globalB3['dom.openB3Checkout'])) { - setOpenPage({ - isOpen: true, - openUrl: '/login', - }) - } + // if (globalB3['dom.openB3Checkout'] && document.getElementById(globalB3['dom.openB3Checkout'])) { + // setOpenPage({ + // isOpen: true, + // openUrl: '/login', + // }) + // } // login register orther if (document.querySelectorAll(globalB3['dom.registerElement']).length) { const registerArr = Array.from(document.querySelectorAll(globalB3['dom.registerElement'])) const allOtherArr = Array.from(document.querySelectorAll(globalB3['dom.allOtherElement'])) - const handleTriggerClick = (e: MouseEvent) => { if (registerArr.includes(e.target) || allOtherArr.includes(e.target)) { e.preventDefault() diff --git a/packages/hooks/useB3PDPOpen.ts b/packages/hooks/useB3PDPOpen.ts index 11f997b6..66da2293 100644 --- a/packages/hooks/useB3PDPOpen.ts +++ b/packages/hooks/useB3PDPOpen.ts @@ -16,7 +16,7 @@ export const useB3PDPOpen = (el: string, cd: () => void, isB2BUser: boolean, rol let shoppingBtnDom: CustomFieldItems | null = null if (!addToCartAll.length) return if (document.querySelectorAll('#shoppingListBtn').length) return - if (isB2BUser && (+role === 0 || +role === 1)) { + if (isB2BUser && (+role === 0 || +role === 1 || +role === 2)) { addToCartAll.forEach((node: CustomFieldItems) => { shoppingBtnDom = document.createElement('div') shoppingBtnDom.setAttribute('id', 'shoppingListBtn')