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