{"version":3,"file":"processRegisterError-D0ZcChGw.js","sources":["../../src/api/subscription.api.ts","../../src/queries/subscription.queries.ts","../../src/pages/register/processRegisterError.ts"],"sourcesContent":["import axios from 'axios';\r\nimport type { IStripeSubscription, IStripeSubscriptionProduct } from '../types';\r\n\r\nexport async function createSubscription(subscription: Partial) {\r\n return axios.post('subscription', subscription);\r\n}\r\n\r\nexport async function createSubscriptionForExistingUser(\r\n subscription: Partial>\r\n) {\r\n return axios.post('subscription/existing-user', subscription);\r\n}\r\n\r\nexport async function getStripeSubscriptionProducts() {\r\n return axios.get('subscription/products');\r\n}\r\n","import { queryOptions } from '@tanstack/react-query';\r\nimport { getStripeSubscriptionProducts } from '../api/subscription.api';\r\n\r\nexport function getStripeSubscriptionProductsQuery() {\r\n return queryOptions({\r\n queryKey: ['stripe-subscription-products'],\r\n queryFn: async () => (await getStripeSubscriptionProducts()).data,\r\n });\r\n}\r\n","import { showErrorToast } from '@app/core/utilities/toasts';\r\nimport axios, { type AxiosError } from 'axios';\r\nimport type { UseFormSetError } from 'react-hook-form';\r\n\r\ninterface IProps {\r\n error: unknown;\r\n reportError: (error: unknown) => void;\r\n setError: UseFormSetError<{ promoCode?: string; contactEmail?: string }>;\r\n\r\n resetCaptcha: () => void;\r\n}\r\n\r\nconst DUPLICATE_EMAIL_ERROR = 'This account already exists.';\r\n\r\n/**\r\n * Process server side error for registering a new user or creating a new company\r\n *\r\n */\r\nexport function processRegisterError(props: IProps) {\r\n const { error, reportError, setError, resetCaptcha } = props;\r\n let message = 'Registration failed';\r\n if (axios.isAxiosError(error)) {\r\n message = (error as AxiosError<{ displayMessage?: string }>).response?.data.displayMessage ?? message;\r\n }\r\n if (message.includes('Duplicate')) {\r\n setError('contactEmail', { message: DUPLICATE_EMAIL_ERROR });\r\n } else if (message.includes('Promotion code')) {\r\n setError('promoCode', { message });\r\n } else {\r\n reportError(error);\r\n showErrorToast({ message });\r\n }\r\n resetCaptcha();\r\n}\r\n"],"names":["createSubscription","subscription","axios","createSubscriptionForExistingUser","getStripeSubscriptionProducts","getStripeSubscriptionProductsQuery","queryOptions","DUPLICATE_EMAIL_ERROR","processRegisterError","props","error","reportError","setError","resetCaptcha","message","_a","showErrorToast"],"mappings":"sDAGA,eAAsBA,EAAmBC,EAA4C,CAC5E,OAAAC,EAAM,KAA0B,eAAgBD,CAAY,CACrE,CAEA,eAAsBE,EACpBF,EACA,CACO,OAAAC,EAAM,KAA0B,6BAA8BD,CAAY,CACnF,CAEA,eAAsBG,GAAgC,CAC7C,OAAAF,EAAM,IAAkC,uBAAuB,CACxE,CCZO,SAASG,GAAqC,CACnD,OAAOC,EAAa,CAClB,SAAU,CAAC,8BAA8B,EACzC,QAAS,UAAa,MAAMF,EAAA,GAAiC,IAAA,CAC9D,CACH,CCIA,MAAMG,EAAwB,+BAMvB,SAASC,EAAqBC,EAAe,OAClD,KAAM,CAAE,MAAAC,EAAO,YAAAC,EAAa,SAAAC,EAAU,aAAAC,GAAiBJ,EACvD,IAAIK,EAAU,sBACVZ,EAAM,aAAaQ,CAAK,IACfI,IAAAC,EAAAL,EAAkD,WAAlD,YAAAK,EAA4D,KAAK,iBAAkBD,GAE5FA,EAAQ,SAAS,WAAW,EAC9BF,EAAS,eAAgB,CAAE,QAASL,CAAuB,CAAA,EAClDO,EAAQ,SAAS,gBAAgB,EACjCF,EAAA,YAAa,CAAE,QAAAE,CAAA,CAAS,GAEjCH,EAAYD,CAAK,EACFM,EAAA,CAAE,QAAAF,EAAS,GAEfD,GACf"}