{"version":3,"file":"CommonHelpers-DhM8sVTE.js","sources":["../../Client/api/CommercialApi/index.ts","../../Client/legacy/Commercial/CommonHelpers.ts"],"sourcesContent":["import {\r\n    CommercialBindQuoteRequest,\r\n    CommercialOccupancyTypeOptionsModel,\r\n    CommercialQuoteCreateRequest,\r\n    CommercialQuoteModel,\r\n    CommercialQuotePatchRequest,\r\n    ComparisonQuotesModel,\r\n    IDropdownQuoteSummaryItem,\r\n    IQuoteDetails,\r\n    PropertyData,\r\n    QuoteRequestEvent,\r\n    RepriceModel,\r\n} from '@shared/Models';\r\nimport { CategoryData } from '@webkit/components/categorySelect/models';\r\nimport * as NProgress from 'nprogress';\r\nimport * as ApiCaller from '../ApiCaller';\r\nimport { fetchAndLog } from '../Fetch';\r\n\r\nexport function getOrCreateQuote(request: CommercialQuoteCreateRequest): Promise<CommercialQuoteModel> {\r\n    return ApiCaller.$put('api/commercial/quotes', request, NProgress, 'get or create quote');\r\n}\r\n\r\nexport function getOrCreateComparisonQuote(request: CommercialQuoteCreateRequest): Promise<ComparisonQuotesModel> {\r\n    return fetchAndLog(`/api/commercial/quotes/comparisonquotes`, 'get or create comparison quote', {\r\n        method: 'PUT',\r\n        body: JSON.stringify(request),\r\n    });\r\n}\r\n\r\nexport function bindQuote(request: CommercialBindQuoteRequest) {\r\n    return ApiCaller.$post('api/commercial/bind', request, NProgress, 'bind quote');\r\n}\r\n\r\nexport function getQuoteByQuoteId(quoteId: string): Promise<CommercialQuoteModel> {\r\n    return ApiCaller.$get(`api/commercial/quotes/quoteid/${quoteId}`, NProgress, 'get quote by quoteId');\r\n}\r\n\r\nexport function getQuoteByQuoteHistory(reprice: RepriceModel): Promise<CommercialQuoteModel> {\r\n    return ApiCaller.$post(`api/commercial/quotes/quotehistory`, reprice, NProgress, 'get quote by quoteHistory');\r\n}\r\n\r\nexport function patchQuote(patch: CommercialQuotePatchRequest): Promise<CommercialQuoteModel> {\r\n    const gaEventAction = patch.gaEventAction || 'update commercial quote';\r\n    return ApiCaller.$patch(`api/commercial/quotes`, patch, NProgress, gaEventAction);\r\n}\r\n\r\n/**\r\n * Logs an unsuccessful attempt to lookup an address using a technique that allows it to succeed even as the page is navigating away.\r\n */\r\nexport function logQuoteRequestSafe(event: QuoteRequestEvent) {\r\n    const url =\r\n        `/api/log/quoterequest?eventName=${encodeURIComponent(event.EventName)}` +\r\n        `&addressKey=${encodeURIComponent(event.AddressKey || '')}` +\r\n        `&address=${encodeURIComponent(event.Address)}` +\r\n        `&description=${encodeURIComponent(event.Description || '')}`;\r\n    ApiCaller.$sendBeacon(url);\r\n}\r\n\r\nexport function getQuoteDetails(quoteId: string): Promise<IQuoteDetails> {\r\n    // I removed the NProgress here because we don't need it to show progress on loading when the modal isn't even displayed yet. 4/29/20 - Darius Carrick\r\n    return ApiCaller.$get(`api/commercial/quotes/${quoteId}/details`, null, 'get quote details by quoteId');\r\n}\r\n\r\nexport async function getAddressMatches(\r\n    partialAddress: string,\r\n    signal?: AbortSignal,\r\n    max?: number\r\n): Promise<PropertyData[]> {\r\n    partialAddress = partialAddress ? partialAddress.substring(0, 100).trim() : '';\r\n    if (!partialAddress) {\r\n        return Promise.resolve([]);\r\n    }\r\n\r\n    let url = `/api/property/addressMatches?productLine=2&partialAddress=${encodeURIComponent(partialAddress)}`;\r\n    if (max) {\r\n        url += `&max=${max}`;\r\n    }\r\n\r\n    return await fetchAndLog<PropertyData[]>(url, 'get commercial address matches', { signal });\r\n}\r\n\r\nexport async function getExistingCommercialQuotes(\r\n    partialAddress: string,\r\n    signal: AbortSignal\r\n): Promise<IDropdownQuoteSummaryItem[]> {\r\n    const url = `/api/commercial/quotes?partialAddress=${encodeURIComponent(partialAddress)}`;\r\n    return await fetchAndLog<IDropdownQuoteSummaryItem[]>(url, 'get existing quotes', { signal });\r\n}\r\n\r\nexport function initiateReprice(reprice: RepriceModel): Promise<CommercialQuoteModel> {\r\n    return ApiCaller.$post(`api/commercial/quotes/initiatereprice`, reprice, null, 'initiate reprice');\r\n}\r\n\r\nexport function acceptReprice(quoteId: string, reprice: RepriceModel) {\r\n    return ApiCaller.$post(`api/commercial/quotes/${quoteId}/acceptreprice`, reprice, null, 'accept reprice');\r\n}\r\n\r\nexport function getPolicyAge(quoteId: string): Promise<number> {\r\n    return ApiCaller.$get(`api/commercial/quotes/${quoteId}/policyage`, null, 'get age of policy');\r\n}\r\n\r\nexport function isRewrite(imsQuoteGuid: string): Promise<boolean> {\r\n    return ApiCaller.$get(\r\n        `api/commercial/quotes/${imsQuoteGuid}/isrewrite`,\r\n        null,\r\n        'check if quote is a rewrite for commercial'\r\n    );\r\n}\r\n\r\nexport function updateEffectiveDate(quoteId: string, effectiveDate: Date) {\r\n    return ApiCaller.$post(`api/commercial/quotes/${quoteId}/updateeffectivedate`, effectiveDate);\r\n}\r\n\r\nexport function requestAppointment(name: string, email: string) {\r\n    return ApiCaller.$post(\r\n        'api/commercial/request-appointment',\r\n        {\r\n            Name: name,\r\n            EmailAddress: email,\r\n        },\r\n        null\r\n    );\r\n}\r\n\r\nexport function setAgentId(quoteId: string, agentId: number): Promise<CommercialQuoteModel> {\r\n    return ApiCaller.$put(\r\n        `api/commercial/quotes/${quoteId}/setagent/${agentId}`,\r\n        null,\r\n        NProgress,\r\n        'assign commercial quote to agent'\r\n    );\r\n}\r\n\r\nexport function getQuotePreFlightDocumentsUrl(quoteId: string): Promise<string> {\r\n    return ApiCaller.$get(\r\n        `api/commercial/quotes/${quoteId}/onedriveurl`,\r\n        null,\r\n        'get one drive folder for commercial quote preflight documents from quote details modal'\r\n    );\r\n}\r\n\r\nexport async function getConstructionTypes() {\r\n    return fetchAndLog<string[]>('/api/commercial/quotes/construction-types', 'get commercial construction types');\r\n}\r\n\r\n/** Returns Commercial occupancy type options grouped by category.\r\n * See CommercialQuoteApiController.cs\r\n */\r\nexport async function getOccupancyTypes(signal: AbortSignal): Promise<CategoryData[]> {\r\n    const data = await fetchAndLog<CommercialOccupancyTypeOptionsModel[]>(\r\n        '/api/commercial/quotes/get-occupancy-types',\r\n        'get commercial occupancy types',\r\n        { signal }\r\n    );\r\n\r\n    return data.map(item => ({\r\n        name: item.Category,\r\n        items: item.Items.map(item => ({\r\n            name: item,\r\n            items: [],\r\n        })),\r\n    }));\r\n}\r\n\r\n/** Returns true if the occupancy type parsed from the display name supports multiple units. */\r\nexport async function occupancySupportsMultipleUnits(occupancyTypeDisplayName: string) {\r\n    return fetchAndLog<boolean>(\r\n        `/api/commercial/quotes/occupancy-supports-multiple-units/${encodeURIComponent(occupancyTypeDisplayName)}`,\r\n        'check if commercial occupancy type supports multiple units'\r\n    );\r\n}\r\n\r\n/** Returns the occupancy type set value after parsing it from the display name. */\r\nexport async function getOccupancyTypeValue(occupancyTypeDisplayName: string): Promise<string> {\r\n    return fetchAndLog<string>(\r\n        `/api/commercial/quotes/get-occupancy-type-value/${encodeURIComponent(occupancyTypeDisplayName)}`,\r\n        'get commercial occupancy type value'\r\n    );\r\n}\r\n","import * as React from 'react';\r\nimport * as ReactDom from 'react-dom';\r\n\r\nimport * as CommApi from '@api/CommercialApi';\r\nimport * as Common from '@shared/Common';\r\nimport * as Constants from '@shared/Constants';\r\nimport * as Models from '@shared/Models';\r\nimport * as Storage from '@shared/Storage';\r\n\r\nimport Alert from '../Components/Modals/Alert';\r\n\r\nlet RenderedCommercialErrorModal;\r\n\r\nexport async function getCommQuoteFromScratch(): Promise<Models.CommercialQuoteModel> {\r\n    const quoteId = Storage.getQuoteId();\r\n\r\n    if (!quoteId) {\r\n        throw 'No QuoteId was found';\r\n    }\r\n\r\n    try {\r\n        const quote = await CommApi.getQuoteByQuoteId(quoteId);\r\n\r\n        if (!!quote && !quote.IsOk)\r\n            return showModalHandler(\r\n                quote.ErrorMessage,\r\n                quote.Severity ? quote.Severity.m_levelName : Constants.commercialErrorSeverityTypes.Warning\r\n            );\r\n\r\n        return quote;\r\n    } catch (reason) {\r\n        //TODO: replace with error handler once error modals are merged\r\n        throw reason;\r\n    }\r\n}\r\n\r\nexport function getCommQuoteById(quoteId: string): Promise<Models.CommercialQuoteModel> {\r\n    const getQuote = CommApi.getQuoteByQuoteId(quoteId);\r\n    return getQuote.then(quote => {\r\n        if (!!quote && !quote.IsOk)\r\n            return showModalHandler(\r\n                quote.ErrorMessage,\r\n                quote.Severity ? quote.Severity.m_levelName : Constants.commercialErrorSeverityTypes.Warning\r\n            );\r\n\r\n        Storage.setQuoteId(quote.QuoteId);\r\n        return quote;\r\n    });\r\n}\r\n\r\nexport function getCommQuoteByHistory(reprice: Models.RepriceModel): Promise<Models.CommercialQuoteModel> {\r\n    const getQuote = CommApi.getQuoteByQuoteHistory(reprice);\r\n    return getQuote.then(quote => {\r\n        if (!!quote && !quote.IsOk)\r\n            return showModalHandler(\r\n                quote.ErrorMessage,\r\n                quote.Severity ? quote.Severity.m_levelName : Constants.commercialErrorSeverityTypes.Warning\r\n            );\r\n\r\n        Storage.setQuoteId(quote.QuoteId);\r\n        return quote;\r\n    });\r\n}\r\n\r\nexport async function handleGeneralError(reason: any): Promise<void> {\r\n    //normalize error reason text prior to instantiating modal.\r\n    await Common.saveAndShowError(Common.normalizeError(reason), showModalHandler);\r\n}\r\n\r\nexport function showModalHandler(message, header?, severity?) {\r\n    if (!RenderedCommercialErrorModal) {\r\n        let container = document.createElement('div');\r\n        document.body.appendChild(container);\r\n\r\n        RenderedCommercialErrorModal = ReactDom.render(React.createElement(Alert) as any, container);\r\n    }\r\n\r\n    return RenderedCommercialErrorModal.error(\r\n        message,\r\n        header || 'Issue found',\r\n        severity || Constants.AlertFooterType.Commercial\r\n    );\r\n}\r\n"],"names":["getOrCreateQuote","request","ApiCaller.$put","NProgress","getOrCreateComparisonQuote","fetchAndLog","bindQuote","ApiCaller.$post","getQuoteByQuoteId","quoteId","ApiCaller.$get","getQuoteByQuoteHistory","reprice","patchQuote","patch","gaEventAction","ApiCaller.$patch","logQuoteRequestSafe","event","url","ApiCaller.$sendBeacon","getQuoteDetails","getAddressMatches","partialAddress","signal","max","getExistingCommercialQuotes","initiateReprice","acceptReprice","getPolicyAge","isRewrite","imsQuoteGuid","updateEffectiveDate","effectiveDate","requestAppointment","name","email","setAgentId","agentId","getQuotePreFlightDocumentsUrl","getConstructionTypes","getOccupancyTypes","item","occupancySupportsMultipleUnits","occupancyTypeDisplayName","getOccupancyTypeValue","RenderedCommercialErrorModal","getCommQuoteFromScratch","Storage.getQuoteId","quote","CommApi.getQuoteByQuoteId","showModalHandler","Constants.commercialErrorSeverityTypes","reason","getCommQuoteById","Storage.setQuoteId","getCommQuoteByHistory","CommApi.getQuoteByQuoteHistory","handleGeneralError","Common.saveAndShowError","Common.normalizeError","message","header","severity","container","ReactDom.render","React.createElement","Alert","Constants.AlertFooterType"],"mappings":"4TAkBO,SAASA,EAAiBC,EAAsE,CACnG,OAAOC,EAAe,wBAAyBD,EAASE,EAAW,qBAAqB,CAC5F,CAEO,SAASC,EAA2BH,EAAuE,CACvG,OAAAI,EAAY,0CAA2C,iCAAkC,CAC5F,OAAQ,MACR,KAAM,KAAK,UAAUJ,CAAO,CAAA,CAC/B,CACL,CAEO,SAASK,EAAUL,EAAqC,CAC3D,OAAOM,EAAgB,sBAAuBN,EAASE,EAAW,YAAY,CAClF,CAEO,SAASK,EAAkBC,EAAgD,CAC9E,OAAOC,EAAe,iCAAiCD,CAAO,GAAIN,EAAW,sBAAsB,CACvG,CAEO,SAASQ,EAAuBC,EAAsD,CACzF,OAAOL,EAAgB,qCAAsCK,EAAST,EAAW,2BAA2B,CAChH,CAEO,SAASU,EAAWC,EAAmE,CACpF,MAAAC,EAAgBD,EAAM,eAAiB,0BAC7C,OAAOE,EAAiB,wBAAyBF,EAAOX,EAAWY,CAAa,CACpF,CAKO,SAASE,EAAoBC,EAA0B,CACpD,MAAAC,EACF,mCAAmC,mBAAmBD,EAAM,SAAS,CAAC,eACvD,mBAAmBA,EAAM,YAAc,EAAE,CAAC,YAC7C,mBAAmBA,EAAM,OAAO,CAAC,gBAC7B,mBAAmBA,EAAM,aAAe,EAAE,CAAC,GAC/DE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