@australiangreens/ag-internal-components 0.3.5 → 0.3.7
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/README.md +2 -2
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/components/FetchAutocomplete/FetchAutocomplete.d.ts +5 -10
- package/dist/components/FetchAutocomplete/FetchAutocomplete.d.ts.map +1 -1
- package/dist/components/types.d.ts +5 -3
- package/dist/components/types.d.ts.map +1 -1
- package/dist/esm/index.js +389 -394
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Generally, all that will be needed is to use a theme provider with the
|
|
|
13
13
|
components:
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import {internalAgSystemsTheme} from '@
|
|
16
|
+
import {internalAgSystemsTheme} from '@australiangreens/ag-internal-components';
|
|
17
17
|
|
|
18
18
|
<ThemeProvider theme={fed21Theme}>
|
|
19
19
|
<App />
|
|
@@ -31,7 +31,7 @@ with `internalAgSystemsTheme` or just ensure all required properties in the
|
|
|
31
31
|
We are now at version 22 of node, with React 19 and Vite 7. We use pnpm for
|
|
32
32
|
development.
|
|
33
33
|
|
|
34
|
-
## Development with pnpm link
|
|
34
|
+
## Development with pnpm link
|
|
35
35
|
|
|
36
36
|
If you wish to give the latest version of `ag-internal-components` a red hot go with
|
|
37
37
|
your calling application (like ListManager), add this to its `package.json`, or
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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:(m,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((m,D)=>{var F;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)||y,color:m==null?void 0:m.buttonColor,children:(F=m.text)!=null?F:`Button ${D}`},D)}),a&&o.jsx(r.Button,{onClick:()=>I(null,null,function*(){var m;g(!0),yield(m=a.onClick)==null?void 0:m.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:m="",preLoadedOptions:D=void 0,disablePortal:F=!1,disableIconFlip:T=!1,chipToolTipSlotProps:H=it,isTemplatePlaceholder:M=!1,placeholderText:E=void 0,onRightClick:L=()=>{},disableDefaultRightClickBehaviour:B=!1}){const[$,N]=w.useState(""),S=(f,A)=>{const P=h.filter(K=>K.id!==A);n(P,"delete",f)},{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:f=>typeof f=="string"?f:f.label,loading:R?b:!1,options:[...h,...u!=null?u:[]],filterSelectedOptions:!0,includeInputInList:!0,value:h,onChange:(f,A,P)=>{n(A,P,f)},onInputChange:(f,A,P)=>{N(A),i&&i(h,P,f)},noOptionsText:R?g:"Start typing to search",loadingText:y,popupIcon:v,renderInput:f=>o.jsx(r.TextField,p(_(p({},f),{label:l,fullWidth:!0,variant:C,error:k,helperText:m,slotProps:{input:_(p({},f.InputProps),{endAdornment:M?void 0:o.jsxs(o.Fragment,{children:[b?o.jsx(r.CircularProgress,{color:"inherit",size:20}):null,f.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:(f,A)=>f.id===A.id,renderOption:(f,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({},f),{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({},f),{key:A.id,"data-testid":s?`${s}:option(${A.id.toString()})`:void 0}),A.label)},onMouseDownCapture:f=>{f.button===ve.right&&B&&(f.preventDefault(),f.stopPropagation())},onContextMenuCapture:f=>{B&&(f.preventDefault(),f.stopPropagation()),L(f)},readOnly:M}),h.length>0&&o.jsx(r.Box,{sx:c,children:h.map(f=>{var A;return o.jsx(r.Chip,{sx:{marginTop:1,marginRight:1,height:"auto"},label:o.jsx(r.Tooltip,{title:(A=f.tooltipContent)!=null?A:"",placement:"bottom-start",slotProps:H,children:o.jsx(r.Typography,{style:{whiteSpace:"normal"},children:f.chipLabel?f.chipLabel:f.label})}),"data-testid":s?`${s}:Chip(${f.id.toString()})`:void 0,onDelete:P=>S(P,f.id),deleteIcon:o.jsx(Y.Cancel,{"data-testid":s?`${s}:Chip(${f.id.toString()}):deleteIcon`:void 0})},f.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:m,disableIconFlip:D,isTemplatePlaceholder: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:m,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 ft={autoHideDuration:6e3,anchorOrigin:{vertical:"top",horizontal:"center"},disableWindowBlurListener:!1},mt={shouldClose:(e,t)=>t!=="clickaway"},pe={message:"",severity:"info",variant:"standard",progressIndicator:void 0},he=100,fe=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=mt.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>=fe&&(x.current=Date.now(),console.error(`SaladBarProvider: MAX_QUEUE_LENGTH (${he}) hit ${C.current} times in last ${fe}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)),m=(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({},ft),a),$=p(p({open:s,setOpen:y,enqueueNotification:g,enqueueSuccessNotification:v,enqueueInfoNotification:k,enqueueWarningNotification:m,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 me=j.atom(JSON.parse((Se=localStorage.getItem(ke))!=null?Se:'{"domainCode": ""}').domainCode),Fe=j.atom(e=>e(me),(e,t,n)=>{t(me,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(""))}),m=()=>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:m},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),[m]=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:m,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:m,"data-testid":h,useNewAvatar:C}),o.jsx(Ot,_(p({"data-testid":a,topBarHeight:m},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;
|
|
1
|
+
"use strict";var He=Object.defineProperty,We=Object.defineProperties;var Ve=Object.getOwnPropertyDescriptors;var z=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,de=Object.prototype.propertyIsEnumerable;var Y=(e,t,n)=>t in e?He(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,p=(e,t)=>{for(var n in t||(t={}))ce.call(t,n)&&Y(e,n,t[n]);if(z)for(var n of z(t))de.call(t,n)&&Y(e,n,t[n]);return e},b=(e,t)=>We(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&&z)for(var i of z(e))t.indexOf(i)<0&&de.call(e,i)&&(n[i]=e[i]);return n};var pe=(e,t,n)=>Y(e,typeof t!="symbol"?t+"":t,n);var P=(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"),J=require("@mui/icons-material"),ze=require("autosuggest-highlight/match"),Ge=require("autosuggest-highlight/parse"),we=require("@tanstack/react-query"),ee=require("@auth0/auth0-react"),Xe=require("buffer"),Ke=require("@mui/material/Skeleton"),j=require("jotai"),Qe=require("souvlaki"),Ye=require("@mui/material/CssBaseline"),Je=require("@mui/material/Box"),Ze=require("jotai/utils"),N=require("@mui/material/styles"),et=require("react-avatar"),q=e=>e&&e.__esModule?e:{default:e},tt=q(ze),ot=q(Ge),nt=q(Ke),it=q(Ye),he=q(Je),me=q(et);function rt({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 te=({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)=>P(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:()=>P(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})]})]})},st={popper:{modifiers:[{name:"offset",options:{offset:[115,-15]}}]}},De={right:2},oe=({minLength:e,preLoadedOptions:t,lookup:n,label:i,inputValue:a})=>we.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 at({lookup:e=()=>P(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",textFieldFocused:y,textFieldSx:g,loadingText:v="Loading...",noOptionsText:k="No options",popupIcon:f=o.jsx(J.ArrowDropDown,{}),error:D=!1,helperText:F="",preLoadedOptions:E=void 0,disablePortal:U=!1,disableIconFlip:L=!1,chipToolTipSlotProps:T=st,placeholderText:O=void 0,onRightClick:B=()=>{},disableDefaultRightClickBehaviour:$=!1,readOnly:M,hideInputEndAdornment:S}){const[u,_]=w.useState(""),H=(m,A)=>{const I=h.filter(Q=>Q.id!==A);n(I,"delete",m)},{data:K,isLoading:se}=oe({inputValue:u,label:l,lookup:e,minLength:a,preLoadedOptions:E}),ae=u.length>=a;return o.jsxs("div",{"data-testid":s,children:[o.jsx(r.Autocomplete,{sx:p(p({},d),L?{".MuiAutocomplete-popupIndicatorOpen":{transform:"rotate(0deg)"}}:{}),"data-testid":s?`${s}:Autocomplete`:void 0,disablePortal:U,multiple:!0,getOptionLabel:m=>typeof m=="string"?m:m.label,loading:ae?se:!1,options:[...h,...K!=null?K:[]],filterSelectedOptions:!0,includeInputInList:!0,value:h,onChange:(m,A,I)=>{n(A,I,m)},onInputChange:(m,A,I)=>{_(A),i&&i(h,I,m)},noOptionsText:ae?k:"Start typing to search",loadingText:v,popupIcon:f,renderInput:m=>o.jsx(r.TextField,b(p({},m),{label:l,fullWidth:!0,variant:C,error:D,helperText:F,slotProps:{input:b(p({},m.InputProps),{endAdornment:S?void 0:o.jsxs(o.Fragment,{children:[se?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:O,sx:g,focused:y})),renderValue:()=>null,isOptionEqualToValue:(m,A)=>m.id===A.id,renderOption:(m,A,I)=>{if(t){const Q=tt.default(A.label,I.inputValue,{insideWords:!0,findAllOccurrences:!0}),qe=ot.default(A.label,Q);return w.createElement("li",b(p({},m),{key:A.id,"data-testid":s?`${s}:Autocomplete:option(${A.id.toString()})`:void 0}),o.jsx("div",{children:qe.map((le,Ue)=>o.jsx("span",{style:{fontWeight:le.highlight?700:400},children:le.text},Ue))}))}else return w.createElement("li",b(p({},m),{key:A.id,"data-testid":s?`${s}:option(${A.id.toString()})`:void 0}),A.label)},onMouseDownCapture:m=>{m.button===De.right&&$&&(m.preventDefault(),m.stopPropagation())},onContextMenuCapture:m=>{$&&(m.preventDefault(),m.stopPropagation()),B(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:T,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:I=>H(I,m.id),deleteIcon:o.jsx(J.Cancel,{"data-testid":s?`${s}:Chip(${m.id.toString()}):deleteIcon`:void 0})},m.id)})})]})}const lt=/MUI: The value provided to.*is invalid/i,ct=({lookup:e=()=>P(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,isTemplatePlaceholder:F=!1,placeholderText:E=void 0,onRightClick:U=()=>{},disableDefaultRightClickBehaviour:L=!1})=>{const[T,O]=w.useState(""),{data:B,isLoading:$}=oe({inputValue:T,label:i,lookup:e,minLength:C!=null?C:0,preLoadedOptions:g}),M=T.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===De.right&&L&&(u.preventDefault(),u.stopPropagation())},onContextMenuCapture:u=>{L&&(u.preventDefault(),u.stopPropagation()),U(u)},children:o.jsx(r.Autocomplete,{sx:p(p({},l),D?{".MuiAutocomplete-popupIndicatorOpen":{transform:"rotate(0deg)"}}:{}),"data-testid":c?`${c}:Autocomplete`:void 0,loading:M?$:!1,options:B!=null?B:[],onChange:(u,_,H)=>{t(u,_,H)},disablePortal:y,filterOptions:u=>u,value:a,noOptionsText:M?x:"Start typing to search",getOptionLabel:u=>u.label,popupIcon:f,renderInput:u=>o.jsx(r.TextField,p(b(p({"data-testid":c?`${c}:Autocomplete:TextField`:void 0},u),{variant:s,label:i,color:h,error:d,helperText:v,placeholder:E!=null?E:F?"Placeholder field":void 0}),S)),isOptionEqualToValue:(u,_)=>u.id===_.id,onInputChange:(u,_,H)=>{O(_),n&&n(_,H,u)},renderOption:(u,_)=>w.createElement("li",b(p({},u),{key:_.id,"data-testid":c?`${c}:Autocomplete:option(${_.id.toString()})`:void 0}),_.label),disabled:k,readOnly:F})})})},ke=e=>{if(!e)return-1;try{const n=e.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),i=decodeURIComponent(Xe.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}},dt=({open:e=!1,closeHandler:t,setAuth0ExpiryTime:n})=>{const{logout:i,getAccessTokenSilently:a}=ee.useAuth0(),l=()=>P(null,null,function*(){i({logoutParams:{returnTo:`${window.location.origin}`}})}),s={text:"Continue",onClick:()=>P(null,null,function*(){const c=yield a({cacheMode:"off"}),x=ke(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(te,{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 ut(e){return"error"in e}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.startsWith("You do not have the required authorization")}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("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 ft({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}=ee.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(ut(s)){let g="Auth error",v="An unknown Auth0 error occurred.";if(pt(s))g="Unauthorised",v=`You are not authorised to access ${t}.`;else if(ht(s))g="App not authorised",v=`You have not authorised ${t} to access your user profile. This is necessary to use ${t}.`;else if(mt(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(nt.default,{variant:"rectangular",animation:"pulse",height:"100vh",width:"100vw"})}const gt={autoHideDuration:6e3,anchorOrigin:{vertical:"top",horizontal:"center"},disableWindowBlurListener:!1},xt={shouldClose:(e,t)=>t!=="clickaway"},fe={message:"",severity:"info",variant:"standard",progressIndicator:void 0},ge=100,xe=2e3,At=2e3,Ct=(()=>{let e=0;return()=>(e+=1,e)})(),St={borderBottomLeftRadius:"0px",borderBottomRightRadius:"0px"},yt={},vt={},ne=w.createContext(null);function Fe(l){var h=l,{overrideState:e=yt,overrideActions:t=vt,shouldClose:n=xt.shouldClose,children:i}=h,a=ue(h,["overrideState","overrideActions","shouldClose","children"]);var M;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>=ge&&Date.now()-x.current>=xe&&(x.current=Date.now(),console.error(`SaladBarProvider: MAX_QUEUE_LENGTH (${ge}) hit ${C.current} times in last ${xe}ms)`),C.current=0);const u=p(b(p({},fe),{key:Ct()}),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(_=>_.key===S);if(u!==-1)return u===0?(d({open:!1}),c.current[0]):c.current.splice(u,1)},E=(S,u)=>{n(S,u)&&d({open:!1})},U=()=>{},L=()=>{c.current.shift(),c.current.length>0&&d({open:!0})},T=(M=c.current[0])!=null?M:p({},fe),O={};"autoHideDuration"in T&&(O.autoHideDuration=T.autoHideDuration);const B=p(p({},gt),a),$=p(p({open:s,setOpen:y,enqueueNotification:g,enqueueSuccessNotification:v,enqueueInfoNotification:k,enqueueWarningNotification:f,enqueueErrorNotification:D,removeNotification:F},e),t);return o.jsxs(ne.Provider,{value:$,children:[i,o.jsx(r.Snackbar,b(p(p({},B),O),{open:s,onClose:E,TransitionProps:{onExited:L,onExit:U},sx:{zIndex:At},children:o.jsxs("div",{children:[o.jsx(r.Alert,{onClose:S=>E(S,"closeAlert"),severity:T.severity,variant:"filled",icon:T.progressIndicator==="circular"?o.jsx(r.CircularProgress,{size:"1em"}):void 0,style:T.progressIndicator==="linear"?St:void 0,children:T.message}),T.progressIndicator==="linear"&&o.jsx(r.LinearProgress,{color:"primary"})]})}))]})}class ie extends Error{}pe(ie,"errorName","ContextError");function be(){const e=w.useContext(ne);if(e===null)throw new ie("Error: Tried to useSaladBar outside of a <SaladBarProvider>");return e}const jt=Qe.createHelper((e={autoHideDuration:1},t={},n={})=>({children:i})=>o.jsx(Fe,b(p({},e),{overrideState:t,overrideActions:n,children:o.jsx(o.Fragment,{children:i})}))),_e="domainCode";var je;const Ae=j.atom(JSON.parse((je=localStorage.getItem(_e))!=null?je:'{"domainCode": ""}').domainCode),Ee=j.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","":""},re=e=>{var t;return e===null?"N/A":(t=Te[e])!=null?t:""},wt=({isLoading:e,isOpen:t,onClose:n,onDomainChange:i,domainOptions:a,applicationName:l,handleLogout:h})=>{const[s,d]=j.useAtom(Ee),[c,x]=w.useState(s),{enqueueSuccessNotification:C}=be(),y=a.length===0,g=!!s&&!a.includes(s)&&!a.includes(c),v=!s||y||g,k=()=>P(null,null,function*(){c?(d(c),i==null||i(c),C(`Set organisation to ${c}`),n()):(d(""),i==null||i(""))}),f=()=>P(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(te,{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,E)=>x(E!=null?E:""),getOptionLabel:re,options:[...a.toSorted()],renderInput:F=>o.jsx(r.TextField,b(p({},F),{variant:"filled",label:"Select organisation",InputProps:b(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})]})},Pe=()=>{const e=r.useTheme();return r.useMediaQuery(e.breakpoints.down("sm"))},Dt=64,kt=72,Ft=256,V=j.atom(!0),Ie=j.atom(Ft),Be=j.atom(kt),Z=j.atom(""),Me=j.atom(void 0),Ne=j.atom(Dt),Le=j.atom(void 0);function bt({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`},_t=N.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)}})),R=(e,t,n)=>e.transitions.create(t,{easing:e.transitions.easing.sharp,duration:n==="leaving"?e.transitions.duration.leavingScreen:e.transitions.duration.enteringScreen}),Et=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))},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)=>p({width:t,transition:R(e,"width","entering")},Oe(e)),Se=(e,t)=>p({width:t,transition:R(e,"width","leaving")},Oe(e)),Tt=N.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&&b(p({},Ce(e,n)),{backgroundColor:"","& .MuiDrawer-paper":Ce(e,n)})),!t&&b(p({},Se(e,a?n:i)),{backgroundColor:"","& .MuiDrawer-paper":Se(e,a?n:i)})));function $e(e){return e.replace(/(^|-)([a-z])/g,(t,n,i)=>n==="-"?" "+i.toUpperCase():i.toUpperCase())}function Pt(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 $e((d=s.split("/").at(-1))!=null?d:"")});return(h=i.find(s=>n[s].some(d=>l.includes(d))))!=null?h:"None"}const It=e=>{const{getIdTokenClaims:t,user:n}=ee.useAuth0();return we.useQuery({queryKey:["availableDomains",n==null?void 0:n.sub],queryFn:()=>P(null,null,function*(){const i=yield t();return i?Object.entries(i).reduce((a,[l,h])=>{var c;const s=$e((c=l.split("/").at(-1))!=null?c:""),d=l.startsWith("https://greens.org.au/roles/")&&e.includes(s)?h:[];return[...new Set([...a,...d])]},[]):[]})})},Bt=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 Nt(e){if(e)console[e]=X[e];else for(const t of Object.keys(X))console[t]=X[t]}function Re(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 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 Lt({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?R(a,["width","height"],"entering"):R(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:ye[Math.abs(Re(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?R(a,["width","height"],"entering"):R(a,["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(Et,{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:re(t)}):o.jsx(r.Skeleton,{animation:!1,width:"25%"})]})})})]})}function Ot({open:e,widthClosed:t,widthOpen:n,"data-testid":i,top:a,middle:l,bottom:h,user:s,domainCode:d,useNewAvatar:c=!1}){const x=Pe(),C=j.useSetAtom(V);return o.jsx(_t,{className:W.root,"data-testid":i,children:o.jsxs(Tt,{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(bt,{links:l}):l}),o.jsxs(r.Box,{flexGrow:"0",children:[o.jsx(r.Divider,{variant:"middle",sx:{marginY:"0.5rem"}}),o.jsx(Lt,{user:s,domainCode:d,open:e,useNewAvatar:c}),h&&o.jsx(o.Fragment,{children:h})]})]})})}function $t({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 Rt="TopBar",qt={titleText:`${Rt}-titleText`};function Ut({titleText:e="",height:t,"data-testid":n,middle:i}){const a=j.useSetAtom(V),l=()=>a(d=>!d),h=r.useTheme(),s=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: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(J.ViewHeadline,{fontSize:"medium"})}),o.jsx(r.Typography,{className:qt.titleText,variant:"h6",component:"h1",children:e}),i]})})}function Ht({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}){Ze.useHydrateAtoms([[V,n!=null?n:!0],[Z,t!=null?t:""]]);const y=j.useAtomValue(V),[g]=j.useAtom(Ie),[v]=j.useAtom(Be),k=j.useAtomValue(Z),[f]=j.useAtom(Ne),[D]=j.useAtom(Me),[F]=j.useAtom(Le);return o.jsxs(he.default,{children:[o.jsx(it.default,{}),o.jsx(Ut,{titleText:k,"data-testid":l,height:f,middle:D}),o.jsxs(he.default,{sx:{display:"flex"},children:[o.jsx(Ot,{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($t,b(p({"data-testid":a,topBarHeight:f},i),{children:e}))]})]})}const Wt=N.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"}}),Vt=N.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:N.alpha(e.palette.secondary.main,e.palette.action.selectedOpacity),"&:hover":{backgroundColor:N.alpha(e.palette.secondary.main,e.palette.action.selectedOpacity)},"&.Mui-focusVisible":{backgroundColor:N.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=te;exports.AppLayout=Ht;exports.AuthGuard=ft;exports.Context=ne;exports.ContextError=ie;exports.DOMAIN_CODE_LABELS=Te;exports.DomainCodeDialog=wt;exports.ExampleComponent=rt;exports.FetchAutocomplete=at;exports.MUI_AUTOCOMPLETE_VALUE_WARNING_REGEX=lt;exports.SaladBarProvider=Fe;exports.SessionExpiryDialog=dt;exports.SingleAutocomplete=ct;exports.determineUserLevelFromClaims=Pt;exports.domainCodeAtom=Ee;exports.fed21Theme=Wt;exports.getAuth0Expiry=ke;exports.getDomainOptionLabel=re;exports.getValidBusinessRoles=Bt;exports.internalAgSystemsTheme=Vt;exports.navBarOpenAtom=V;exports.navBarTopAtom=Le;exports.navBarWidthClosedAtom=Be;exports.navBarWidthOpenAtom=Ie;exports.simpleHashCode=Re;exports.suppressConsole=Mt;exports.titleTextAtom=Z;exports.topBarHeightAtom=Ne;exports.topBarMiddleAtom=Me;exports.unsuppressConsole=Nt;exports.useAutocompleteOptions=oe;exports.useSaladBar=be;exports.useValidDomains=It;exports.withSaladBarProvider=jt;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|