@australiangreens/ag-internal-components 0.3.19 → 0.3.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +112 -108
- package/dist/esm/index.js.map +1 -1
- package/dist/layouts/AppLayout/AppLayout.d.ts +3 -1
- package/dist/layouts/AppLayout/AppLayout.d.ts.map +1 -1
- package/dist/layouts/AppLayout/TopBar.d.ts +3 -1
- package/dist/layouts/AppLayout/TopBar.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var We=Object.defineProperty,ze=Object.defineProperties;var Ve=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,de=Object.prototype.propertyIsEnumerable;var Z=(e,t,n)=>t in e?We(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,u=(e,t)=>{for(var n in t||(t={}))ce.call(t,n)&&Z(e,n,t[n]);if(K)for(var n of K(t))de.call(t,n)&&Z(e,n,t[n]);return e},E=(e,t)=>ze(e,Ve(t));var ue=(e,t)=>{var n={};for(var i in e)ce.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(e!=null&&K)for(var i of K(e))t.indexOf(i)<0&&de.call(e,i)&&(n[i]=e[i]);return n};var pe=(e,t,n)=>Z(e,typeof t!="symbol"?t+"":t,n);var I=(e,t,n)=>new Promise((i,s)=>{var l=c=>{try{a(n.next(c))}catch(d){s(d)}},p=c=>{try{a(n.throw(c))}catch(d){s(d)}},a=c=>c.done?i(c.value):Promise.resolve(c.value).then(l,p);a((n=n.apply(e,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),w=require("react"),r=require("@mui/material"),ee=require("@mui/icons-material"),De=require("@tanstack/react-query"),Ge=require("autosuggest-highlight/match"),Xe=require("autosuggest-highlight/parse"),oe=require("@auth0/auth0-react"),Ke=require("buffer"),Qe=require("@mui/material/Skeleton"),D=require("jotai"),Ye=require("souvlaki"),Je=require("@mui/material/CssBaseline"),Ze=require("@mui/material/Box"),et=require("jotai/utils"),L=require("@mui/material/styles"),tt=require("react-avatar"),U=e=>e&&e.__esModule?e:{default:e},ot=U(Ge),nt=U(Xe),it=U(Qe),rt=U(Je),he=U(Ze),fe=U(tt);function st({text:e}){const[t,n]=w.useState(0);return o.jsxs(o.Fragment,{children:[o.jsx(r.Typography,{variant:"h6",color:"inherit",component:"div",sx:{fontSize:"22px"},children:"Hello world"}),o.jsx(r.Typography,{variant:"caption",display:"block",children:o.jsx("span",{children:"Just ensuring MUI is working as planned as a peer dependency. v0.0.11"})}),o.jsx(r.Button,{variant:"outlined",onClick:()=>n(i=>i+1),"aria-label":"Increment",children:"Hello I am a button"}),o.jsxs("p",{children:["This is some text: ",o.jsx("span",{children:e})]}),o.jsxs(r.Paper,{children:["This number will incremember when button pressed: ",t]})]})}const ne=({isOpen:e,dialogTitle:t,children:n,maxWidth:i,primaryButton:s,secondaryButton:l,additionalButtons:p,onClose:a,sx:c,"data-testid":d,disableCloseOnBackdropOrEscape:g=!1,isLoading:A=!1})=>{var S,k;const[v,x]=w.useState(!1);return o.jsxs(r.Dialog,{open:e,onClose:(f,F)=>I(null,null,function*(){g&&(F==="backdropClick"||F==="escapeKeyDown")||v||(l!=null&&l.onClick?yield l.onClick():a())}),fullWidth:!0,maxWidth:i!=null?i:"xs","data-testid":d,sx:c,children:[A&&o.jsx(r.LinearProgress,{sx:{height:"4px",marginBottom:"-4px"}}),o.jsx(r.DialogTitle,{children:t}),o.jsx(r.DialogContent,{sx:{"& > :last-child":{marginBottom:0}},children:n}),o.jsxs(r.DialogActions,{children:[o.jsx(r.Button,{onClick:(S=l==null?void 0:l.onClick)!=null?S:a,"data-testid":l==null?void 0:l.testId,disabled:(l==null?void 0:l.disabled)||v,color:l==null?void 0:l.buttonColor,children:(k=l==null?void 0:l.text)!=null?k:"Cancel"}),p&&p.map((f,F)=>{var _;return o.jsx(r.Button,{onClick:f==null?void 0:f.onClick,"data-testid":f==null?void 0:f.testId,disabled:(f==null?void 0:f.disabled)||v,color:f==null?void 0:f.buttonColor,children:(_=f.text)!=null?_:`Button ${F}`},F)}),s&&o.jsx(r.Button,{onClick:()=>I(null,null,function*(){var f;x(!0),yield(f=s.onClick)==null?void 0:f.call(s),x(!1)}),"data-testid":s.testId,disabled:s.disabled||v,color:s==null?void 0:s.buttonColor,children:s.text})]})]})},at={popper:{modifiers:[{name:"offset",options:{offset:[115,-15]}}]}},we={right:2},ie=({minLength:e,preLoadedOptions:t,lookup:n,label:i,inputValue:s})=>De.useQuery({queryFn:()=>e&&s.length<e?t!=null?t:[]:t?t.filter(l=>l.label.toLowerCase().includes(s.toLowerCase())):n(s),queryKey:["autocomplete",i,s]});function lt({lookup:e=()=>I(null,null,function*(){}),enableHighlighting:t=!0,onChange:n,onInputChange:i,minLength:s=0,label:l,value:p,"data-testid":a,sx:c,boxSx:d,textFieldColor:g,textFieldVariant:A="filled",textFieldFocused:v,textFieldSx:x,loadingText:S="Loading...",noOptionsText:k="No options",popupIcon:f=o.jsx(ee.ArrowDropDown,{}),error:F=!1,helperText:_="",preLoadedOptions:P=void 0,disablePortal:H=!1,disableIconFlip:W=!1,chipToolTipSlotProps:b=at,placeholderText:M=void 0,onRightClick:z=()=>{},disableDefaultRightClickBehaviour:O=!1,readOnly:N,hideInputEndAdornment:j}){const[C,$]=w.useState(""),X=(h,y)=>{const B=p.filter(J=>J.id!==y);n(B,"delete",h)},{data:m,isLoading:T}=ie({inputValue:C,label:l,lookup:e,minLength:s,preLoadedOptions:P}),R=C.length>=s;return o.jsxs("div",{"data-testid":a,children:[o.jsx(r.Autocomplete,{sx:u(u({},c),W?{".MuiAutocomplete-popupIndicatorOpen":{transform:"rotate(0deg)"}}:{}),"data-testid":a?`${a}:Autocomplete`:void 0,disablePortal:H,multiple:!0,getOptionLabel:h=>typeof h=="string"?h:h.label,loading:R?T:!1,options:[...p,...m!=null?m:[]],filterSelectedOptions:!0,includeInputInList:!0,value:p,onChange:(h,y,B)=>{n(y,B,h)},onInputChange:(h,y,B)=>{$(y),i&&i(p,B,h)},noOptionsText:R?k:"Start typing to search",loadingText:S,popupIcon:f,renderInput:h=>o.jsx(r.TextField,E(u({},h),{label:l,fullWidth:!0,variant:A,error:F,helperText:_,autoComplete:"off",slotProps:{input:E(u({},h.InputProps),{endAdornment:j?void 0:o.jsxs(o.Fragment,{children:[T?o.jsx(r.CircularProgress,{color:"inherit",size:20}):null,h.InputProps.endAdornment]})})},"data-testid":a?`${a}:Autocomplete:TextField`:void 0,onKeyDown:y=>{(y.key==="Backspace"||y.key==="Delete")&&y.stopPropagation()},color:g,placeholder:M,sx:x,focused:v})),renderValue:()=>null,isOptionEqualToValue:(h,y)=>h.id===y.id,renderOption:(h,y,B)=>{if(t){const J=ot.default(y.label,B.inputValue,{insideWords:!0,findAllOccurrences:!0}),Ue=nt.default(y.label,J);return w.createElement("li",E(u({},h),{key:y.id,"data-testid":a?`${a}:Autocomplete:option(${y.id.toString()})`:void 0}),o.jsx("div",{children:Ue.map((le,He)=>o.jsx("span",{style:{fontWeight:le.highlight?700:400},children:le.text},He))}))}else return w.createElement("li",E(u({},h),{key:y.id,"data-testid":a?`${a}:option(${y.id.toString()})`:void 0}),y.label)},onMouseDownCapture:h=>{h.button===we.right&&O&&(h.preventDefault(),h.stopPropagation())},onContextMenuCapture:h=>{O&&(h.preventDefault(),h.stopPropagation()),z(h)},readOnly:N}),p.length>0&&o.jsx(r.Box,{sx:d,children:p.map(h=>{var y;return o.jsx(r.Chip,{sx:{marginTop:1,marginRight:1,height:"auto"},label:o.jsx(r.Tooltip,{title:(y=h.tooltipContent)!=null?y:"",placement:"bottom-start",slotProps:b,children:o.jsx(r.Typography,{style:{whiteSpace:"normal"},children:h.chipLabel?h.chipLabel:h.label})}),"data-testid":a?`${a}:Chip(${h.id.toString()})`:void 0,onDelete:B=>X(B,h.id),deleteIcon:o.jsx(ee.Cancel,{"data-testid":a?`${a}:Chip(${h.id.toString()}):deleteIcon`:void 0})},h.id)})})]})}const ct=/MUI: The value provided to.*is invalid/i,dt=({lookup:e=()=>I(null,null,function*(){}),onChange:t,onInputChange:n,label:i,value:s,sx:l,textFieldColor:p,textFieldVariant:a="filled",textFieldFocused:c,textFieldSx:d,error:g=!1,"data-testid":A,loadingText:v="Loading...",noOptionsText:x="No options",minLength:S=3,disablePortal:k=!1,preLoadedOptions:f,helperText:F="",disabled:_,popupIcon:P,disableIconFlip:H,placeholderText:W=void 0,onRightClick:b=()=>{},disableDefaultRightClickBehaviour:M=!1,readOnly:z,hideInputEndAdornment:O})=>{const[N,j]=w.useState(""),{data:C,isLoading:$}=ie({inputValue:N,label:i,lookup:e,minLength:S!=null?S:0,preLoadedOptions:f}),X=N.length>=S;return o.jsx("div",{"data-testid":A,children:o.jsx(r.Stack,{direction:"row",spacing:1,onMouseDownCapture:m=>{m.button===we.right&&M&&(m.preventDefault(),m.stopPropagation())},onContextMenuCapture:m=>{M&&(m.preventDefault(),m.stopPropagation()),b(m)},children:o.jsx(r.Autocomplete,{sx:u(u({},l),H?{".MuiAutocomplete-popupIndicatorOpen":{transform:"rotate(0deg)"}}:{}),"data-testid":A?`${A}:Autocomplete`:void 0,loading:X?$:!1,options:C!=null?C:[],onChange:(m,T,R)=>{t(m,T,R)},disablePortal:k,filterOptions:m=>m,value:s,noOptionsText:X?x:"Start typing to search",loadingText:v,getOptionLabel:m=>m.label,popupIcon:P,renderInput:m=>o.jsx(r.TextField,E(u({"data-testid":A?`${A}:Autocomplete:TextField`:void 0},m),{variant:a,label:i,color:p,error:g,helperText:F,autoComplete:"off",slotProps:{input:E(u({},m.InputProps),{endAdornment:O?void 0:o.jsxs(o.Fragment,{children:[$?o.jsx(r.CircularProgress,{color:"inherit",size:20}):null,m.InputProps.endAdornment]})})},placeholder:W,sx:d,focused:c})),isOptionEqualToValue:(m,T)=>m.id===T.id,onInputChange:(m,T,R)=>{j(T),n&&n(T,R,m)},renderOption:(m,T)=>w.createElement("li",E(u({},m),{key:T.id,"data-testid":A?`${A}:Autocomplete:option(${T.id.toString()})`:void 0}),T.label),disabled:_,readOnly:z})})})},Fe=e=>{if(!e)return-1;try{const n=e.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),i=decodeURIComponent(Ke.Buffer.from(n,"base64").toString("utf8").split("").map(function(l){return"%"+("00"+l.charCodeAt(0).toString(16)).slice(-2)}).join("")),s=JSON.parse(i);return s!=null&&s.exp?s.exp:-1}catch(t){return-1}},ut=({open:e=!1,closeHandler:t,setAuth0ExpiryTime:n})=>{const{logout:i,getAccessTokenSilently:s}=oe.useAuth0(),l=()=>I(null,null,function*(){i({logoutParams:{returnTo:`${window.location.origin}`}})}),a={text:"Continue",onClick:()=>I(null,null,function*(){const d=yield s({cacheMode:"off"}),g=Fe(d)*1e3;n(g),t()}),disabled:!1,testId:"PreferencesDialog",buttonColor:"secondary"},c={text:"Log out",onClick:l,disabled:!1,testId:"PreferencesDialog",buttonColor:"secondary"};return o.jsx(ne,{isOpen:e,primaryButton:a,secondaryButton:c,onClose:t,dialogTitle:"Session expiry",disableCloseOnBackdropOrEscape:!0,children:o.jsx("p",{style:{marginBottom:0},children:"Your session is about to time out due to inactivity. Do you want to continue?"})})};function pt(e){return"error"in e}function ht(e){var i;const t=e.error,n=(i=e==null?void 0:e.error_description)!=null?i:"";return t==="access_denied"&&n.startsWith("You do not have the required authorization")}function ft(e){var i;const t=e.error,n=(i=e==null?void 0:e.error_description)!=null?i:"";return t==="access_denied"&&n.startsWith("User did not authorize the request")}function mt(e){var i;const t=e.error,n=(i=e==null?void 0:e.error_description)!=null?i:"";return t==="access_denied"&&n.match(/Script.*time.*exceeded/)}function xt({children:e,appName:t="the app",throwErrors:n="none",disableConsoleLogging:i=!1,onError:s=()=>{}}){var A,v;const{isAuthenticated:l,isLoading:p,error:a,loginWithRedirect:c,logout:d}=oe.useAuth0();w.useEffect(()=>{a&&s(a)},[a,s]);const g=w.useMemo(()=>({appState:{returnTo:`${window.location.pathname}${window.location.search}`}}),[]);if(w.useEffect(()=>{p||l||a||c(g)},[p,l,a,c,s,g]),a){if(i||console.error(`Error detected in AuthGuard [isAuthenticated=${l},isLoading=${p}]`,a),n==="all")throw a;if(pt(a)){let x="Auth error",S="An unknown Auth0 error occurred.";if(ht(a))x="Unauthorised",S=`You are not authorised to access ${t}.`;else if(ft(a))x="App not authorised",S=`You have not authorised ${t} to access your user profile. This is necessary to use ${t}.`;else if(mt(a))x="Auth0 script execution time exceeded",S="The Auth0 login flow exceeded the time limit (20s). Try again in a minute by clicking the RELOAD button below.";else if(a.message==="Invalid state"){const k=localStorage.getItem("auth0_redirect_count");k?k&&parseInt(k)<2&&(localStorage.setItem("auth0_redirect_count",String(parseInt(k)+1)),c(g)):(localStorage.setItem("auth0_redirect_count","1"),c(g))}else if(n==="unknown")throw a;return o.jsxs(r.Dialog,{open:!0,children:[o.jsx(r.DialogTitle,{children:x}),o.jsxs(r.DialogContent,{children:[o.jsx(r.Typography,{children:S}),o.jsx("br",{}),o.jsx(r.Typography,{variant:"subtitle2",children:"Details from Auth0"}),o.jsxs(r.Typography,{variant:"body2",children:["error: ",(A=a==null?void 0:a.error)!=null?A:"N/A"]}),o.jsxs(r.Typography,{variant:"body2",children:["description: ",(v=a==null?void 0:a.error_description)!=null?v:"N/A"]})]}),o.jsxs(r.DialogActions,{children:[x==="Auth0 script execution time exceeded"&&o.jsx(r.Button,{href:window.location.origin+window.location.pathname,children:"Reload"}),o.jsx(r.Button,{onClick:()=>d({logoutParams:{returnTo:window.location.origin}}),children:"Logout"})]})]})}else if(n==="unknown")throw a}return l?(localStorage.removeItem("auth0_redirect_count"),o.jsx(o.Fragment,{children:e})):o.jsx(it.default,{variant:"rectangular",animation:"pulse",height:"100vh",width:"100vw"})}const gt={autoHideDuration:6e3,anchorOrigin:{vertical:"top",horizontal:"center"},disableWindowBlurListener:!1},At={shouldClose:(e,t)=>t!=="clickaway"},me={message:"",severity:"info",variant:"standard",progressIndicator:void 0},xe=100,ge=2e3,Ct=2e3,St=(()=>{let e=0;return()=>(e+=1,e)})(),yt={borderBottomLeftRadius:"0px",borderBottomRightRadius:"0px"},jt={},vt={},re=w.createContext(null);function ke(l){var p=l,{overrideState:e=jt,overrideActions:t=vt,shouldClose:n=At.shouldClose,children:i}=p,s=ue(p,["overrideState","overrideActions","shouldClose","children"]);var N;const[{open:a},c]=w.useState({open:!1}),d=w.useRef([]),g=w.useRef(Date.now()),A=w.useRef(0),v=w.useCallback(j=>{c({open:j})},[]),x=w.useCallback((j={})=>{A.current+=1,d.current.length>=xe&&Date.now()-g.current>=ge&&(g.current=Date.now(),console.error(`SaladBarProvider: MAX_QUEUE_LENGTH (${xe}) hit ${A.current} times in last ${ge}ms)`),A.current=0);const C=u(E(u({},me),{key:St()}),j);return d.current.push(C),d.current.length===1&&c({open:!0}),C.key},[]),S=(j="",C={})=>x(u({message:j,severity:"success"},C)),k=(j="",C={})=>x(u({message:j,severity:"info"},C)),f=(j="",C={})=>x(u({message:j,severity:"warning"},C)),F=(j="",C={})=>x(u({message:j,severity:"error"},C)),_=j=>{const C=d.current.findIndex($=>$.key===j);if(C!==-1)return C===0?(c({open:!1}),d.current[0]):d.current.splice(C,1)},P=(j,C)=>{n(j,C)&&c({open:!1})},H=()=>{},W=()=>{d.current.shift(),d.current.length>0&&c({open:!0})},b=(N=d.current[0])!=null?N:u({},me),M={};"autoHideDuration"in b&&(M.autoHideDuration=b.autoHideDuration);const z=u(u({},gt),s),O=u(u({open:a,setOpen:v,enqueueNotification:x,enqueueSuccessNotification:S,enqueueInfoNotification:k,enqueueWarningNotification:f,enqueueErrorNotification:F,removeNotification:_},e),t);return o.jsxs(re.Provider,{value:O,children:[i,o.jsx(r.Snackbar,E(u(u({},z),M),{open:a,onClose:P,TransitionProps:{onExited:W,onExit:H},sx:{zIndex:Ct},children:o.jsxs("div",{children:[o.jsx(r.Alert,{onClose:j=>P(j,"closeAlert"),severity:b.severity,variant:"filled",icon:b.progressIndicator==="circular"?o.jsx(r.CircularProgress,{size:"1em"}):void 0,style:b.progressIndicator==="linear"?yt:void 0,children:b.message}),b.progressIndicator==="linear"&&o.jsx(r.LinearProgress,{color:"primary"})]})}))]})}class se extends Error{}pe(se,"errorName","ContextError");function Ee(){const e=w.useContext(re);if(e===null)throw new se("Error: Tried to useSaladBar outside of a <SaladBarProvider>");return e}const Dt=Ye.createHelper((e={autoHideDuration:1},t={},n={})=>({children:i})=>o.jsx(ke,E(u({},e),{overrideState:t,overrideActions:n,children:o.jsx(o.Fragment,{children:i})}))),_e="domainCode";var ve;const Ae=D.atom(JSON.parse((ve=localStorage.getItem(_e))!=null?ve:'{"domainCode": ""}').domainCode),Te=D.atom(e=>e(Ae),(e,t,n)=>{t(Ae,n),localStorage.setItem(_e,JSON.stringify({domainCode:n}))}),be={act:"ACT",nsw:"NSW",nt:"NT",qld:"QLD",sa:"SA",tas:"TAS",vic:"VIC",wa:"WA",ag:"AG",fedmps:"FedMPs","":""},ae=e=>{var t;return e===null?"N/A":(t=be[e])!=null?t:""},wt=({isLoading:e,isOpen:t,onClose:n,onDomainChange:i,domainOptions:s,applicationName:l,handleLogout:p})=>{const[a,c]=D.useAtom(Te),[d,g]=w.useState(a),{enqueueSuccessNotification:A}=Ee(),v=s.length===0,x=!!a&&!s.includes(a)&&!s.includes(d),S=!a||v||x,k=()=>I(null,null,function*(){d?(c(d),i==null||i(d),A(`Set organisation to ${d}`),n()):(c(""),i==null||i(""))}),f=()=>I(null,null,function*(){a&&!v&&!x?(g(a),n()):S&&p()});let F;return v?F="Unable to retrieve your active organisations. Try logging in again.":x&&(F="You no longer have any roles in your chosen organisation. Please choose another."),o.jsxs(ne,{isOpen:t,dialogTitle:"Select an organisation",primaryButton:{text:"Confirm",onClick:k,disabled:!d||v||x,buttonColor:"primary"},secondaryButton:{text:S?"Logout":"Cancel",onClick:f},onClose:S?()=>{}:n,children:[o.jsxs(r.Typography,{marginBottom:2,children:["Select the default organisation that you want to use with the ",l,"."]}),o.jsx(r.Autocomplete,{loading:e,multiple:!1,disableClearable:!1,value:d!==""?d:null,onChange:(_,P)=>g(P!=null?P:""),getOptionLabel:ae,options:[...s.toSorted()],renderInput:_=>o.jsx(r.TextField,E(u({},_),{variant:"filled",label:"Select organisation",InputProps:E(u({},_.InputProps),{endAdornment:o.jsxs(o.Fragment,{children:[e?o.jsx(r.CircularProgress,{color:"inherit",size:20,sx:{marginTop:"-20px"}}):null,_.InputProps.endAdornment]})})}))}),F&&o.jsx(r.FormHelperText,{error:!0,children:F})]})},Pe=()=>{const e=r.useTheme();return r.useMediaQuery(e.breakpoints.down("sm"))},Ft=64,kt=72,Et=256,G=D.atom(!0),Ie=D.atom(Et),Be=D.atom(kt),te=D.atom(""),Me=D.atom(void 0),Ne=D.atom(Ft),Le=D.atom(void 0);function _t({links:e}){return o.jsx("div",{children:"LinksMenu not implemented yet"})}const Q="Navbar",V={root:`${Q}-root`,menuButton:`${Q}-menuButton`,hide:`${Q}-hide`,content:`${Q}-content`},Tt=L.styled(r.Box,{name:"NavBar"})(({theme:e})=>({[`&.${V.root}`]:{display:"flex"},[`& .${V.menuButton}`]:{marginRight:36},[`& .${V.hide}`]:{display:"none"},[`& .${V.content}`]:{flexGrow:1,padding:e.spacing(3)}})),q=(e,t,n)=>e.transitions.create(t,{easing:e.transitions.easing.sharp,duration:n==="leaving"?e.transitions.duration.leavingScreen:e.transitions.duration.enteringScreen}),bt=e=>{const t=r.useTheme();return o.jsx(r.Collapse,u({easing:t.transitions.easing.sharp,timeout:{enter:t.transitions.duration.enteringScreen,exit:t.transitions.duration.leavingScreen}},e))},Oe=e=>{var t,n;return{overflowX:"hidden",color:"inherit",backgroundColor:(n=(t=e==null?void 0:e.navBar)==null?void 0:t.backgroundColor)!=null?n:"white"}},Ce=(e,t)=>u({width:t,transition:q(e,"width","entering")},Oe(e)),Se=(e,t)=>u({width:t,transition:q(e,"width","leaving")},Oe(e)),Pt=L.styled(r.Drawer,{shouldForwardProp:e=>!["widthOpen","widthClosed","isSmallScreen"].includes(e)})(({theme:e,open:t,widthOpen:n,widthClosed:i,isSmallScreen:s})=>u(u({flexShrink:0,whiteSpace:"nowrap",boxSizing:"border-box",display:"flex",flexDirection:"column"},t&&E(u({},Ce(e,n)),{backgroundColor:"","& .MuiDrawer-paper":Ce(e,n)})),!t&&E(u({},Se(e,s?n:i)),{backgroundColor:"","& .MuiDrawer-paper":Se(e,s?n:i)})));function $e(e){return e.replace(/(^|-)([a-z])/g,(t,n,i)=>n==="-"?" "+i.toUpperCase():i.toUpperCase())}function It(e,t,n,i){var p;if(!e)return"None";const s=e["https://greens.org.au/roles"];if(!s)return"None";const l=Object.entries(s).filter(([,a])=>a.includes(t)).map(([a])=>$e(a));return(p=i.find(a=>n[a].some(c=>l.includes(c))))!=null?p:"None"}function Re(e,t){return Object.entries(e).reduce((n,[i,s])=>{const l=$e(i),p=t.includes(l)?s:[];return[...new Set([...n,...p])]},[])}const Bt=e=>{const{getIdTokenClaims:t,user:n}=oe.useAuth0();return De.useQuery({queryKey:["availableDomains",n==null?void 0:n.sub],queryFn:()=>I(null,null,function*(){const i=yield t();if(!i)return[];const s=i["https://greens.org.au/roles"];return s?Re(s,e):[]})})},Mt=e=>Object.values(e).reduce((t,n)=>[...new Set([...t,...n])],[]),Y={log:console.warn.bind(console),error:console.error.bind(console),warn:console.warn.bind(console),info:console.info.bind(console),debug:console.debug.bind(console)};function Nt(e,t){console[e]=(...n)=>{for(const i of t)if(typeof i=="function"){if(i(...n))return}else if(i instanceof RegExp&&n.length>0){for(const s of n)if(typeof s=="string"&&i.test(s))return}Y[e](n)}}function Lt(e){if(e)console[e]=Y[e];else for(const t of Object.keys(Y))console[t]=Y[t]}function Ot(e,t){return e!=null&&typeof e=="object"&&"error"in e&&e.error===t}function $t(e,t){const n=t==null?void 0:t.originalException;return Ot(n,"login_required")?null:e}function qe(e){let t=0;for(let n=0,i=e.length;n<i;n++){const s=e.charCodeAt(n);t=(t<<5)-t+s,t|=0}return t}const ye=["#A62A21","#7e3794","#0B51C1","#3A6024","#A81563","#B3003C"],je=e=>e.split(/\s/).map(t=>t.substring(0,1).toUpperCase()).filter(t=>!!t).slice(0,2).join("").toUpperCase();function Rt({user:e,domainCode:t,open:n,useNewAvatar:i=!1}){const s=r.useTheme();return o.jsxs(r.Box,{sx:{paddingTop:3,display:"flex",alignItems:"center",flexDirection:"column",gap:"0.5rem"},children:[!i&&o.jsx(r.Box,{sx:{width:n?"5rem":"2rem",transition:n?q(s,["width","height"],"entering"):q(s,["width","height"],"leaving"),aspectRatio:1},children:e!=null&&e.name?o.jsx(o.Fragment,{children:o.jsx(r.Avatar,{src:e==null?void 0:e.picture,sx:{width:"100%",height:"100%",bgcolor:ye[Math.abs(qe(e==null?void 0:e.name))%ye.length]},children:je(e==null?void 0:e.name)})}):o.jsx(r.Avatar,{sx:{width:"100%",height:"100%"}})}),i&&o.jsx(r.Box,{sx:{width:n?"5rem":"2rem",transition:n?q(s,["width","height"],"entering"):q(s,["width","height"],"leaving"),aspectRatio:1},children:e!=null&&e.name?o.jsx(o.Fragment,{children:o.jsxs(fe.default,{src:e==null?void 0:e.picture,name:e==null?void 0:e.name,round:!0,size:n?"80":"32",children:[" ",je(e==null?void 0:e.name)," ","ab"]})}):o.jsx(fe.default,{})}),o.jsx(bt,{sx:{width:"100%"},in:n,children:o.jsx(r.Fade,{in:n,children:o.jsxs(r.Box,{width:"100%",display:"flex",flexDirection:"column",alignItems:"center",children:[e!=null&&e.name?o.jsx(r.Typography,{children:e==null?void 0:e.name}):o.jsx(r.Skeleton,{animation:!1,width:"50%"}),t?o.jsx(r.Typography,{children:ae(t)}):o.jsx(r.Skeleton,{animation:!1,width:"25%"})]})})})]})}function qt({open:e,widthClosed:t,widthOpen:n,"data-testid":i,top:s,middle:l,bottom:p,user:a,domainCode:c,useNewAvatar:d=!1}){const g=Pe(),A=D.useSetAtom(G);return o.jsx(Tt,{className:V.root,"data-testid":i,children:o.jsxs(Pt,{open:e,widthOpen:n,widthClosed:t,anchor:"left",variant:g?"temporary":"permanent",PaperProps:{component:"nav"},onClose:()=>{A(!1)},isSmallScreen:g,children:[!g&&o.jsx(r.Toolbar,{}),s&&o.jsxs(r.Box,{flexGrow:"0",children:[s,o.jsx(r.Divider,{variant:"middle",sx:{marginY:"0.5rem"}})]}),o.jsx(r.Box,{flexGrow:"1",children:Array.isArray(l)?o.jsx(_t,{links:l}):l}),o.jsxs(r.Box,{flexGrow:"0",children:[o.jsx(r.Divider,{variant:"middle",sx:{marginY:"0.5rem"}}),o.jsx(Rt,{user:a,domainCode:c,open:e,useNewAvatar:d}),p&&o.jsx(o.Fragment,{children:p})]})]})})}function Ut({children:e,topBarHeight:t,maxWidth:n=!1,noPadding:i}){return o.jsx(r.Box,{sx:{overflow:"auto",height:`calc(100vh - ${t}px)`,flexGrow:1},children:i?o.jsx(r.Box,{height:"inherit",children:e}):o.jsx(r.Container,{maxWidth:n,sx:{paddingTop:3,paddingBottom:3,flexGrow:1},children:e})})}const Ht="TopBar",Wt={titleText:`${Ht}-titleText`};function zt({titleText:e="",height:t,"data-testid":n,middle:i}){const s=D.useSetAtom(G),l=()=>s(c=>!c),p=r.useTheme(),a=Pe();return o.jsx("header",{"data-testid":n,children:o.jsxs(r.Paper,{square:!0,elevation:0,sx:{width:"100%",position:"sticky",color:"primary.contrastText",backgroundColor:"primary.main",display:"flex",alignItems:"center",gap:2,flexShrink:0,height:t,zIndex:a?0:p.zIndex.drawer+99},children:[o.jsx(r.IconButton,{size:"medium",color:"inherit",sx:{padding:1.5,marginLeft:"12px"},onClick:l,children:o.jsx(ee.ViewHeadline,{fontSize:"medium"})}),o.jsx(r.Typography,{className:Wt.titleText,variant:"h6",component:"h1",children:e}),i]})})}function Vt({children:e,initialTitleText:t,initialNavBarOpen:n,pageContainerProps:i,pageContentDataTestId:s,topBarDataTestId:l,navBarDataTestId:p,navBarMiddle:a,navBarBottom:c,user:d,domainCode:g,useNewAvatar:A=!1}){et.useHydrateAtoms([[G,n!=null?n:!0],[te,t!=null?t:""]]);const v=D.useAtomValue(G),[x]=D.useAtom(Ie),[S]=D.useAtom(Be),k=D.useAtomValue(te),[f]=D.useAtom(Ne),[F]=D.useAtom(Me),[_]=D.useAtom(Le);return o.jsxs(he.default,{children:[o.jsx(rt.default,{}),o.jsx(zt,{titleText:k,"data-testid":l,height:f,middle:F}),o.jsxs(he.default,{sx:{display:"flex"},children:[o.jsx(qt,{open:v,top:_,middle:a,bottom:c,user:d,domainCode:g,widthOpen:x,widthClosed:S,offsetTop:f,"data-testid":p,useNewAvatar:A}),o.jsx(Ut,E(u({"data-testid":s,topBarHeight:f},i),{children:e}))]})]})}const Gt=L.createTheme({palette:{primary:{dark:"#00A651",light:"#A3D39C",main:"#007236",contrastText:"#FFF"},warning:{main:"#F5871F",light:"#FCC589",dark:"#A2590A",contrastText:"#FFF"},secondary:{main:"#662D91",light:"#BD8CBF",dark:"#440E62",contrastText:"#FFF"},error:{main:"#D43C95",light:"#8F2064",dark:"#F9CDE0",contrastText:"#FFF"},info:{main:"#00A88D",light:"#ADDCCF",dark:"#005243",contrastText:"#FFF"},success:{main:"#00A651",light:"#A3D39C",dark:"#007236",contrastText:"#FFF"}},typography:{explainer:{fontSize:"14px",marginBlockStart:"1em"}},navBar:{backgroundColor:"#E8E8E8"}}),Xt=L.createTheme({palette:{primary:{main:"#007236",dark:"#005221",light:"#00A04E",contrastText:"#FFFFFF"},secondary:{main:"#662D91",dark:"#440E62",light:"#93268F",contrastText:"#FFFFFF"},error:{main:"#D32F2F",dark:"#C62828",light:"#EF5350"},info:{main:"#0288D1",dark:"#01579B",light:"#03A9F4"},success:{main:"#0288D1",dark:"#01579B",light:"#03A9F4"}},components:{MuiTextField:{defaultProps:{color:"secondary"}},MuiToggleButtonGroup:{defaultProps:{color:"secondary"}},MuiCheckbox:{defaultProps:{color:"secondary"}},MuiSelect:{defaultProps:{color:"secondary"}},MuiSwitch:{defaultProps:{color:"secondary"}},MuiFormControl:{defaultProps:{color:"secondary"}},MuiMenuItem:{styleOverrides:{root:({theme:e})=>({"&.Mui-selected":{backgroundColor:L.alpha(e.palette.secondary.main,e.palette.action.selectedOpacity),"&:hover":{backgroundColor:L.alpha(e.palette.secondary.main,e.palette.action.selectedOpacity)},"&.Mui-focusVisible":{backgroundColor:L.alpha(e.palette.secondary.main,e.palette.action.focusOpacity)}}})}}},typography:{h4:{fontSize:"1.88rem",fontWeight:500},h5:{fontWeight:500},explainer:{fontSize:"14px",marginBlockStart:"1em"}},navBar:{backgroundColor:"#E8E8E8"}});exports.AgDialog=ne;exports.AppLayout=Vt;exports.AuthGuard=xt;exports.Context=re;exports.ContextError=se;exports.DOMAIN_CODE_LABELS=be;exports.DomainCodeDialog=wt;exports.ExampleComponent=st;exports.FetchAutocomplete=lt;exports.MUI_AUTOCOMPLETE_VALUE_WARNING_REGEX=ct;exports.SaladBarProvider=ke;exports.SessionExpiryDialog=ut;exports.SingleAutocomplete=dt;exports.determineUserLevelFromClaims=It;exports.domainCodeAtom=Te;exports.fed21Theme=Gt;exports.getAuth0Expiry=Fe;exports.getDomainOptionLabel=ae;exports.getDomainsFromRolesClaim=Re;exports.getValidBusinessRoles=Mt;exports.internalAgSystemsTheme=Xt;exports.navBarOpenAtom=G;exports.navBarTopAtom=Le;exports.navBarWidthClosedAtom=Be;exports.navBarWidthOpenAtom=Ie;exports.sentryBeforeSend=$t;exports.simpleHashCode=qe;exports.suppressConsole=Nt;exports.titleTextAtom=te;exports.topBarHeightAtom=Ne;exports.topBarMiddleAtom=Me;exports.unsuppressConsole=Lt;exports.useAutocompleteOptions=ie;exports.useSaladBar=Ee;exports.useValidDomains=Bt;exports.withSaladBarProvider=Dt;
|
|
1
|
+
"use strict";var We=Object.defineProperty,ze=Object.defineProperties;var Ve=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,de=Object.prototype.propertyIsEnumerable;var Z=(e,t,n)=>t in e?We(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,u=(e,t)=>{for(var n in t||(t={}))ce.call(t,n)&&Z(e,n,t[n]);if(K)for(var n of K(t))de.call(t,n)&&Z(e,n,t[n]);return e},E=(e,t)=>ze(e,Ve(t));var ue=(e,t)=>{var n={};for(var i in e)ce.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(e!=null&&K)for(var i of K(e))t.indexOf(i)<0&&de.call(e,i)&&(n[i]=e[i]);return n};var pe=(e,t,n)=>Z(e,typeof t!="symbol"?t+"":t,n);var I=(e,t,n)=>new Promise((i,s)=>{var l=d=>{try{a(n.next(d))}catch(c){s(c)}},p=d=>{try{a(n.throw(d))}catch(c){s(c)}},a=d=>d.done?i(d.value):Promise.resolve(d.value).then(l,p);a((n=n.apply(e,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),F=require("react"),r=require("@mui/material"),ee=require("@mui/icons-material"),De=require("@tanstack/react-query"),Ge=require("autosuggest-highlight/match"),Xe=require("autosuggest-highlight/parse"),oe=require("@auth0/auth0-react"),Ke=require("buffer"),Qe=require("@mui/material/Skeleton"),w=require("jotai"),Ye=require("souvlaki"),Je=require("@mui/material/CssBaseline"),Ze=require("@mui/material/Box"),et=require("jotai/utils"),L=require("@mui/material/styles"),tt=require("react-avatar"),U=e=>e&&e.__esModule?e:{default:e},ot=U(Ge),nt=U(Xe),it=U(Qe),rt=U(Je),he=U(Ze),me=U(tt);function st({text:e}){const[t,n]=F.useState(0);return o.jsxs(o.Fragment,{children:[o.jsx(r.Typography,{variant:"h6",color:"inherit",component:"div",sx:{fontSize:"22px"},children:"Hello world"}),o.jsx(r.Typography,{variant:"caption",display:"block",children:o.jsx("span",{children:"Just ensuring MUI is working as planned as a peer dependency. v0.0.11"})}),o.jsx(r.Button,{variant:"outlined",onClick:()=>n(i=>i+1),"aria-label":"Increment",children:"Hello I am a button"}),o.jsxs("p",{children:["This is some text: ",o.jsx("span",{children:e})]}),o.jsxs(r.Paper,{children:["This number will incremember when button pressed: ",t]})]})}const ne=({isOpen:e,dialogTitle:t,children:n,maxWidth:i,primaryButton:s,secondaryButton:l,additionalButtons:p,onClose:a,sx:d,"data-testid":c,disableCloseOnBackdropOrEscape:g=!1,isLoading:A=!1})=>{var S,k;const[j,x]=F.useState(!1);return o.jsxs(r.Dialog,{open:e,onClose:(m,D)=>I(null,null,function*(){g&&(D==="backdropClick"||D==="escapeKeyDown")||j||(l!=null&&l.onClick?yield l.onClick():a())}),fullWidth:!0,maxWidth:i!=null?i:"xs","data-testid":c,sx:d,children:[A&&o.jsx(r.LinearProgress,{sx:{height:"4px",marginBottom:"-4px"}}),o.jsx(r.DialogTitle,{children:t}),o.jsx(r.DialogContent,{sx:{"& > :last-child":{marginBottom:0}},children:n}),o.jsxs(r.DialogActions,{children:[o.jsx(r.Button,{onClick:(S=l==null?void 0:l.onClick)!=null?S:a,"data-testid":l==null?void 0:l.testId,disabled:(l==null?void 0:l.disabled)||j,color:l==null?void 0:l.buttonColor,children:(k=l==null?void 0:l.text)!=null?k:"Cancel"}),p&&p.map((m,D)=>{var _;return o.jsx(r.Button,{onClick:m==null?void 0:m.onClick,"data-testid":m==null?void 0:m.testId,disabled:(m==null?void 0:m.disabled)||j,color:m==null?void 0:m.buttonColor,children:(_=m.text)!=null?_:`Button ${D}`},D)}),s&&o.jsx(r.Button,{onClick:()=>I(null,null,function*(){var m;x(!0),yield(m=s.onClick)==null?void 0:m.call(s),x(!1)}),"data-testid":s.testId,disabled:s.disabled||j,color:s==null?void 0:s.buttonColor,children:s.text})]})]})},at={popper:{modifiers:[{name:"offset",options:{offset:[115,-15]}}]}},we={right:2},ie=({minLength:e,preLoadedOptions:t,lookup:n,label:i,inputValue:s})=>De.useQuery({queryFn:()=>e&&s.length<e?t!=null?t:[]:t?t.filter(l=>l.label.toLowerCase().includes(s.toLowerCase())):n(s),queryKey:["autocomplete",i,s]});function lt({lookup:e=()=>I(null,null,function*(){}),enableHighlighting:t=!0,onChange:n,onInputChange:i,minLength:s=0,label:l,value:p,"data-testid":a,sx:d,boxSx:c,textFieldColor:g,textFieldVariant:A="filled",textFieldFocused:j,textFieldSx:x,loadingText:S="Loading...",noOptionsText:k="No options",popupIcon:m=o.jsx(ee.ArrowDropDown,{}),error:D=!1,helperText:_="",preLoadedOptions:T=void 0,disablePortal:H=!1,disableIconFlip:W=!1,chipToolTipSlotProps:P=at,placeholderText:M=void 0,onRightClick:z=()=>{},disableDefaultRightClickBehaviour:O=!1,readOnly:N,hideInputEndAdornment:v}){const[C,$]=F.useState(""),X=(h,y)=>{const B=p.filter(J=>J.id!==y);n(B,"delete",h)},{data:f,isLoading:b}=ie({inputValue:C,label:l,lookup:e,minLength:s,preLoadedOptions:T}),R=C.length>=s;return o.jsxs("div",{"data-testid":a,children:[o.jsx(r.Autocomplete,{sx:u(u({},d),W?{".MuiAutocomplete-popupIndicatorOpen":{transform:"rotate(0deg)"}}:{}),"data-testid":a?`${a}:Autocomplete`:void 0,disablePortal:H,multiple:!0,getOptionLabel:h=>typeof h=="string"?h:h.label,loading:R?b:!1,options:[...p,...f!=null?f:[]],filterSelectedOptions:!0,includeInputInList:!0,value:p,onChange:(h,y,B)=>{n(y,B,h)},onInputChange:(h,y,B)=>{$(y),i&&i(p,B,h)},noOptionsText:R?k:"Start typing to search",loadingText:S,popupIcon:m,renderInput:h=>o.jsx(r.TextField,E(u({},h),{label:l,fullWidth:!0,variant:A,error:D,helperText:_,autoComplete:"off",slotProps:{input:E(u({},h.InputProps),{endAdornment:v?void 0:o.jsxs(o.Fragment,{children:[b?o.jsx(r.CircularProgress,{color:"inherit",size:20}):null,h.InputProps.endAdornment]})})},"data-testid":a?`${a}:Autocomplete:TextField`:void 0,onKeyDown:y=>{(y.key==="Backspace"||y.key==="Delete")&&y.stopPropagation()},color:g,placeholder:M,sx:x,focused:j})),renderValue:()=>null,isOptionEqualToValue:(h,y)=>h.id===y.id,renderOption:(h,y,B)=>{if(t){const J=ot.default(y.label,B.inputValue,{insideWords:!0,findAllOccurrences:!0}),Ue=nt.default(y.label,J);return F.createElement("li",E(u({},h),{key:y.id,"data-testid":a?`${a}:Autocomplete:option(${y.id.toString()})`:void 0}),o.jsx("div",{children:Ue.map((le,He)=>o.jsx("span",{style:{fontWeight:le.highlight?700:400},children:le.text},He))}))}else return F.createElement("li",E(u({},h),{key:y.id,"data-testid":a?`${a}:option(${y.id.toString()})`:void 0}),y.label)},onMouseDownCapture:h=>{h.button===we.right&&O&&(h.preventDefault(),h.stopPropagation())},onContextMenuCapture:h=>{O&&(h.preventDefault(),h.stopPropagation()),z(h)},readOnly:N}),p.length>0&&o.jsx(r.Box,{sx:c,children:p.map(h=>{var y;return o.jsx(r.Chip,{sx:{marginTop:1,marginRight:1,height:"auto"},label:o.jsx(r.Tooltip,{title:(y=h.tooltipContent)!=null?y:"",placement:"bottom-start",slotProps:P,children:o.jsx(r.Typography,{style:{whiteSpace:"normal"},children:h.chipLabel?h.chipLabel:h.label})}),"data-testid":a?`${a}:Chip(${h.id.toString()})`:void 0,onDelete:B=>X(B,h.id),deleteIcon:o.jsx(ee.Cancel,{"data-testid":a?`${a}:Chip(${h.id.toString()}):deleteIcon`:void 0})},h.id)})})]})}const ct=/MUI: The value provided to.*is invalid/i,dt=({lookup:e=()=>I(null,null,function*(){}),onChange:t,onInputChange:n,label:i,value:s,sx:l,textFieldColor:p,textFieldVariant:a="filled",textFieldFocused:d,textFieldSx:c,error:g=!1,"data-testid":A,loadingText:j="Loading...",noOptionsText:x="No options",minLength:S=3,disablePortal:k=!1,preLoadedOptions:m,helperText:D="",disabled:_,popupIcon:T,disableIconFlip:H,placeholderText:W=void 0,onRightClick:P=()=>{},disableDefaultRightClickBehaviour:M=!1,readOnly:z,hideInputEndAdornment:O})=>{const[N,v]=F.useState(""),{data:C,isLoading:$}=ie({inputValue:N,label:i,lookup:e,minLength:S!=null?S:0,preLoadedOptions:m}),X=N.length>=S;return o.jsx("div",{"data-testid":A,children:o.jsx(r.Stack,{direction:"row",spacing:1,onMouseDownCapture:f=>{f.button===we.right&&M&&(f.preventDefault(),f.stopPropagation())},onContextMenuCapture:f=>{M&&(f.preventDefault(),f.stopPropagation()),P(f)},children:o.jsx(r.Autocomplete,{sx:u(u({},l),H?{".MuiAutocomplete-popupIndicatorOpen":{transform:"rotate(0deg)"}}:{}),"data-testid":A?`${A}:Autocomplete`:void 0,loading:X?$:!1,options:C!=null?C:[],onChange:(f,b,R)=>{t(f,b,R)},disablePortal:k,filterOptions:f=>f,value:s,noOptionsText:X?x:"Start typing to search",loadingText:j,getOptionLabel:f=>f.label,popupIcon:T,renderInput:f=>o.jsx(r.TextField,E(u({"data-testid":A?`${A}:Autocomplete:TextField`:void 0},f),{variant:a,label:i,color:p,error:g,helperText:D,autoComplete:"off",slotProps:{input:E(u({},f.InputProps),{endAdornment:O?void 0:o.jsxs(o.Fragment,{children:[$?o.jsx(r.CircularProgress,{color:"inherit",size:20}):null,f.InputProps.endAdornment]})})},placeholder:W,sx:c,focused:d})),isOptionEqualToValue:(f,b)=>f.id===b.id,onInputChange:(f,b,R)=>{v(b),n&&n(b,R,f)},renderOption:(f,b)=>F.createElement("li",E(u({},f),{key:b.id,"data-testid":A?`${A}:Autocomplete:option(${b.id.toString()})`:void 0}),b.label),disabled:_,readOnly:z})})})},Fe=e=>{if(!e)return-1;try{const n=e.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),i=decodeURIComponent(Ke.Buffer.from(n,"base64").toString("utf8").split("").map(function(l){return"%"+("00"+l.charCodeAt(0).toString(16)).slice(-2)}).join("")),s=JSON.parse(i);return s!=null&&s.exp?s.exp:-1}catch(t){return-1}},ut=({open:e=!1,closeHandler:t,setAuth0ExpiryTime:n})=>{const{logout:i,getAccessTokenSilently:s}=oe.useAuth0(),l=()=>I(null,null,function*(){i({logoutParams:{returnTo:`${window.location.origin}`}})}),a={text:"Continue",onClick:()=>I(null,null,function*(){const c=yield s({cacheMode:"off"}),g=Fe(c)*1e3;n(g),t()}),disabled:!1,testId:"PreferencesDialog",buttonColor:"secondary"},d={text:"Log out",onClick:l,disabled:!1,testId:"PreferencesDialog",buttonColor:"secondary"};return o.jsx(ne,{isOpen:e,primaryButton:a,secondaryButton:d,onClose:t,dialogTitle:"Session expiry",disableCloseOnBackdropOrEscape:!0,children:o.jsx("p",{style:{marginBottom:0},children:"Your session is about to time out due to inactivity. Do you want to continue?"})})};function pt(e){return"error"in e}function ht(e){var i;const t=e.error,n=(i=e==null?void 0:e.error_description)!=null?i:"";return t==="access_denied"&&n.startsWith("You do not have the required authorization")}function mt(e){var i;const t=e.error,n=(i=e==null?void 0:e.error_description)!=null?i:"";return t==="access_denied"&&n.startsWith("User did not authorize the request")}function ft(e){var i;const t=e.error,n=(i=e==null?void 0:e.error_description)!=null?i:"";return t==="access_denied"&&n.match(/Script.*time.*exceeded/)}function xt({children:e,appName:t="the app",throwErrors:n="none",disableConsoleLogging:i=!1,onError:s=()=>{}}){var A,j;const{isAuthenticated:l,isLoading:p,error:a,loginWithRedirect:d,logout:c}=oe.useAuth0();F.useEffect(()=>{a&&s(a)},[a,s]);const g=F.useMemo(()=>({appState:{returnTo:`${window.location.pathname}${window.location.search}`}}),[]);if(F.useEffect(()=>{p||l||a||d(g)},[p,l,a,d,s,g]),a){if(i||console.error(`Error detected in AuthGuard [isAuthenticated=${l},isLoading=${p}]`,a),n==="all")throw a;if(pt(a)){let x="Auth error",S="An unknown Auth0 error occurred.";if(ht(a))x="Unauthorised",S=`You are not authorised to access ${t}.`;else if(mt(a))x="App not authorised",S=`You have not authorised ${t} to access your user profile. This is necessary to use ${t}.`;else if(ft(a))x="Auth0 script execution time exceeded",S="The Auth0 login flow exceeded the time limit (20s). Try again in a minute by clicking the RELOAD button below.";else if(a.message==="Invalid state"){const k=localStorage.getItem("auth0_redirect_count");k?k&&parseInt(k)<2&&(localStorage.setItem("auth0_redirect_count",String(parseInt(k)+1)),d(g)):(localStorage.setItem("auth0_redirect_count","1"),d(g))}else if(n==="unknown")throw a;return o.jsxs(r.Dialog,{open:!0,children:[o.jsx(r.DialogTitle,{children:x}),o.jsxs(r.DialogContent,{children:[o.jsx(r.Typography,{children:S}),o.jsx("br",{}),o.jsx(r.Typography,{variant:"subtitle2",children:"Details from Auth0"}),o.jsxs(r.Typography,{variant:"body2",children:["error: ",(A=a==null?void 0:a.error)!=null?A:"N/A"]}),o.jsxs(r.Typography,{variant:"body2",children:["description: ",(j=a==null?void 0:a.error_description)!=null?j:"N/A"]})]}),o.jsxs(r.DialogActions,{children:[x==="Auth0 script execution time exceeded"&&o.jsx(r.Button,{href:window.location.origin+window.location.pathname,children:"Reload"}),o.jsx(r.Button,{onClick:()=>c({logoutParams:{returnTo:window.location.origin}}),children:"Logout"})]})]})}else if(n==="unknown")throw a}return l?(localStorage.removeItem("auth0_redirect_count"),o.jsx(o.Fragment,{children:e})):o.jsx(it.default,{variant:"rectangular",animation:"pulse",height:"100vh",width:"100vw"})}const gt={autoHideDuration:6e3,anchorOrigin:{vertical:"top",horizontal:"center"},disableWindowBlurListener:!1},At={shouldClose:(e,t)=>t!=="clickaway"},fe={message:"",severity:"info",variant:"standard",progressIndicator:void 0},xe=100,ge=2e3,Ct=2e3,St=(()=>{let e=0;return()=>(e+=1,e)})(),yt={borderBottomLeftRadius:"0px",borderBottomRightRadius:"0px"},vt={},jt={},re=F.createContext(null);function ke(l){var p=l,{overrideState:e=vt,overrideActions:t=jt,shouldClose:n=At.shouldClose,children:i}=p,s=ue(p,["overrideState","overrideActions","shouldClose","children"]);var N;const[{open:a},d]=F.useState({open:!1}),c=F.useRef([]),g=F.useRef(Date.now()),A=F.useRef(0),j=F.useCallback(v=>{d({open:v})},[]),x=F.useCallback((v={})=>{A.current+=1,c.current.length>=xe&&Date.now()-g.current>=ge&&(g.current=Date.now(),console.error(`SaladBarProvider: MAX_QUEUE_LENGTH (${xe}) hit ${A.current} times in last ${ge}ms)`),A.current=0);const C=u(E(u({},fe),{key:St()}),v);return c.current.push(C),c.current.length===1&&d({open:!0}),C.key},[]),S=(v="",C={})=>x(u({message:v,severity:"success"},C)),k=(v="",C={})=>x(u({message:v,severity:"info"},C)),m=(v="",C={})=>x(u({message:v,severity:"warning"},C)),D=(v="",C={})=>x(u({message:v,severity:"error"},C)),_=v=>{const C=c.current.findIndex($=>$.key===v);if(C!==-1)return C===0?(d({open:!1}),c.current[0]):c.current.splice(C,1)},T=(v,C)=>{n(v,C)&&d({open:!1})},H=()=>{},W=()=>{c.current.shift(),c.current.length>0&&d({open:!0})},P=(N=c.current[0])!=null?N:u({},fe),M={};"autoHideDuration"in P&&(M.autoHideDuration=P.autoHideDuration);const z=u(u({},gt),s),O=u(u({open:a,setOpen:j,enqueueNotification:x,enqueueSuccessNotification:S,enqueueInfoNotification:k,enqueueWarningNotification:m,enqueueErrorNotification:D,removeNotification:_},e),t);return o.jsxs(re.Provider,{value:O,children:[i,o.jsx(r.Snackbar,E(u(u({},z),M),{open:a,onClose:T,TransitionProps:{onExited:W,onExit:H},sx:{zIndex:Ct},children:o.jsxs("div",{children:[o.jsx(r.Alert,{onClose:v=>T(v,"closeAlert"),severity:P.severity,variant:"filled",icon:P.progressIndicator==="circular"?o.jsx(r.CircularProgress,{size:"1em"}):void 0,style:P.progressIndicator==="linear"?yt:void 0,children:P.message}),P.progressIndicator==="linear"&&o.jsx(r.LinearProgress,{color:"primary"})]})}))]})}class se extends Error{}pe(se,"errorName","ContextError");function Ee(){const e=F.useContext(re);if(e===null)throw new se("Error: Tried to useSaladBar outside of a <SaladBarProvider>");return e}const Dt=Ye.createHelper((e={autoHideDuration:1},t={},n={})=>({children:i})=>o.jsx(ke,E(u({},e),{overrideState:t,overrideActions:n,children:o.jsx(o.Fragment,{children:i})}))),_e="domainCode";var je;const Ae=w.atom(JSON.parse((je=localStorage.getItem(_e))!=null?je:'{"domainCode": ""}').domainCode),be=w.atom(e=>e(Ae),(e,t,n)=>{t(Ae,n),localStorage.setItem(_e,JSON.stringify({domainCode:n}))}),Te={act:"ACT",nsw:"NSW",nt:"NT",qld:"QLD",sa:"SA",tas:"TAS",vic:"VIC",wa:"WA",ag:"AG",fedmps:"FedMPs","":""},ae=e=>{var t;return e===null?"N/A":(t=Te[e])!=null?t:""},wt=({isLoading:e,isOpen:t,onClose:n,onDomainChange:i,domainOptions:s,applicationName:l,handleLogout:p})=>{const[a,d]=w.useAtom(be),[c,g]=F.useState(a),{enqueueSuccessNotification:A}=Ee(),j=s.length===0,x=!!a&&!s.includes(a)&&!s.includes(c),S=!a||j||x,k=()=>I(null,null,function*(){c?(d(c),i==null||i(c),A(`Set organisation to ${c}`),n()):(d(""),i==null||i(""))}),m=()=>I(null,null,function*(){a&&!j&&!x?(g(a),n()):S&&p()});let D;return j?D="Unable to retrieve your active organisations. Try logging in again.":x&&(D="You no longer have any roles in your chosen organisation. Please choose another."),o.jsxs(ne,{isOpen:t,dialogTitle:"Select an organisation",primaryButton:{text:"Confirm",onClick:k,disabled:!c||j||x,buttonColor:"primary"},secondaryButton:{text:S?"Logout":"Cancel",onClick:m},onClose:S?()=>{}:n,children:[o.jsxs(r.Typography,{marginBottom:2,children:["Select the default organisation that you want to use with the ",l,"."]}),o.jsx(r.Autocomplete,{loading:e,multiple:!1,disableClearable:!1,value:c!==""?c:null,onChange:(_,T)=>g(T!=null?T:""),getOptionLabel:ae,options:[...s.toSorted()],renderInput:_=>o.jsx(r.TextField,E(u({},_),{variant:"filled",label:"Select organisation",InputProps:E(u({},_.InputProps),{endAdornment:o.jsxs(o.Fragment,{children:[e?o.jsx(r.CircularProgress,{color:"inherit",size:20,sx:{marginTop:"-20px"}}):null,_.InputProps.endAdornment]})})}))}),D&&o.jsx(r.FormHelperText,{error:!0,children:D})]})},Pe=()=>{const e=r.useTheme();return r.useMediaQuery(e.breakpoints.down("sm"))},Ft=64,kt=72,Et=256,G=w.atom(!0),Ie=w.atom(Et),Be=w.atom(kt),te=w.atom(""),Me=w.atom(void 0),Ne=w.atom(Ft),Le=w.atom(void 0);function _t({links:e}){return o.jsx("div",{children:"LinksMenu not implemented yet"})}const Q="Navbar",V={root:`${Q}-root`,menuButton:`${Q}-menuButton`,hide:`${Q}-hide`,content:`${Q}-content`},bt=L.styled(r.Box,{name:"NavBar"})(({theme:e})=>({[`&.${V.root}`]:{display:"flex"},[`& .${V.menuButton}`]:{marginRight:36},[`& .${V.hide}`]:{display:"none"},[`& .${V.content}`]:{flexGrow:1,padding:e.spacing(3)}})),q=(e,t,n)=>e.transitions.create(t,{easing:e.transitions.easing.sharp,duration:n==="leaving"?e.transitions.duration.leavingScreen:e.transitions.duration.enteringScreen}),Tt=e=>{const t=r.useTheme();return o.jsx(r.Collapse,u({easing:t.transitions.easing.sharp,timeout:{enter:t.transitions.duration.enteringScreen,exit:t.transitions.duration.leavingScreen}},e))},Oe=e=>{var t,n;return{overflowX:"hidden",color:"inherit",backgroundColor:(n=(t=e==null?void 0:e.navBar)==null?void 0:t.backgroundColor)!=null?n:"white"}},Ce=(e,t)=>u({width:t,transition:q(e,"width","entering")},Oe(e)),Se=(e,t)=>u({width:t,transition:q(e,"width","leaving")},Oe(e)),Pt=L.styled(r.Drawer,{shouldForwardProp:e=>!["widthOpen","widthClosed","isSmallScreen"].includes(e)})(({theme:e,open:t,widthOpen:n,widthClosed:i,isSmallScreen:s})=>u(u({flexShrink:0,whiteSpace:"nowrap",boxSizing:"border-box",display:"flex",flexDirection:"column"},t&&E(u({},Ce(e,n)),{backgroundColor:"","& .MuiDrawer-paper":Ce(e,n)})),!t&&E(u({},Se(e,s?n:i)),{backgroundColor:"","& .MuiDrawer-paper":Se(e,s?n:i)})));function $e(e){return e.replace(/(^|-)([a-z])/g,(t,n,i)=>n==="-"?" "+i.toUpperCase():i.toUpperCase())}function It(e,t,n,i){var p;if(!e)return"None";const s=e["https://greens.org.au/roles"];if(!s)return"None";const l=Object.entries(s).filter(([,a])=>a.includes(t)).map(([a])=>$e(a));return(p=i.find(a=>n[a].some(d=>l.includes(d))))!=null?p:"None"}function Re(e,t){return Object.entries(e).reduce((n,[i,s])=>{const l=$e(i),p=t.includes(l)?s:[];return[...new Set([...n,...p])]},[])}const Bt=e=>{const{getIdTokenClaims:t,user:n}=oe.useAuth0();return De.useQuery({queryKey:["availableDomains",n==null?void 0:n.sub],queryFn:()=>I(null,null,function*(){const i=yield t();if(!i)return[];const s=i["https://greens.org.au/roles"];return s?Re(s,e):[]})})},Mt=e=>Object.values(e).reduce((t,n)=>[...new Set([...t,...n])],[]),Y={log:console.warn.bind(console),error:console.error.bind(console),warn:console.warn.bind(console),info:console.info.bind(console),debug:console.debug.bind(console)};function Nt(e,t){console[e]=(...n)=>{for(const i of t)if(typeof i=="function"){if(i(...n))return}else if(i instanceof RegExp&&n.length>0){for(const s of n)if(typeof s=="string"&&i.test(s))return}Y[e](n)}}function Lt(e){if(e)console[e]=Y[e];else for(const t of Object.keys(Y))console[t]=Y[t]}function Ot(e,t){return e!=null&&typeof e=="object"&&"error"in e&&e.error===t}function $t(e,t){const n=t==null?void 0:t.originalException;return Ot(n,"login_required")?null:e}function qe(e){let t=0;for(let n=0,i=e.length;n<i;n++){const s=e.charCodeAt(n);t=(t<<5)-t+s,t|=0}return t}const ye=["#A62A21","#7e3794","#0B51C1","#3A6024","#A81563","#B3003C"],ve=e=>e.split(/\s/).map(t=>t.substring(0,1).toUpperCase()).filter(t=>!!t).slice(0,2).join("").toUpperCase();function Rt({user:e,domainCode:t,open:n,useNewAvatar:i=!1}){const s=r.useTheme();return o.jsxs(r.Box,{sx:{paddingTop:3,display:"flex",alignItems:"center",flexDirection:"column",gap:"0.5rem"},children:[!i&&o.jsx(r.Box,{sx:{width:n?"5rem":"2rem",transition:n?q(s,["width","height"],"entering"):q(s,["width","height"],"leaving"),aspectRatio:1},children:e!=null&&e.name?o.jsx(o.Fragment,{children:o.jsx(r.Avatar,{src:e==null?void 0:e.picture,sx:{width:"100%",height:"100%",bgcolor:ye[Math.abs(qe(e==null?void 0:e.name))%ye.length]},children:ve(e==null?void 0:e.name)})}):o.jsx(r.Avatar,{sx:{width:"100%",height:"100%"}})}),i&&o.jsx(r.Box,{sx:{width:n?"5rem":"2rem",transition:n?q(s,["width","height"],"entering"):q(s,["width","height"],"leaving"),aspectRatio:1},children:e!=null&&e.name?o.jsx(o.Fragment,{children:o.jsxs(me.default,{src:e==null?void 0:e.picture,name:e==null?void 0:e.name,round:!0,size:n?"80":"32",children:[" ",ve(e==null?void 0:e.name)," ","ab"]})}):o.jsx(me.default,{})}),o.jsx(Tt,{sx:{width:"100%"},in:n,children:o.jsx(r.Fade,{in:n,children:o.jsxs(r.Box,{width:"100%",display:"flex",flexDirection:"column",alignItems:"center",children:[e!=null&&e.name?o.jsx(r.Typography,{children:e==null?void 0:e.name}):o.jsx(r.Skeleton,{animation:!1,width:"50%"}),t?o.jsx(r.Typography,{children:ae(t)}):o.jsx(r.Skeleton,{animation:!1,width:"25%"})]})})})]})}function qt({open:e,widthClosed:t,widthOpen:n,"data-testid":i,top:s,middle:l,bottom:p,user:a,domainCode:d,useNewAvatar:c=!1}){const g=Pe(),A=w.useSetAtom(G);return o.jsx(bt,{className:V.root,"data-testid":i,children:o.jsxs(Pt,{open:e,widthOpen:n,widthClosed:t,anchor:"left",variant:g?"temporary":"permanent",PaperProps:{component:"nav"},onClose:()=>{A(!1)},isSmallScreen:g,children:[!g&&o.jsx(r.Toolbar,{}),s&&o.jsxs(r.Box,{flexGrow:"0",children:[s,o.jsx(r.Divider,{variant:"middle",sx:{marginY:"0.5rem"}})]}),o.jsx(r.Box,{flexGrow:"1",children:Array.isArray(l)?o.jsx(_t,{links:l}):l}),o.jsxs(r.Box,{flexGrow:"0",children:[o.jsx(r.Divider,{variant:"middle",sx:{marginY:"0.5rem"}}),o.jsx(Rt,{user:a,domainCode:d,open:e,useNewAvatar:c}),p&&o.jsx(o.Fragment,{children:p})]})]})})}function Ut({children:e,topBarHeight:t,maxWidth:n=!1,noPadding:i}){return o.jsx(r.Box,{sx:{overflow:"auto",height:`calc(100vh - ${t}px)`,flexGrow:1},children:i?o.jsx(r.Box,{height:"inherit",children:e}):o.jsx(r.Container,{maxWidth:n,sx:{paddingTop:3,paddingBottom:3,flexGrow:1},children:e})})}const Ht="TopBar",Wt={titleText:`${Ht}-titleText`};function zt({titleText:e="",height:t,"data-testid":n,middle:i,menuButtonAriaLabel:s="Open navigation menu"}){const l=w.useSetAtom(G),p=()=>l(c=>!c),a=r.useTheme(),d=Pe();return o.jsx("header",{"data-testid":n,children:o.jsxs(r.Paper,{square:!0,elevation:0,sx:{width:"100%",position:"sticky",color:"primary.contrastText",backgroundColor:"primary.main",display:"flex",alignItems:"center",gap:2,flexShrink:0,height:t,zIndex:d?0:a.zIndex.drawer+99},children:[o.jsx(r.IconButton,{size:"medium",color:"inherit",sx:{padding:1.5,marginLeft:"12px"},onClick:p,"aria-label":s,children:o.jsx(ee.ViewHeadline,{fontSize:"medium"})}),o.jsx(r.Typography,{className:Wt.titleText,variant:"h6",component:"h1",children:e}),i]})})}function Vt({children:e,initialTitleText:t,initialNavBarOpen:n,pageContainerProps:i,pageContentDataTestId:s,topBarDataTestId:l,menuButtonAriaLabel:p,navBarDataTestId:a,navBarMiddle:d,navBarBottom:c,user:g,domainCode:A,useNewAvatar:j=!1}){et.useHydrateAtoms([[G,n!=null?n:!0],[te,t!=null?t:""]]);const x=w.useAtomValue(G),[S]=w.useAtom(Ie),[k]=w.useAtom(Be),m=w.useAtomValue(te),[D]=w.useAtom(Ne),[_]=w.useAtom(Me),[T]=w.useAtom(Le);return o.jsxs(he.default,{children:[o.jsx(rt.default,{}),o.jsx(zt,{titleText:m,"data-testid":l,height:D,middle:_,menuButtonAriaLabel:p}),o.jsxs(he.default,{sx:{display:"flex"},children:[o.jsx(qt,{open:x,top:T,middle:d,bottom:c,user:g,domainCode:A,widthOpen:S,widthClosed:k,offsetTop:D,"data-testid":a,useNewAvatar:j}),o.jsx(Ut,E(u({"data-testid":s,topBarHeight:D},i),{children:e}))]})]})}const Gt=L.createTheme({palette:{primary:{dark:"#00A651",light:"#A3D39C",main:"#007236",contrastText:"#FFF"},warning:{main:"#F5871F",light:"#FCC589",dark:"#A2590A",contrastText:"#FFF"},secondary:{main:"#662D91",light:"#BD8CBF",dark:"#440E62",contrastText:"#FFF"},error:{main:"#D43C95",light:"#8F2064",dark:"#F9CDE0",contrastText:"#FFF"},info:{main:"#00A88D",light:"#ADDCCF",dark:"#005243",contrastText:"#FFF"},success:{main:"#00A651",light:"#A3D39C",dark:"#007236",contrastText:"#FFF"}},typography:{explainer:{fontSize:"14px",marginBlockStart:"1em"}},navBar:{backgroundColor:"#E8E8E8"}}),Xt=L.createTheme({palette:{primary:{main:"#007236",dark:"#005221",light:"#00A04E",contrastText:"#FFFFFF"},secondary:{main:"#662D91",dark:"#440E62",light:"#93268F",contrastText:"#FFFFFF"},error:{main:"#D32F2F",dark:"#C62828",light:"#EF5350"},info:{main:"#0288D1",dark:"#01579B",light:"#03A9F4"},success:{main:"#0288D1",dark:"#01579B",light:"#03A9F4"}},components:{MuiTextField:{defaultProps:{color:"secondary"}},MuiToggleButtonGroup:{defaultProps:{color:"secondary"}},MuiCheckbox:{defaultProps:{color:"secondary"}},MuiSelect:{defaultProps:{color:"secondary"}},MuiSwitch:{defaultProps:{color:"secondary"}},MuiFormControl:{defaultProps:{color:"secondary"}},MuiMenuItem:{styleOverrides:{root:({theme:e})=>({"&.Mui-selected":{backgroundColor:L.alpha(e.palette.secondary.main,e.palette.action.selectedOpacity),"&:hover":{backgroundColor:L.alpha(e.palette.secondary.main,e.palette.action.selectedOpacity)},"&.Mui-focusVisible":{backgroundColor:L.alpha(e.palette.secondary.main,e.palette.action.focusOpacity)}}})}}},typography:{h4:{fontSize:"1.88rem",fontWeight:500},h5:{fontWeight:500},explainer:{fontSize:"14px",marginBlockStart:"1em"}},navBar:{backgroundColor:"#E8E8E8"}});exports.AgDialog=ne;exports.AppLayout=Vt;exports.AuthGuard=xt;exports.Context=re;exports.ContextError=se;exports.DOMAIN_CODE_LABELS=Te;exports.DomainCodeDialog=wt;exports.ExampleComponent=st;exports.FetchAutocomplete=lt;exports.MUI_AUTOCOMPLETE_VALUE_WARNING_REGEX=ct;exports.SaladBarProvider=ke;exports.SessionExpiryDialog=ut;exports.SingleAutocomplete=dt;exports.determineUserLevelFromClaims=It;exports.domainCodeAtom=be;exports.fed21Theme=Gt;exports.getAuth0Expiry=Fe;exports.getDomainOptionLabel=ae;exports.getDomainsFromRolesClaim=Re;exports.getValidBusinessRoles=Mt;exports.internalAgSystemsTheme=Xt;exports.navBarOpenAtom=G;exports.navBarTopAtom=Le;exports.navBarWidthClosedAtom=Be;exports.navBarWidthOpenAtom=Ie;exports.sentryBeforeSend=$t;exports.simpleHashCode=qe;exports.suppressConsole=Nt;exports.titleTextAtom=te;exports.topBarHeightAtom=Ne;exports.topBarMiddleAtom=Me;exports.unsuppressConsole=Lt;exports.useAutocompleteOptions=ie;exports.useSaladBar=Ee;exports.useValidDomains=Bt;exports.withSaladBarProvider=Dt;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|