{"version":3,"sources":["components/SelectComponent.tsx","img/arrow_down.svg","components/SupplierComponent.tsx","util/dataRetriever.tsx","App.tsx","hooks/hooks.tsx","index.tsx"],"names":["SelectComponent","props","thisRef","useRef","useEffect","ev2","Event","bubbles","current","dispatchEvent","options","listItems","map","listElem","value","id","name","className","htmlFor","selectTitle","required","loading","ref","disabled","selectValue","onChange","e","selectedValue","currentTarget","dispatch","type","dispatchType","payload","hidden","placeholderText","SupplierComponent","supplierObj","priority","phone","email","useState","expansionAnimStarted","setExpansionAnimStarted","isAnimRunning","setIsAnimRunning","isExpanded","setExpanded","contentHeight","setContentHeight","currentContentHeight","setCurrentContentHeight","contentRef","animTime","getBoundingClientRect","height","aria-label","onClick","setTimeout","changeExpandState","tabIndex","aria-expanded","data-title","src","arrow","alt","style","noParentOtherGuid","formatAccounts","accounts","newAccountList","forEach","acc","dataAcc","newAccount","shi_account","accountid","parentId","parentaccountid","undefined","push","formatAreas","newAreaList","newArea","shi_agreement_request_form_areaid","shi_name","formatSupplier","suppliers","newSuppliers","supp","newSupplier","shi_supplier","shi_supplier_email","shi_supplier_phone","shi_priority","areaId","shi_Delomrade","accountId","shi_Request_Form_Account","generateParentAccounts","newParentAccountList","subAccounts","otherAccount","filter","index","_id","JSON","stringify","findIndex","obj","populateParentAccounts","accountList","parentAccountList","parent","newSubAccounts","account","length","pop","App","queryString","window","location","search","prodUrl","URLSearchParams","get","formattedData","setFormattedData","currentParentAccObj","setCurrentParentAccObj","url","data","setData","setLoading","responseOk","setResponseOk","a","requestHesders","Headers","append","fetch","method","headers","response","ok","json","fetchUrl","useFetch","isLoading","useReducer","reducer","currentParentAccId","parentAccDispatch","currentAccountId","accountDispatch","currentAreaId","areaDispatch","action","parentAccounts","areas","agreement_areas","form","formInfo","agreement_form","console","log","description","shi_description","supplier_information","RetrieveFormattedData","filteredList","supplier","mailToString","test","open","generateMailList","sort","b","ReactDOM","document","getElementById"],"mappings":"+LA2DeA,MAtCf,SAAyBC,GAAe,IAAD,E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ACI,wBAAQA,UAAW,MAAOuC,QAAS,kBArC/C+F,EAAkB,CAAEzH,KAAM,mBAAoBE,QAAS,KACvDuH,EAAkB,CAAEzH,KAAM,qBAAsBE,QAAS,KACzDyH,EAAgB,CAAE3H,KAAM,aAAcE,QAAS,UAC/C2H,EAAa,CAAE7H,KAAM,aAAcE,QAAS,MAkCsBT,SAAW4H,EAAjE,gCAGa,KAAlBO,GAA6C,KAArBF,EAA2B,GAClD,0BAASvI,UAAW,gBAApB,UACI,sBAAKA,UAAW,gBAAhB,UACI,yEACEwJ,GAAgBA,EAAatD,OAAS,EACpC,wBAAQlG,UAAW,MAAOuC,QAAS,kBAtC3D,SAA0B8B,GACtB,IAAIqF,EAAuB,UAClB,OAATrF,QAAS,IAATA,KAAWhB,SAAQ,SAACoG,GAIZ,uEAAuEE,KAAKF,EAASnI,SACzFoI,EAAeA,EAAeD,EAASnI,MAAQ,QAGnDgF,OAAOsD,KAAKF,GA4BiDG,CAAiBL,IAA1D,6BACyB,MAGjC,qBAAKxJ,UAAW,cAEfwJ,GAAgBA,EAAatD,OAAS,EAAtC,OACOsD,QADP,IACOA,OADP,EACOA,EAAcM,MAAK,SAACxC,EAAEyC,GAAH,OAAUzC,EAAElG,SAAW2I,EAAE3I,YAAWzB,KAAI,SAAC8J,GAAD,OACvD,cAAC,EAAD,CAAqCtI,YAAasI,GAA1BA,EAAS3J,OACrC,2EAKX,6DEtIjBkK,SACE,cAAC,aAAD,UACE,cAAC,EAAD,MAEFC,SAASC,eAAe,W","file":"static/js/main.7f9eff39.chunk.js","sourcesContent":["import * as React from \"react\";\r\nimport {IFormattedAccount, IFormattedArea, IFormattedParentAccount} from \"../interfaces/IFormatted\";\r\nimport {Dispatch, useEffect, useRef} from \"react\";\r\nimport {Action} from \"../interfaces/utilInterfaces\";\r\n\r\n\r\ntype Options = (IFormattedAccount[] | undefined) | (IFormattedArea[] | undefined) | (IFormattedParentAccount[] | undefined);\r\n\r\ntype Props = {\r\n options: Options;\r\n selectTitle: string,\r\n placeholderText : string,\r\n dispatch: Dispatch\r\n loading: boolean,\r\n disabled: boolean ,\r\n dispatchType: string,\r\n selectValue : string ,\r\n};\r\n\r\n\r\n\r\nfunction SelectComponent(props: Props) {\r\n\r\n const thisRef = useRef(null)\r\n\r\n function handleOnChange(e: React.FormEvent) {\r\n //selectValue is the GUID of the object\r\n const selectedValue :string = e.currentTarget.value;\r\n props.dispatch({ type: props.dispatchType, payload: selectedValue });\r\n\r\n }\r\n\r\n /*With the \"props.options\" as a dependency, this useEffect hook will fire whenever there is a change in the data, such as when the user changes the parent account, the data in the select options changes because of the parent.\r\n * Explaining this specific case further: When parent account select is changed, it doesnt fire the onChangeEvent on the account select element. Therefore we have to \"watch\" for any changes in the account list, whenever that\r\n * changes it programmatically fires the onChange event, dispatching the action in the reducer, and thus changing the list of the suppliers.\r\n * */\r\n\r\n useEffect(() => {\r\n const ev2 = new Event('change', { bubbles: true});\r\n thisRef.current?.dispatchEvent(ev2);\r\n },[props.options])\r\n\r\n\r\n const listItems = (props.options as Array)?.map((listElem ) =>\r\n \r\n )\r\n\r\n return (\r\n
\r\n \r\n \r\n
\r\n );\r\n};\r\n\r\n\r\nexport default SelectComponent;\r\n","export default __webpack_public_path__ + \"static/media/arrow_down.025b0ec3.svg\";","import * as React from \"react\";\r\nimport {MutableRefObject, useState, useRef, useEffect} from \"react\";\r\nimport arrow from \"../img/arrow_down.svg\"\r\nimport {IFormattedSupplierInfo} from \"../interfaces/IFormatted\";\r\n\r\ninterface SupplierProps {\r\n supplierObj: IFormattedSupplierInfo,\r\n}\r\nconst SupplierComponent = ( { supplierObj} : SupplierProps ) => {\r\n const {priority , name, phone, email} = supplierObj;\r\n\r\n const [expansionAnimStarted, setExpansionAnimStarted] = useState(true);\r\n const [isAnimRunning, setIsAnimRunning] = useState(false);\r\n const [isExpanded, setExpanded] = useState(false);\r\n const [contentHeight, setContentHeight] = useState(-1);\r\n const [currentContentHeight, setCurrentContentHeight] = useState(-1);\r\n const contentRef = useRef() as MutableRefObject;\r\n\r\n const animTime = 150;\r\n //useEffect runs before the components are mounted and rendered\r\n useEffect(() => {\r\n if(contentRef.current) {\r\n /*Since the expansionAnimStarted state is 'true', we can cache the absolute value of the height of the html element before its shown*/\r\n setContentHeight(contentRef.current.getBoundingClientRect().height);\r\n /*Quickly, after caching the height, we remove set the expansionAnimStarted to false to remove the content inside from the DOM\r\n Removal of non-visible HTML is better for accessibility */\r\n setExpansionAnimStarted(false);\r\n }\r\n }, [contentRef, contentHeight]);\r\n\r\n return (\r\n
\r\n \r\n {expansionAnimStarted &&\r\n //TODO: Rewrite into for accessibility purposes\r\n
-1 ? {height: + currentContentHeight + \"px\"} as React.CSSProperties : {}} >\r\n\r\n
\r\n

E-post:

\r\n

{email}

\r\n
\r\n
\r\n

Telefon:

\r\n

{phone}

\r\n
\r\n\r\n
}\r\n \r\n );\r\n\r\n function changeExpandState() {\r\n //We have to ensure that the user can only collapse/expand only when the animation is NOT running.\r\n if(isAnimRunning) return;\r\n if(!isExpanded) {\r\n expandAnimation()\r\n } else {\r\n collapseAnimation()\r\n }\r\n }\r\n\r\n function expandAnimation() {\r\n\r\n //Setting the state for starting the expand animation, set height to 0 after a short short time\r\n setTimeout(() => {\r\n setExpansionAnimStarted(true);\r\n setCurrentContentHeight(0);\r\n }, 10);\r\n\r\n //Since the height has already been set to 0, we then set a new height, using the cached value in the hook state, triggering the css transition we want\r\n setTimeout(() => {\r\n setIsAnimRunning(true)\r\n setCurrentContentHeight(contentHeight);\r\n\r\n }, 20);\r\n\r\n //After some milliseconds, sets the component state to expanded\r\n //Note: If changing animation, remember to set the timeout milliseconds the same as the transition-property in .content-class\r\n setTimeout(() => {\r\n setIsAnimRunning(false)\r\n setExpanded(true);\r\n }, animTime);\r\n }\r\n\r\n function collapseAnimation() {\r\n setExpanded(false);\r\n setIsAnimRunning(true)\r\n setCurrentContentHeight(0);\r\n // contentRef.current.style = \"height: 0;\";\r\n setTimeout(() => {\r\n setIsAnimRunning(false)\r\n setExpansionAnimStarted(false);\r\n }, animTime);\r\n\r\n\r\n }\r\n};\r\n\r\n\r\nexport default SupplierComponent;\r\n","import {IDataAccount, IDataArea, IDataFormInfo, IDataSupplierInfo} from \"../interfaces/IData\";\r\nimport {\r\n IFormattedAccount,\r\n IFormattedArea,\r\n IFormattedFormInfo, IFormattedParentAccount,\r\n IFormattedSupplierInfo\r\n} from \"../interfaces/IFormatted\";\r\n\r\n/*\r\n* File for mapping data from request over to\r\n*\r\n*\r\n* */\r\n\r\n//Takes in and IDataFormInfo object and returns an IFormattedFormInfo\r\nfunction formatFormInfo(formInfo : IDataFormInfo | undefined): IFormattedFormInfo {\r\n console.log(formInfo);\r\n\r\n return{\r\n name: formInfo?.shi_name,\r\n id : \"1\",\r\n description: formInfo?.shi_description\r\n } as IFormattedFormInfo;\r\n}\r\n\r\nconst noParentOtherGuid = \"0a0000b0-abc0-ab00-a000-000abcdefghi\";\r\nfunction parentCheckQualifier(dataAcc : IDataAccount) {\r\n if (!dataAcc.shi_account.parentaccountid\r\n || dataAcc.shi_account.parentaccountid.accountid === undefined\r\n || dataAcc.shi_account.parentaccountid.accountid === \"\"\r\n /*insert more null qualifiers if need*/) {\r\n return false;\r\n } else {\r\n return true\r\n }\r\n}\r\n\r\n/*Takes in an array with IDataAaccount interface, returns a new array with the IFormattedAccount*/\r\nfunction formatAccounts(accounts : IDataAccount[] | undefined) {\r\n let newAccountList : IFormattedAccount[]= [];\r\n accounts?.forEach((acc) => {\r\n const id = acc.shi_account.accountid;\r\n const name = acc.shi_account.name;\r\n let parentId;\r\n /*If parent somehow doesnt exist, insert pre-defined gui for the account to go in to the \"other\"-group*/\r\n if (parentCheckQualifier(acc)) {\r\n parentId = acc.shi_account.parentaccountid.accountid;\r\n } else {\r\n parentId = noParentOtherGuid;\r\n }\r\n const newAccount : IFormattedAccount = {id: id, name: name, parentId : parentId}\r\n newAccountList.push(newAccount);\r\n })\r\n return newAccountList;\r\n}\r\n\r\n/*Takes in an array with IDataArea interface, returns a new array with the IFormattedArea*/\r\nfunction formatAreas(accounts : IDataArea[] | undefined) {\r\n let newAreaList :IFormattedArea[]= [];\r\n accounts?.forEach((acc) => {\r\n const id = acc.shi_agreement_request_form_areaid;\r\n const name = acc.shi_name;\r\n\r\n const newArea : IFormattedArea = {id: id, name: name}\r\n newAreaList.push(newArea);\r\n })\r\n return newAreaList;\r\n}\r\n\r\nfunction formatSupplier(suppliers : IDataSupplierInfo[] | undefined) {\r\n let newSuppliers : IFormattedSupplierInfo[] = [];\r\n\r\n suppliers?.forEach((supp) => {\r\n const newSupplier : IFormattedSupplierInfo = {\r\n id : supp.shi_supplier.accountid,\r\n name : supp.shi_supplier.name,\r\n email : supp.shi_supplier_email,\r\n phone : supp.shi_supplier_phone,\r\n priority : supp.shi_priority,\r\n areaId : supp.shi_Delomrade.shi_agreement_request_form_areaid,\r\n accountId : supp.shi_Request_Form_Account.shi_account.accountid\r\n }\r\n newSuppliers.push(newSupplier);\r\n })\r\n return newSuppliers;\r\n}\r\n\r\n/*Takes in and IDataAccount array, builds a new array with objects of IFormattedAccound\r\n* This array is then used to filter out single instances of the parentAccount and finally returns individual occurences of the parent accounts\r\n* */\r\nfunction generateParentAccounts(accounts : IDataAccount[] | undefined) {\r\n let newParentAccountList : IFormattedParentAccount[]= [];\r\n const subAccounts : IFormattedAccount[] = [];\r\n\r\n accounts?.forEach((acc) => {\r\n let id: string;\r\n let name: string;\r\n \r\n if(acc.shi_account.parentaccountid != null) {\r\n id = acc.shi_account.parentaccountid.accountid;\r\n name = acc.shi_account.parentaccountid.name;\r\n }else{\r\n id = \"0a0000b0-abc0-ab00-a000-000abcdefghi\";\r\n name = \"Annet\"\r\n }\r\n\r\n\r\n\r\n const newAccount : IFormattedParentAccount = {id: id, name: name, subAccounts : subAccounts}\r\n newParentAccountList.push(newAccount);\r\n })\r\n /* Create a parent account for orphan accounts with no parent*/\r\n const otherAccount : IFormattedParentAccount = {id: noParentOtherGuid, name: \"Annet\", subAccounts : subAccounts}\r\n newParentAccountList.push(otherAccount);\r\n\r\n return newParentAccountList.filter((id, index) => {\r\n const _id = JSON.stringify(id);\r\n return index === newParentAccountList.findIndex(obj => {\r\n return JSON.stringify(obj) === _id;\r\n });\r\n });\r\n}\r\n\r\n/*\r\n *Takes in a formatted account list and a generated and formatted list of parent accounts. Creates a copy of the parent list and iterates through each parent\r\n * and compares the parent id with the parentid present in the subaccount. If true, push the subaccount in to the list of subaccounts, when finished iterating\r\n * on one parent, it then sets the sist of subccounts to the parent.\r\n * When finished we check if the \"Other\" group is empy or not, if empty, we dont need it at all, so we remove it.\r\n * In the end we return a parentlist account that has all subaccounts in it\r\n * */\r\nfunction populateParentAccounts(accountList : IFormattedAccount[] | undefined, parentAccountList : IFormattedParentAccount[]) {\r\n const newParentAccountList : IFormattedParentAccount[] = parentAccountList\r\n\r\n newParentAccountList?.forEach((parent => {\r\n const newSubAccounts : IFormattedAccount[] = [];\r\n accountList?.forEach((account => {\r\n if(account.parentId === parent.id || account.id === parent.id) {\r\n newSubAccounts.push(account)\r\n }\r\n }))\r\n parent.subAccounts = newSubAccounts;\r\n }))\r\n /* Since \"Other\" parent is ALWAYS last in list, we can check the length of it after the account populating is finished\r\n * if its empty, we pop it from the parentaccountlist */\r\n if(newParentAccountList[newParentAccountList.length-1].subAccounts.length === 0) {\r\n newParentAccountList.pop()\r\n }\r\n return newParentAccountList;\r\n}\r\n\r\n\r\nexport { formatAccounts, formatAreas, formatFormInfo, formatSupplier, generateParentAccounts, populateParentAccounts };\r\n","import * as React from \"react\";\r\nimport SelectComponent from \"./components/SelectComponent\";\r\nimport SupplierComponent from \"./components/SupplierComponent\";\r\nimport {\r\n formatAccounts,\r\n formatAreas,\r\n formatFormInfo,\r\n formatSupplier,\r\n generateParentAccounts, populateParentAccounts\r\n} from \"./util/dataRetriever\";\r\nimport { useEffect, useReducer, useState} from \"react\";\r\nimport {IFormattedParentAccount, IFormattedRequest, IFormattedSupplierInfo} from \"./interfaces/IFormatted\";\r\nimport {useFetch} from \"./hooks/hooks\";\r\nimport {Action} from \"./interfaces/utilInterfaces\";\r\nimport {IDataRequest} from \"./interfaces/IData\";\r\n\r\nfunction App() {\r\n\r\n //TODO: put these urls somewhere else, .env perhaps?\r\n const baseUrl = \"https://shiexternal.blob.core.windows.net/$web/\";\r\n\r\n const queryString = window.location.search;\r\n const searchParams = new URLSearchParams(queryString);\r\n const jsonGUID = searchParams.get(\"guid\");\r\n\r\n const prodUrl = baseUrl + jsonGUID + \".json\"\r\n const [formattedData, setFormattedData] = useState();\r\n const [currentParentAccObj, setCurrentParentAccObj] = useState();\r\n const [data, isLoading, responseOk] = useFetch(prodUrl);\r\n const [currentParentAccId, parentAccDispatch] = useReducer(reducer, \"\");\r\n const [currentAccountId, accountDispatch] = useReducer(reducer, \"\");\r\n const [currentAreaId, areaDispatch] = useReducer(reducer, \"\");\r\n\r\n useEffect(() => {\r\n function RetrieveFormattedData() {\r\n if(!isLoading) {\r\n const formattedData : IFormattedRequest= {\r\n accounts : formatAccounts(data?.accounts),\r\n areas : formatAreas((data?.agreement_areas)),\r\n form : formatFormInfo(data?.agreement_form),\r\n suppliers : formatSupplier(data?.supplier_information),\r\n parentAccounts : populateParentAccounts(formatAccounts(data?.accounts), generateParentAccounts(data?.accounts))\r\n }\r\n setFormattedData(formattedData)\r\n console.log(formattedData)\r\n }\r\n }\r\n RetrieveFormattedData()\r\n },[data, isLoading])\r\n\r\n /* the var \"id\" is the selected option in the selectComponent, id of the object, and is routed to the specific action type*/\r\n function reducer(id: string, action : Action) {\r\n switch (action.type) {\r\n case \"setPayload\":\r\n /*Account selectComponent and Area selectComponent uses different dispatches, but same disptachTypes\r\n * This means that they execute the same code but they pertain to their respective states: currentAccount and currentArea\r\n * */\r\n id = action.payload;\r\n return id;\r\n\r\n case \"setParentPayload\":\r\n id = action.payload;\r\n formattedData?.parentAccounts.forEach((parent) => {\r\n if(parent.id === id) {\r\n setCurrentParentAccObj(parent)\r\n }\r\n })\r\n return id;\r\n //Used only for clearing the selected parent object\r\n case \"emptyParentPayload\":\r\n setCurrentParentAccObj(undefined)\r\n return id;\r\n\r\n default:\r\n return id\r\n }\r\n }\r\n\r\n /*Empties the form by setting the values of the select to the defaultValue of \"\", and an own action for clearing the current parent obj*/\r\n function emptyForm() {\r\n parentAccDispatch({ type: \"setParentPayload\", payload: \"\" });\r\n parentAccDispatch({ type: \"emptyParentPayload\", payload: \"\"});\r\n accountDispatch({ type: \"setPayload\", payload: \"\"} );\r\n areaDispatch({ type: \"setPayload\", payload: \"\"});\r\n\r\n }\r\n\r\n function generateMailList(suppliers : IFormattedSupplierInfo[] | undefined) {\r\n let mailToString: string = \"mailto:\";\r\n suppliers?.forEach((supplier) => {\r\n /*Behold, the magic of regex*/\r\n /* Spoiler alert: its from the internet, for a description of what it actually does, see here: https://www.w3resource.com/javascript/form/email-validation.php\r\n * */\r\n if (/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$/.test(supplier.email)){\r\n mailToString = mailToString + supplier.email + \";\"\r\n }\r\n })\r\n window.open(mailToString)\r\n }\r\n\r\n //TODO: Only for testing as the data doesnt have that many suppliers in each region\r\n //let filteredList = formattedData?.suppliers.filter((supplier) => supplier.accountId === currentAccountId);\r\n let filteredList = formattedData?.suppliers.filter((supplier) => supplier.accountId === currentAccountId && supplier.areaId === currentAreaId);\r\n return (\r\n
\r\n { responseOk ?\r\n <>\r\n
\r\n

{ (isLoading ? \"Laster data...\" : formattedData?.form.name)}

\r\n

{isLoading ? \"\" : formattedData?.form.description}

\r\n \r\n\r\n \r\n \r\n\r\n
\r\n \r\n
\r\n
\r\n { (currentAreaId === \"\" || currentAccountId === \"\") ? \"\" :\r\n
\r\n
\r\n

Leverandører i rangert rekkefølge

\r\n { filteredList && filteredList.length > 0 ?\r\n : \"\"}\r\n
\r\n\r\n
\r\n\r\n {filteredList && filteredList.length > 0 ?\r\n filteredList?.sort((a,b) => (a.priority - b.priority)).map((supplier) =>\r\n ) :\r\n

Ingen leverandører i denne listen

\r\n }\r\n\r\n\r\n
}\r\n :

404 - Finner ikke skjema

}\r\n
\r\n );\r\n}\r\n\r\nexport default App;\r\n","import { useState, useEffect } from \"react\";\r\n\r\n/*Generic custom hook for fetching data. Can technically be used with any type.*/\r\nfunction useFetch(url: string) {\r\n const [data, setData] = useState();\r\n const [loading, setLoading,] = useState(true);\r\n const [responseOk, setResponseOk,] = useState(true);\r\n type GenericBooleanTuple = [T | undefined, boolean, boolean]\r\n\r\n useEffect(() => {\r\n async function fetchUrl() {\r\n let requestHesders = new Headers();\r\n requestHesders.append(\"Content-Type\", \"application/json\");\r\n //add no-cache header\r\n requestHesders.append(\"Cache-Control\", \"no-cache\");\r\n const response = await fetch(url, {method: \"GET\" , headers: requestHesders});\r\n if (response.ok) {\r\n const json = await response.json();\r\n setData(json);\r\n setLoading(false);\r\n } else {\r\n setResponseOk(false)\r\n }\r\n }\r\n fetchUrl();\r\n }, [url]);\r\n\r\n const genericResult: GenericBooleanTuple = [data, loading, responseOk]\r\n\r\n return genericResult;\r\n}\r\n\r\nexport { useFetch };\r\n","import * as React from 'react';\r\nimport * as ReactDOM from 'react-dom';\r\nimport './style/css/index.css';\r\nimport App from './App';\r\n\r\nReactDOM.render(\r\n \r\n \r\n ,\r\n document.getElementById('root')\r\n);\r\n\r\n// If you want to start measuring performance in your app, pass a function\r\n// to log results (for example: reportWebVitals(console.log))\r\n// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals\r\n"],"sourceRoot":""}