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