{"version":3,"file":"cart-merged-notification-d7cdb165.js","sources":["../../../client/src/javascripts/customer_pages/_cart-merged-notification/cart-merged-notification.jsx","../../../client/src/javascripts/entry_points/cart-merged-notification.jsx"],"sourcesContent":["/* eslint-disable react/prop-types */\n// Import Libraries\nimport React from 'react';\nimport ReactDOM from 'react-dom';\n// Import JS Modules\nimport { builderDispatch, WebUI } from '../_utils/ui';\nimport translate from '../_utils/tools/translate';\n\n// -----------------------------------------------------------\n// PrintsPreview\n// -----------------------------------------------------------\nconst PrintsPreview = ({ thumbUrl }) => {\n return (\n
\n
\n
\n
\n
\n print preview\n
\n
\n );\n};\n\n// -----------------------------------------------------------\n// PrismPreview\n// -----------------------------------------------------------\nconst PrismPreview = ({ thumbUrl }) => {\n return (\n
\n prism preview\n
\n );\n};\n\nconst PREVIEW_THUMBS_MAX = 6;\n\nconst mergeThumbnails = (printsThumbnail, prismItems) => {\n const mergedThumbnails = prismItems.map((e) => ({\n type: 'PRISM',\n thumbUrl: e.thumbnail\n }));\n\n if (printsThumbnail) {\n mergedThumbnails.unshift({\n type: 'PRINTS',\n thumbUrl: printsThumbnail\n });\n }\n\n return mergedThumbnails;\n}\n\nconst stringifyPortions = (portions) => {\n switch (portions.length) {\n case 1:\n return portions[0];\n case 2:\n return portions.join(' and ');\n default:\n return `${portions.slice(0, portions.length - 2).join(', ')} and ${portions[portions.length - 1]}`;\n }\n}\n\nclass CartMergedNotification extends React.Component {\n constructor() {\n super();\n\n this.state = {\n basketPath: '',\n loaded: false,\n $otherModals: [],\n }\n }\n\n UNSAFE_componentWillMount() {\n this.builderDispatchToken = builderDispatch.register(payload => {\n if (payload.type !== WebUI.LOGIN) {\n return;\n }\n\n this.handleLogin(\n payload.previous_basket_contents,\n payload.basketPath\n );\n });\n }\n\n componentDidMount() {\n const $meJQ = this.getMeAsJQuery();\n\n $meJQ\n .on('show.bs.modal', this.handleModalOnShow)\n .on('hide.bs.modal', this.handleModalOnHide)\n .on('hidden.bs.modal', this.handleModalOnHidden);\n }\n\n componentWillUnmount() {\n builderDispatch.unregister(this.builderDispatchToken);\n }\n\n open = () => {\n const $meJQ = this.getMeAsJQuery();\n $meJQ.modal('show');\n }\n\n getMeAsJQuery = () => {\n // Yes I know this sucks...\n // eslint-disable-next-line react/no-find-dom-node\n return $(ReactDOM.findDOMNode(this));\n }\n\n handleLogin = (previousBasketContents, basketPath) => {\n if (!previousBasketContents) {\n // if there's a previousBasketContents object then there was a cart merge.\n // if not, then there wasn't and there's nothing for us to be doing.\n return;\n }\n\n const {\n prints_quantity: printsQuantity,\n prism_items_summary: prismItems = [],\n } = previousBasketContents;\n\n if (printsQuantity || prismItems.length) {\n // show the user what was merged from the other basket\n this.setState(\n Object.assign({}, previousBasketContents, { loaded: true }),\n this.open\n );\n } else {\n // there was nothing merged, instead the earlier session has taken over.\n this.setState({\n basketPath\n });\n this.sendNotifyCartMerged();\n }\n }\n\n handleModalOnHidden = () => {\n this.sendNotifyCartMerged();\n }\n\n handleModalOnHide = () => {\n const { $otherModals } = this.state;\n\n $otherModals.forEach(($otherModal) => {\n $otherModal.modal('show');\n });\n }\n\n handleModalOnShow = () => {\n const $otherModals = [];\n\n $('.modal:visible').each((i, el) => {\n const $otherModal = $(el);\n $otherModals.push($otherModal);\n $otherModal.modal('hide');\n });\n\n this.setState({\n $otherModals\n })\n }\n\n sendNotifyCartMerged = () => {\n const { basketPath } = this.state;\n\n builderDispatch.delayedDispatch({\n type: WebUI.CART_MERGED,\n basketPath,\n });\n }\n\n renderBody = () => {\n const { loaded } = this.state;\n\n if (!loaded) {\n return (\n
\n )\n }\n\n return (\n
\n

{this.renderHeadlineMessage()}

\n
{this.renderPreviews()}
\n

\n For your convenience, we have merged the contents of the old{' '}\n {translate('cart')} into the current one.{' '}\n {this.renderComponentsMessage()}\n

\n

Please review your order before proceeding to checkout.

\n
\n )\n }\n\n renderComponentsMessage = () => {\n const {\n prints_quantity: printsQuantity,\n prism_items_summary: prismItems,\n } = this.state;\n\n const portions = prismItems.map(item => `${item.quantity} ${item.title}`);\n\n if (printsQuantity) {\n portions.unshift(\n `${printsQuantity} ${printsQuantity === 1 ? 'print' : 'prints'}`\n );\n }\n\n return `${stringifyPortions(portions)} ${portions.length === 1 && printsQuantity === 1 ? 'has' : 'have'} been added to your ${translate('cart')} as a result.`;\n }\n\n renderHeadlineMessage = () => {\n const {\n prints_quantity: printsQuantity,\n prism_items_summary: prismItemsSummary\n } = this.state;\n\n const prismItemsQuantity = prismItemsSummary.length;\n const portions = [];\n\n if (printsQuantity) {\n portions.push(\n `${printsQuantity} ${printsQuantity === 1 ? 'print' : 'prints'}`\n );\n }\n\n if (prismItemsQuantity) {\n portions.push(\n `${prismItemsQuantity} ${prismItemsQuantity === 1 ? 'item' : 'items'}`\n );\n }\n\n return `You already had ${portions.join(' and ')} in your ${translate('cart')} from a previous visit.`;\n }\n\n renderPreviewItems = (thumbnails) => {\n return thumbnails.map((t, i) => {\n if (t.type === 'PRISM') {\n const key = `prism_preview_${i}`;\n\n return (\n \n );\n }\n\n const key = `prints_preview_${i}`;\n\n return (\n \n );\n });\n }\n\n renderPreviews = () => {\n const {\n prints_thumbnail: printsThumbnail,\n prism_items_summary: prismItems,\n } = this.state;\n\n const mergedThumbnails = mergeThumbnails(printsThumbnail, prismItems);\n\n return this.renderPreviewItems(mergedThumbnails.slice(0, PREVIEW_THUMBS_MAX))\n }\n\n render() {\n return (\n
\n
\n
\n
\n

{translate('Cart')} updated

\n \n ×\n \n
\n
{this.renderBody()}
\n
\n \n Ok\n \n
\n
\n
\n
\n )\n }\n}\n\nexport default CartMergedNotification;\n","import React from 'react';\n// Import Libraries\nimport ReactDOM from 'react-dom';\n// Import Main component\nimport CartMergedNotification from '../customer_pages/_cart-merged-notification/cart-merged-notification';\n\nReactDOM.render(\n ,\n document.getElementById('cart-merged-notification'),\n);\n"],"names":["PrintsPreview","thumbUrl","React","PrismPreview","PREVIEW_THUMBS_MAX","mergeThumbnails","printsThumbnail","prismItems","mergedThumbnails","e","stringifyPortions","portions","CartMergedNotification","__publicField","ReactDOM","previousBasketContents","basketPath","printsQuantity","$otherModals","$otherModal","i","el","builderDispatch","WebUI","loaded","translate","item","prismItemsSummary","prismItemsQuantity","thumbnails","t","key","payload"],"mappings":"sVAWA,MAAMA,EAAgB,CAAC,CAAE,SAAAC,KAErBC,EAAA,cAAC,MAAI,CAAA,UAAU,yBACb,EAAAA,EAAA,cAAC,MAAI,CAAA,UAAU,cACb,EAAAA,EAAA,cAAC,MAAI,IAAA,EACJA,EAAA,cAAA,MAAA,IAAI,EACJA,EAAA,cAAA,MAAA,IAAI,EACLA,EAAA,cAAC,MAAI,CAAA,IAAKD,EAAU,IAAI,gBAAgB,UAAU,wBAAyB,CAAA,CAC7E,CACF,EAOEE,EAAe,CAAC,CAAE,SAAAF,KAEnBC,EAAA,cAAA,MAAA,CAAI,UAAU,yBAAA,EACZA,EAAA,cAAA,MAAA,CAAI,IAAKD,EAAU,IAAI,gBAAgB,UAAU,uBAAwB,CAAA,CAC5E,EAIEG,EAAqB,EAErBC,EAAkB,CAACC,EAAiBC,IAAe,CACvD,MAAMC,EAAmBD,EAAW,IAAKE,IAAO,CAC9C,KAAM,QACN,SAAUA,EAAE,SACZ,EAAA,EAEF,OAAIH,GACFE,EAAiB,QAAQ,CACvB,KAAM,SACN,SAAUF,CAAA,CACX,EAGIE,CACT,EAEME,EAAqBC,GAAa,CACtC,OAAQA,EAAS,OAAQ,CACvB,IAAK,GACH,OAAOA,EAAS,CAAC,EACnB,IAAK,GACI,OAAAA,EAAS,KAAK,OAAO,EAC9B,QACE,MAAO,GAAGA,EAAS,MAAM,EAAGA,EAAS,OAAS,CAAC,EAAE,KAAK,IAAI,CAAC,QAAQA,EAASA,EAAS,OAAS,CAAC,CAAC,EACpG,CACF,EAEA,MAAMC,UAA+BV,EAAM,SAAU,CACnD,aAAc,CACN,QAmCRW,EAAA,YAAO,IAAM,CACG,KAAK,gBACb,MAAM,MAAM,CAAA,GAGpBA,EAAA,qBAAgB,IA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