{"version":3,"sources":["webpack:///./src/api/api-types.ts","webpack:///./src/hooks/useSearchParams.tsx","webpack:///./src/api/hooks/useParty.ts","webpack:///./src/view-models/DeclarationActionTypes.ts","webpack:///./src/components/StatusMessages/StatusMessageOverlay.tsx"],"names":["CollectionState","ElectionType","collectionStateMap","running","locked","approved","noCollection","deactivated","electionTypeMap","Folketingsvalg","EuropaParlamentsvalg","lookupMap","0","dk","1","eu","useElectionType","searchParams","useRouter","electionType","undefined","electionTypeValue","isDefined","value","get","key","toLowerCase","usePartyId","partyId","loadParty","a","url","error","CancelledError","message","status","fetcher","result","serviceResult","prefetchParty","options","queryCache","prefetchQuery","retry","staleTime","useParty","useQuery","enabled","displayName","DeclarationActionTypes","getErrorWithState","state","action","defaultMassage","stateInteger","parseInt","initiate","confirm","withdraw","StatusMessageOverlay","isOpen","onDismiss","t","useDictionary","suspense","data","interpolation","party","name","titleKey","textKey","MessageStatusTypes","ok","title","asString"],"mappings":"0OAQYA,E,iBAAAA,O,qBAAAA,I,mBAAAA,I,uBAAAA,I,+BAAAA,I,8BAAAA,M,KAWL,IAYKC,EAZCC,GAAkB,mBAC5BF,EAAgBG,QAAU,WADE,cAE5BH,EAAgBI,OAAS,UAFG,cAG5BJ,EAAgBK,SAAW,YAHC,cAI5BL,EAAgBM,aAAe,gBAJH,cAK5BN,EAAgBO,YAAc,eALF,I,SAYnBN,O,mCAAAA,I,gDAAAA,M,KAQL,IAAMO,GAAe,mBACzBP,EAAaQ,eAAiB,MADL,cAEzBR,EAAaS,qBAAuB,MAFX,I,iCCvC5B,yFAIMC,EAAY,CAChBC,EAAGX,IAAaQ,eAChBI,GAAIZ,IAAaQ,eACjBK,EAAGb,IAAaS,qBAChBK,GAAId,IAAaS,sBAYZ,SAASM,IAId,MACQC,EAAiBC,cAAjBD,aACR,IAAKA,EACH,MAAO,CACLE,kBAAcC,EACdC,uBAAmBD,EACnBE,WAAW,GAKf,IAAMC,EACJN,EAAaO,IAAI,aAAeP,EAAaO,IAAI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AAD,CACEV,OAAQA,EACRC,UAAWA,EACXY,MAAOX,EAAE5B,EAAQmC,SAAT,YAAC,eAAuBH,GAAxB,IAAuCQ,UAAU,MAEzD,YAAC,IAAD,KACGZ,EAAE5B,EAAQoC,QAAT,YAAC,eAAsBJ,GAAvB,IAAsCQ,UAAU","file":"static/scripts/4-07620f8445d33d7910e9.js","sourcesContent":["import { CancelledError } from 'react-query';\n\n/**\n * Make sure the order here matches the CollectionState.cs\n * See: https://dev.azure.com/charlietango-ve/V%C3%A6lgererkl%C3%A6ringer/_git/VE%20Core?path=%2FVeCore.Entities%2FEnums%2FCollectionState.cs\n * */\nimport { SchemaProblemDetails } from './api-schema';\n\nexport enum CollectionState {\n running,\n locked,\n approved,\n noCollection,\n deactivated,\n}\n\n/**\n * Map the Enum value (the number) to a string value.\n * */\nexport const collectionStateMap = {\n [CollectionState.running]: 'running',\n [CollectionState.locked]: 'locked',\n [CollectionState.approved]: 'approved',\n [CollectionState.noCollection]: 'noCollection',\n [CollectionState.deactivated]: 'deactivated',\n};\n\n/**\n * Make sure the order here matches the ElectionType.cs\n * See: https://dev.azure.com/charlietango-ve/V%C3%A6lgererkl%C3%A6ringer/_git/VE%20Core?path=%2FVeCore.Entities%2FEnums%2FElectionType.cs\n * */\nexport enum ElectionType {\n Folketingsvalg = 0,\n EuropaParlamentsvalg = 1,\n}\n\n/**\n * Map the Enum value (the number) to a string value.\n * */\nexport const electionTypeMap = {\n [ElectionType.Folketingsvalg]: 'dk',\n [ElectionType.EuropaParlamentsvalg]: 'eu',\n};\n\nexport interface IError extends CancelledError {\n message?: string;\n status?: number;\n pathname?: string;\n details?: SchemaProblemDetails;\n response?: Object;\n request?: Object;\n}\n","import { ElectionType, electionTypeMap } from '../api/api-types';\nimport { useRouter } from '../application/Router';\n\n// Valid values for the election query param\nconst lookupMap = {\n 0: ElectionType.Folketingsvalg,\n dk: ElectionType.Folketingsvalg,\n 1: ElectionType.EuropaParlamentsvalg,\n eu: ElectionType.EuropaParlamentsvalg,\n};\n\n/**\n * Get the current electionType from the url search params\n * */\nexport function useElectionType(): {\n electionType: ElectionType;\n electionTypeValue: string;\n isDefined: true;\n};\n// eslint-disable-next-line no-redeclare\nexport function useElectionType(): {\n electionType?: ElectionType;\n electionTypeValue?: string;\n isDefined: boolean;\n} {\n const { searchParams } = useRouter();\n if (!searchParams) {\n return {\n electionType: undefined,\n electionTypeValue: undefined,\n isDefined: false,\n };\n }\n\n // Check for the election type in search params. Check for both `election` and `electionType`.\n const value =\n searchParams.get('election') || searchParams.get('electionType');\n // Check if the value exists, and return the election type that matches\n const key = (value && lookupMap[value.toLowerCase()]) ?? undefined;\n const electionType = key || ElectionType.Folketingsvalg;\n\n return {\n electionType,\n electionTypeValue: electionTypeMap[electionType],\n isDefined: key !== undefined,\n };\n}\n\n/**\n * Get the current party Id from the url search params\n * */\nexport function usePartyId() {\n const { searchParams } = useRouter();\n if (!searchParams) return { partyId: undefined };\n\n return { partyId: searchParams.get('party') };\n}\n","import {\n CancelledError,\n QueryConfig,\n QueryResult,\n queryCache,\n useQuery,\n} from 'react-query';\n\nimport { SchemaPartyDetailsResponse } from '../api-schema';\nimport { IError } from '../api-types';\nimport { fetcher } from '../fetcher';\n\nconst queryKey = 'party';\nconst staleTime = 1000 * 60 * 5;\n\nasync function loadParty(key: string, partyId?: string | null) {\n const url = partyId ? `/api/v1/parties/${partyId}` : null;\n if (!url) {\n const error: IError = new CancelledError();\n error.message = '[404] No partyId provided';\n error.status = 404;\n throw error;\n }\n\n const result: SchemaPartyDetailsResponse = await fetcher(url);\n if (result.serviceResult === 0) {\n // Invalid parti - Most likely caused by a valid UUID structure, but without a matching parti.\n const error: IError = new CancelledError();\n error.message = '[404] Parti not found';\n error.status = 404;\n throw error;\n }\n\n return result;\n}\n\nexport function prefetchParty(\n partyId?: string,\n options?: QueryConfig,\n) {\n if (!partyId) return null;\n return queryCache.prefetchQuery([queryKey, partyId], loadParty, {\n retry: false,\n staleTime,\n ...options,\n });\n}\n\n/**\n * Get specific party by id\n * */\nexport function useParty(\n partyId?: string | null,\n options?: QueryConfig,\n): QueryResult {\n return useQuery([queryKey, partyId], loadParty, {\n enabled: !!partyId,\n staleTime,\n ...options,\n });\n}\n\nuseParty.displayName = 'useParty';\n","export enum DeclarationActionTypes {\n initiate = 'initiate',\n confirm = 'confirm',\n withdraw = 'withdraw',\n}\n","import * as React from 'react';\n\nimport { useParty } from '../../api/hooks/useParty';\nimport { useDictionary } from '../../hooks/useDictionary';\nimport { useElectionType, usePartyId } from '../../hooks/useSearchParams';\nimport { DeclarationActionTypes } from '../../view-models/DeclarationActionTypes';\nimport { MessageStatusTypes } from '../../view-models/MessageStatusTypes';\nimport Modal from '../Modal/Modal';\nimport RichText from '../RichText/RichText';\nimport { CollectionState } from '../../api/api-types';\n\nexport function getErrorWithState(state, action, defaultMassage) {\n const stateInteger = parseInt(state);\n\n switch (action) {\n case DeclarationActionTypes.initiate:\n if (stateInteger === CollectionState.locked) {\n return 'errors.declaration_initiation_election_locked_text';\n }\n if (stateInteger === CollectionState.approved) {\n return 'errors.declaration_initiation_election_approved_text';\n }\n if (stateInteger === CollectionState.deactivated) {\n return 'errors.declaration_initiation_election_deactivated_text';\n }\n if (stateInteger === CollectionState.noCollection) {\n return 'errors.declaration_initiation_election_deleted_text';\n }\n return defaultMassage;\n case DeclarationActionTypes.confirm:\n if (stateInteger === CollectionState.locked) {\n return 'errors.declaration_confirmation_election_locked_text';\n }\n if (stateInteger === CollectionState.approved) {\n return 'errors.declaration_confirmation_election_approved_text';\n }\n if (stateInteger === CollectionState.deactivated) {\n return 'errors.declaration_confirmation_election_deactivated_text';\n }\n if (stateInteger === CollectionState.noCollection) {\n return 'errors.declaration_confirmation_election_deleted_text';\n }\n return defaultMassage;\n case DeclarationActionTypes.withdraw:\n if (stateInteger === CollectionState.locked) {\n return 'errors.declaration_withdrawal_election_locked_text';\n }\n if (stateInteger === CollectionState.approved) {\n return 'errors.declaration_withdrawal_election_approved_text';\n }\n if (stateInteger === CollectionState.deactivated) {\n return 'errors.declaration_withdrawal_election_deactivated_text';\n }\n if (stateInteger === CollectionState.noCollection) {\n return 'errors.declaration_withdrawal_election_deleted_text';\n }\n return defaultMassage;\n default:\n return defaultMassage;\n }\n}\n\ntype Props = {\n isOpen: boolean;\n onDismiss: () => void;\n status: MessageStatusTypes;\n action?: DeclarationActionTypes | null;\n state?: CollectionState;\n};\n\nfunction StatusMessageOverlay({\n isOpen = true,\n onDismiss,\n action,\n status,\n state,\n}: Props) {\n const { t } = useDictionary();\n const { electionTypeValue } = useElectionType();\n const { partyId } = usePartyId();\n const { data, status: loadingStatus } = useParty(partyId, { suspense: true });\n\n if (loadingStatus === 'loading') return null;\n\n const interpolation = {\n party: data?.name,\n electionType: t(`${electionTypeValue}Election`),\n };\n\n let message = {\n titleKey: 'errors.generic_title',\n textKey: 'errors.generic_text',\n };\n\n switch (action) {\n case DeclarationActionTypes.confirm:\n if (status === MessageStatusTypes.error) {\n message.textKey = getErrorWithState(state, action, message.textKey);\n }\n if (status === MessageStatusTypes.ok) {\n message.titleKey = 'modal.status_14_02_title';\n message.textKey = 'modal.status_14_02_text';\n }\n break;\n case DeclarationActionTypes.withdraw:\n if (status === MessageStatusTypes.error) {\n message.textKey = getErrorWithState(state, action, message.textKey);\n }\n if (status === MessageStatusTypes.ok) {\n message.titleKey = 'modal.status_14_03_title';\n message.textKey = 'modal.status_14_03_text';\n }\n break;\n case undefined:\n if (status === 'error') {\n message.titleKey = 'errors.data_not_initialized_title';\n message.textKey = 'errors.data_not_initialized_text';\n }\n break;\n }\n\n return (\n \n \n {t(message.textKey, { ...interpolation, asString: true })}\n \n \n );\n}\n\nexport default StatusMessageOverlay;\n"],"sourceRoot":""}