{"version":3,"file":"index-d6625d59.js","sources":["../../../client-app/src/common/services/sanityService/index.ts","../../../client-app/src/common/lib/utm.ts","../../../client-app/src/common/components/CmsNotification/index.tsx"],"sourcesContent":["import { getCmsBaseUri } from '@n2-common/lib/serverSideConfigs';\nimport { CmsNotification } from './cmsNotification';\nimport { default as fetch } from '@n2-common/lib/fetchProxy';\nimport { CmsMyPageContent } from './mypageContent';\n\nexport async function getNotifications(key: string, signal?: AbortSignal): Promise {\n const requestPath = `/api/notifications?key=${key}`;\n try {\n const cmsBaseUri = getCmsBaseUri();\n const response = await fetch(cmsBaseUri + requestPath, { method: 'GET', redirect: 'error', signal });\n const notifications = (await response.json()) as CmsNotification[];\n return notifications;\n } catch (err) {\n return [] as CmsNotification[];\n }\n}\n\nexport async function getMyPageContent(\n key: string,\n country: Country,\n hasLoan: boolean,\n hasCreditCard: boolean,\n hasSavings: boolean,\n signal?: AbortSignal\n): Promise {\n const requestPath = `/api/mypage-content/${key}?country=${country}&hasLoan=${hasLoan}&hasCreditCard=${hasCreditCard}&hasSavings=${hasSavings}`;\n try {\n const cmsBaseUri = getCmsBaseUri();\n const response = await fetch(cmsBaseUri + requestPath, { method: 'GET', redirect: 'error', signal });\n if (!response.ok) {\n throw new Error(`Failed to get my page content for key: ${key}`);\n }\n const notifications = (await response.json()) as CmsMyPageContent;\n return notifications;\n } catch (err) {\n return Promise.reject(err);\n }\n}\n","interface UtmParams {\n medium: string | null;\n campaign: string | null;\n source: string | null;\n}\n\nexport const getUtmlValues = (window: Window): UtmParams => {\n const url = new URL(window.location.href);\n console.log(url.searchParams.get('utm_medium'));\n return {\n medium: url.searchParams.get('utm_medium'),\n campaign: url.searchParams.get('utm_campaign'),\n source: url.searchParams.get('utm_source'),\n };\n};\n","import { useEffect, useState } from 'react';\n\nimport { getNotifications } from '@n2-common/services/sanityService';\nimport { type CmsNotification as CmsNotificationType, CmsNotificationLink } from '@n2-common/services/sanityService/cmsNotification';\nimport { HeadlineStyledSpan, Hero, Paragraph } from '@n2-common/ui';\nimport style from './style.module.scss';\nimport { getUtmlValues } from '@n2-common/lib/utm';\n\ninterface LinkData {\n key: string;\n value: string;\n}\n\nconst externalLink = (link: CmsNotificationLink, linkData?: LinkData[]) => {\n let finalLink = link.url.externalLink || '';\n if (linkData) {\n linkData.forEach((elm) => {\n finalLink = finalLink?.replaceAll(`{${elm.key}}`, elm.value)\n });\n }\n return {link.text} ;\n}\n\nexport const CmsFragementWithUtmVariants = ({ cmsKeyBase, linkData }: { cmsKeyBase: string; linkData: LinkData[] }) => {\n const utmValues = getUtmlValues(window);\n const cmsKeyWithUtmSource = utmValues.source ? `${cmsKeyBase}_${utmValues.source?.toLowerCase()}` : null;\n const cmsKeyWithUtmSourceAndMedium = utmValues.medium ? `${cmsKeyWithUtmSource}_${utmValues.medium?.toLowerCase()}` : null;\n const cmsKeyWithUtmSourceAndMediumAndCampaign = utmValues.campaign\n ? `${cmsKeyWithUtmSourceAndMedium}_${utmValues.campaign?.toLowerCase()}`\n : null;\n\n return (\n <>\n \n {cmsKeyWithUtmSource && }\n {cmsKeyWithUtmSourceAndMedium && }\n {cmsKeyWithUtmSourceAndMediumAndCampaign && }\n \n );\n};\n\n\nconst CmsNotification = ({ cmsKey, className, linkData }: { cmsKey: string; className?: string, linkData?: LinkData[] }): JSX.Element => {\n const notifications = useCmsNotification(cmsKey);\n\n if (notifications.length === 0) {\n return <>;\n }\n return (\n <>\n {notifications.map((elm, i) => {\n return (\n \n {elm.title}\n {elm.description}\n {elm.link && elm.showLink && elm.link.url.externalLink ? \n externalLink(elm.link, linkData)\n : null}\n \n );\n })}\n \n );\n};\n\nexport function useCmsNotification(cmsKey: string) {\n const [notifications, setNotifications] = useState([]);\n\n useEffect(() => {\n if (!cmsKey) {\n return;\n }\n const controller = new AbortController();\n getNotifications(cmsKey, controller.signal).then((res) => {\n setNotifications(res);\n });\n return () => controller.abort();\n }, [cmsKey]);\n return notifications;\n}\n\nexport default CmsNotification;\n"],"names":["getNotifications","key","signal","requestPath","cmsBaseUri","getCmsBaseUri","fetch","getMyPageContent","country","hasLoan","hasCreditCard","hasSavings","response","err","getUtmlValues","window","url","externalLink","link","linkData","finalLink","elm","jsx","style","CmsFragementWithUtmVariants","cmsKeyBase","utmValues","cmsKeyWithUtmSource","_a","cmsKeyWithUtmSourceAndMedium","_b","cmsKeyWithUtmSourceAndMediumAndCampaign","_c","jsxs","Fragment","CmsNotification","cmsKey","className","notifications","useCmsNotification","i","Hero","HeadlineStyledSpan","Paragraph","setNotifications","useState","useEffect","controller","res"],"mappings":"4IAKsB,eAAAA,EAAiBC,EAAaC,EAAkD,CAC5F,MAAAC,EAAc,0BAA0BF,CAAG,GAC7C,GAAA,CACA,MAAMG,EAAaC,IAGZ,OADgB,MADN,MAAMC,EAAMF,EAAaD,EAAa,CAAE,OAAQ,MAAO,SAAU,QAAS,OAAAD,CAAQ,CAAA,GAC7D,YAE5B,CACV,MAAO,EACX,CACJ,CAEA,eAAsBK,EAClBN,EACAO,EACAC,EACAC,EACAC,EACAT,EACyB,CACnB,MAAAC,EAAc,uBAAuBF,CAAG,YAAYO,CAAO,YAAYC,CAAO,kBAAkBC,CAAa,eAAeC,CAAU,GACxI,GAAA,CACA,MAAMP,EAAaC,IACbO,EAAW,MAAMN,EAAMF,EAAaD,EAAa,CAAE,OAAQ,MAAO,SAAU,QAAS,OAAAD,CAAQ,CAAA,EAC/F,GAAA,CAACU,EAAS,GACV,MAAM,IAAI,MAAM,0CAA0CX,CAAG,EAAE,EAG5D,OADgB,MAAMW,EAAS,aAEjCC,EAAK,CACH,OAAA,QAAQ,OAAOA,CAAG,CAC7B,CACJ,CC/Ba,MAAAC,EAAiBC,GAA8B,CACxD,MAAMC,EAAM,IAAI,IAAID,EAAO,SAAS,IAAI,EACxC,eAAQ,IAAIC,EAAI,aAAa,IAAI,YAAY,CAAC,EACvC,CACH,OAAQA,EAAI,aAAa,IAAI,YAAY,EACzC,SAAUA,EAAI,aAAa,IAAI,cAAc,EAC7C,OAA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