thecore-auth 0.0.39 → 0.0.40
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/thecore-auth.cjs.js +11 -11
- package/dist/thecore-auth.esm.js +328 -330
- package/package.json +1 -1
package/dist/thecore-auth.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),Dt=require("jwt-decode"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),Dt=require("jwt-decode"),K=require("react-router-dom"),$t=require("axios");var le={exports:{}},Q={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Je;function Lt(){if(Je)return
|
|
9
|
+
*/var Je;function Lt(){if(Je)return Q;Je=1;var t=d,n=Symbol.for("react.element"),o=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,c=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,u={key:!0,ref:!0,__self:!0,__source:!0};function p(v,f,b){var j,w={},R=null,_=null;b!==void 0&&(R=""+b),f.key!==void 0&&(R=""+f.key),f.ref!==void 0&&(_=f.ref);for(j in f)s.call(f,j)&&!u.hasOwnProperty(j)&&(w[j]=f[j]);if(v&&v.defaultProps)for(j in f=v.defaultProps,f)w[j]===void 0&&(w[j]=f[j]);return{$$typeof:n,type:v,key:R,ref:_,props:w,_owner:c.current}}return Q.Fragment=o,Q.jsx=p,Q.jsxs=p,Q}var ee={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,20 +14,20 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var Ke;function Ft(){return Ke||(Ke=1,process.env.NODE_ENV!=="production"&&function(){var t=d,n=Symbol.for("react.element"),o=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),c=Symbol.for("react.strict_mode"),u=Symbol.for("react.profiler"),p=Symbol.for("react.provider"),v=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),
|
|
18
|
-
`+ge+e}}var ve=!1,
|
|
19
|
-
`),
|
|
20
|
-
`),C=g.length-1,
|
|
21
|
-
`+g[C].replace(" at new "," at ");return e.displayName&&
|
|
17
|
+
*/var Ke;function Ft(){return Ke||(Ke=1,process.env.NODE_ENV!=="production"&&function(){var t=d,n=Symbol.for("react.element"),o=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),c=Symbol.for("react.strict_mode"),u=Symbol.for("react.profiler"),p=Symbol.for("react.provider"),v=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),b=Symbol.for("react.suspense"),j=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),R=Symbol.for("react.lazy"),_=Symbol.for("react.offscreen"),I=Symbol.iterator,D="@@iterator";function P(e){if(e===null||typeof e!="object")return null;var r=I&&e[I]||e[D];return typeof r=="function"?r:null}var x=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function E(e){{for(var r=arguments.length,a=new Array(r>1?r-1:0),l=1;l<r;l++)a[l-1]=arguments[l];$("error",e,a)}}function $(e,r,a){{var l=x.ReactDebugCurrentFrame,m=l.getStackAddendum();m!==""&&(r+="%s",a=a.concat([m]));var y=a.map(function(h){return String(h)});y.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,y)}}var T=!1,U=!1,H=!1,A=!1,L=!1,M;M=Symbol.for("react.module.reference");function F(e){return!!(typeof e=="string"||typeof e=="function"||e===s||e===u||L||e===c||e===b||e===j||A||e===_||T||U||H||typeof e=="object"&&e!==null&&(e.$$typeof===R||e.$$typeof===w||e.$$typeof===p||e.$$typeof===v||e.$$typeof===f||e.$$typeof===M||e.getModuleId!==void 0))}function ne(e,r,a){var l=e.displayName;if(l)return l;var m=r.displayName||r.name||"";return m!==""?a+"("+m+")":a}function V(e){return e.displayName||"Context"}function z(e){if(e==null)return null;if(typeof e.tag=="number"&&E("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case s:return"Fragment";case o:return"Portal";case u:return"Profiler";case c:return"StrictMode";case b:return"Suspense";case j:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case v:var r=e;return V(r)+".Consumer";case p:var a=e;return V(a._context)+".Provider";case f:return ne(e,e.render,"ForwardRef");case w:var l=e.displayName||null;return l!==null?l:z(e.type)||"Memo";case R:{var m=e,y=m._payload,h=m._init;try{return z(h(y))}catch{return null}}}return null}var W=Object.assign,X=0,Ce,Se,Re,Te,_e,Pe,Oe;function ke(){}ke.__reactDisabledLog=!0;function lt(){{if(X===0){Ce=console.log,Se=console.info,Re=console.warn,Te=console.error,_e=console.group,Pe=console.groupCollapsed,Oe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ke,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}X++}}function ct(){{if(X--,X===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:W({},e,{value:Ce}),info:W({},e,{value:Se}),warn:W({},e,{value:Re}),error:W({},e,{value:Te}),group:W({},e,{value:_e}),groupCollapsed:W({},e,{value:Pe}),groupEnd:W({},e,{value:Oe})})}X<0&&E("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var de=x.ReactCurrentDispatcher,ge;function oe(e,r,a){{if(ge===void 0)try{throw Error()}catch(m){var l=m.stack.trim().match(/\n( *(at )?)/);ge=l&&l[1]||""}return`
|
|
18
|
+
`+ge+e}}var ve=!1,ae;{var ut=typeof WeakMap=="function"?WeakMap:Map;ae=new ut}function Ae(e,r){if(!e||ve)return"";{var a=ae.get(e);if(a!==void 0)return a}var l;ve=!0;var m=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var y;y=de.current,de.current=null,lt();try{if(r){var h=function(){throw Error()};if(Object.defineProperty(h.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(h,[])}catch(k){l=k}Reflect.construct(e,[],h)}else{try{h.call()}catch(k){l=k}e.call(h.prototype)}}else{try{throw Error()}catch(k){l=k}e()}}catch(k){if(k&&l&&typeof k.stack=="string"){for(var g=k.stack.split(`
|
|
19
|
+
`),O=l.stack.split(`
|
|
20
|
+
`),C=g.length-1,S=O.length-1;C>=1&&S>=0&&g[C]!==O[S];)S--;for(;C>=1&&S>=0;C--,S--)if(g[C]!==O[S]){if(C!==1||S!==1)do if(C--,S--,S<0||g[C]!==O[S]){var N=`
|
|
21
|
+
`+g[C].replace(" at new "," at ");return e.displayName&&N.includes("<anonymous>")&&(N=N.replace("<anonymous>",e.displayName)),typeof e=="function"&&ae.set(e,N),N}while(C>=1&&S>=0);break}}}finally{ve=!1,de.current=y,ct(),Error.prepareStackTrace=m}var q=e?e.displayName||e.name:"",B=q?oe(q):"";return typeof e=="function"&&ae.set(e,B),B}function ft(e,r,a){return Ae(e,!1)}function dt(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function se(e,r,a){if(e==null)return"";if(typeof e=="function")return Ae(e,dt(e));if(typeof e=="string")return oe(e);switch(e){case b:return oe("Suspense");case j:return oe("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case f:return ft(e.render);case w:return se(e.type,r,a);case R:{var l=e,m=l._payload,y=l._init;try{return se(y(m),r,a)}catch{}}}return""}var Z=Object.prototype.hasOwnProperty,Ie={},Ne=x.ReactDebugCurrentFrame;function ie(e){if(e){var r=e._owner,a=se(e.type,e._source,r?r.type:null);Ne.setExtraStackFrame(a)}else Ne.setExtraStackFrame(null)}function gt(e,r,a,l,m){{var y=Function.call.bind(Z);for(var h in e)if(y(e,h)){var g=void 0;try{if(typeof e[h]!="function"){var O=Error((l||"React class")+": "+a+" type `"+h+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[h]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw O.name="Invariant Violation",O}g=e[h](r,h,l,a,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(C){g=C}g&&!(g instanceof Error)&&(ie(m),E("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",l||"React class",a,h,typeof g),ie(null)),g instanceof Error&&!(g.message in Ie)&&(Ie[g.message]=!0,ie(m),E("Failed %s type: %s",a,g.message),ie(null))}}}var vt=Array.isArray;function pe(e){return vt(e)}function pt(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,a=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return a}}function ht(e){try{return De(e),!1}catch{return!0}}function De(e){return""+e}function $e(e){if(ht(e))return E("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",pt(e)),De(e)}var Le=x.ReactCurrentOwner,mt={key:!0,ref:!0,__self:!0,__source:!0},Fe,Me;function bt(e){if(Z.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function xt(e){if(Z.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function yt(e,r){typeof e.ref=="string"&&Le.current}function Et(e,r){{var a=function(){Fe||(Fe=!0,E("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};a.isReactWarning=!0,Object.defineProperty(e,"key",{get:a,configurable:!0})}}function jt(e,r){{var a=function(){Me||(Me=!0,E("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};a.isReactWarning=!0,Object.defineProperty(e,"ref",{get:a,configurable:!0})}}var wt=function(e,r,a,l,m,y,h){var g={$$typeof:n,type:e,key:r,ref:a,props:h,_owner:y};return g._store={},Object.defineProperty(g._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(g,"_self",{configurable:!1,enumerable:!1,writable:!1,value:l}),Object.defineProperty(g,"_source",{configurable:!1,enumerable:!1,writable:!1,value:m}),Object.freeze&&(Object.freeze(g.props),Object.freeze(g)),g};function Ct(e,r,a,l,m){{var y,h={},g=null,O=null;a!==void 0&&($e(a),g=""+a),xt(r)&&($e(r.key),g=""+r.key),bt(r)&&(O=r.ref,yt(r,m));for(y in r)Z.call(r,y)&&!mt.hasOwnProperty(y)&&(h[y]=r[y]);if(e&&e.defaultProps){var C=e.defaultProps;for(y in C)h[y]===void 0&&(h[y]=C[y])}if(g||O){var S=typeof e=="function"?e.displayName||e.name||"Unknown":e;g&&Et(h,S),O&&jt(h,S)}return wt(e,g,O,m,l,Le.current,h)}}var he=x.ReactCurrentOwner,ze=x.ReactDebugCurrentFrame;function Y(e){if(e){var r=e._owner,a=se(e.type,e._source,r?r.type:null);ze.setExtraStackFrame(a)}else ze.setExtraStackFrame(null)}var me;me=!1;function be(e){return typeof e=="object"&&e!==null&&e.$$typeof===n}function We(){{if(he.current){var e=z(he.current.type);if(e)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+e+"`."}return""}}function St(e){return""}var
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function St(e){return""}var Be={};function Rt(e){{var r=We();if(!r){var a=typeof e=="string"?e:e.displayName||e.name;a&&(r=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+a+">.")}return r}}function
|
|
25
|
+
Check the top-level render call using <`+a+">.")}return r}}function Ue(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var a=Rt(r);if(Be[a])return;Be[a]=!0;var l="";e&&e._owner&&e._owner!==he.current&&(l=" It was passed a child from "+z(e._owner.type)+"."),Y(e),E('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',a,l),Y(null)}}function Ve(e,r){{if(typeof e!="object")return;if(pe(e))for(var a=0;a<e.length;a++){var l=e[a];be(l)&&Ue(l,r)}else if(be(e))e._store&&(e._store.validated=!0);else if(e){var m=P(e);if(typeof m=="function"&&m!==e.entries)for(var y=m.call(e),h;!(h=y.next()).done;)be(h.value)&&Ue(h.value,r)}}}function Tt(e){{var r=e.type;if(r==null||typeof r=="string")return;var a;if(typeof r=="function")a=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===f||r.$$typeof===w))a=r.propTypes;else return;if(a){var l=z(r);gt(a,e.props,"prop",l,e)}else if(r.PropTypes!==void 0&&!me){me=!0;var m=z(r);E("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",m||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&E("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function _t(e){{for(var r=Object.keys(e.props),a=0;a<r.length;a++){var l=r[a];if(l!=="children"&&l!=="key"){Y(e),E("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",l),Y(null);break}}e.ref!==null&&(Y(e),E("Invalid attribute `ref` supplied to `React.Fragment`."),Y(null))}}var Ye={};function qe(e,r,a,l,m,y){{var h=F(e);if(!h){var g="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(g+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var O=St();O?g+=O:g+=We();var C;e===null?C="null":pe(e)?C="array":e!==void 0&&e.$$typeof===n?(C="<"+(z(e.type)||"Unknown")+" />",g=" Did you accidentally export a JSX literal instead of a component?"):C=typeof e,E("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",C,g)}var S=Ct(e,r,a,m,y);if(S==null)return S;if(h){var N=r.children;if(N!==void 0)if(l)if(pe(N)){for(var q=0;q<N.length;q++)Ve(N[q],e);Object.freeze&&Object.freeze(N)}else E("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ve(N,e)}if(Z.call(r,"key")){var B=z(e),k=Object.keys(r).filter(function(Nt){return Nt!=="key"}),xe=k.length>0?"{key: someKey, "+k.join(": ..., ")+": ...}":"{key: someKey}";if(!Ye[B+xe]){var It=k.length>0?"{"+k.join(": ..., ")+": ...}":"{}";E(`A props object containing a "key" prop is being spread into JSX:
|
|
26
26
|
let props = %s;
|
|
27
27
|
<%s {...props} />
|
|
28
28
|
React keys must be passed directly to JSX without using spread:
|
|
29
29
|
let props = %s;
|
|
30
|
-
<%s key={someKey} {...props} />`,xe,
|
|
30
|
+
<%s key={someKey} {...props} />`,xe,B,It,B),Ye[B+xe]=!0}}return e===s?_t(S):Tt(S),S}}function Pt(e,r,a){return qe(e,r,a,!0)}function Ot(e,r,a){return qe(e,r,a,!1)}var kt=Ot,At=Pt;ee.Fragment=s,ee.jsx=kt,ee.jsxs=At}()),ee}var Ge;function Mt(){return Ge||(Ge=1,process.env.NODE_ENV==="production"?le.exports=Lt():le.exports=Ft()),le.exports}var i=Mt();const Ze=d.createContext(),zt=({children:t})=>{const[n,o]=d.useState(!1);return i.jsx(Ze.Provider,{value:{isLoading:n,setIsLoading:o},children:t})},je=()=>{const t=d.useContext(Ze);if(t===void 0)throw new Error("Non puoi settare il loading");return t},Qe=({errorMessage:t,errorShow:n})=>i.jsx("section",{className:n?"":"hidden",children:i.jsxs("div",{className:"container mx-auto",children:[i.jsx("h1",{className:"text-center text-8xl my-12",children:"Errore"}),i.jsx("pre",{className:"text-xl",children:t})]})}),et=d.createContext(),Wt=({children:t})=>{const[n,o]=d.useState({}),[s,c]=d.useState(!1),u=`Creare un file config.json in public per il corretto funzionamento
|
|
31
31
|
Esempio di config.json:
|
|
32
32
|
|
|
33
33
|
{
|
|
@@ -44,4 +44,4 @@ Esempio di config.json:
|
|
|
44
44
|
"defaultMessage": ""
|
|
45
45
|
},
|
|
46
46
|
"clearLoginFormOnError":
|
|
47
|
-
}`,p=async()=>{try{const f=await(await fetch("/config.json")).json();o(f)}catch(v){console.error(v),c(!0)}};return d.useEffect(()=>{p()},[]),Object.keys(n).length===0?i.jsx(Qe,{errorShow:s,errorMessage:u}):i.jsx(et.Provider,{value:n,children:t})},ce=()=>{const t=d.useContext(et);if(t===void 0)throw new Error("Non puoi leggere i config");return t},tt=d.createContext(),Vt=({children:t})=>{const[n,o]=d.useState(!1),[s,c]=d.useState(),[u,p]=d.useState(),v={showAlert:n,setShowAlert:o,typeAlert:s,setTypeAlert:c,messageAlert:u,setMessageAlert:p};return i.jsx(tt.Provider,{value:v,children:t})},K=()=>{const t=d.useContext(tt);if(t===void 0)throw new Error("Non puoi modificare l'alert");return t};let q;const Q=async(t,n,o)=>{if(q)return q;try{const c=await(await fetch("/config.json")).json(),u=c.baseUri,{unauthorized:p,notFound:v,defaultMessage:f}=c.axiosErrors;return q=$t.create({baseURL:u,timeout:5e3}),q.interceptors.request.use(x=>x),q.interceptors.response.use(x=>x,x=>{if(x.response)switch(t(!0),n("danger"),x.response.status){case 401:localStorage.removeItem("accessToken"),o(p);break;case 404:o(v);break;default:o(`${f} ${x.response.status} ${x.response.data.error}`)}return Promise.reject(x)}),q}catch(s){console.error(s)}},rt=d.createContext(),Bt=({children:t})=>{const{heartbeatEndpoint:n,infiniteSession:o,timeDeducted:s,authenticatedEndpoint:c}=ce(),{setIsLoading:u}=je(),{setShowAlert:p,setMessageAlert:v,setTypeAlert:f}=K(),x=J.useNavigate(),[j,w]=d.useState(null),[S,T]=d.useState(),[k,$]=d.useState(),[P,m]=d.useState(),E=async(A,L)=>{A.preventDefault();try{u(!0),p(!1);const F=await(await Q(p,f,v)).post(c,{auth:L}),te=F.data.id,B=F.headers.token;B&&(localStorage.setItem("accessToken",B),localStorage.setItem("id",te),w(!0),T(B),x(`/dashboard/${te}`))}catch(M){console.error(M),u(!1)}},N=()=>{localStorage.removeItem("accessToken"),localStorage.removeItem("id"),w(!1),T(null)},D=async()=>{try{const A=localStorage.getItem("accessToken"),F=(await(await Q(p,f,v)).get(`${n}`,{headers:{Authorization:A}})).headers.token;localStorage.setItem("accessToken",F),T(F)}catch(A){console.error(A),N()}},ue=()=>{if(!S)return;const L=Dt(S).exp,M=Math.floor(Date.now()/1e3),F=(L-M)*1e3;m(F),$(F-s)};d.useEffect(()=>{if(localStorage.getItem("accessToken"))w(!0);else{w(!1);return}},[]),d.useEffect(()=>{ue();let A;o&&S&&k&&(A=setInterval(()=>{D()},k));let L;return!o&&S&&P&&(L=setTimeout(()=>{N(),p(!0),f("danger"),v("Sessione scaduta")},P)),()=>{A&&clearInterval(A),L&&clearTimeout(L)}},[S,k]);const fe={isAuthenticated:j,setIsAuthenticated:w,login:E,logout:N,setCurrentToken:T};return i.jsx(rt.Provider,{value:fe,children:t})},we=()=>{const t=d.useContext(rt);if(t===void 0)throw new Error("Non sei dentro al Auth Provider");return t},Ut=()=>{const{isAuthenticated:t}=we(),{setShowAlert:n,setTypeAlert:o,setMessageAlert:s}=K(),c=localStorage.getItem("accessToken");return d.useEffect(()=>{!t&&!c&&(n(!0),o("danger"),s("Non sei autorizzato"))},[]),t===null?null:t?i.jsx(J.Outlet,{}):i.jsx(J.Navigate,{to:"/"})};var nt={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},He=d.createContext&&d.createContext(nt),Yt=["attr","size","title"];function qt(t,n){if(t==null)return{};var o=Jt(t,n),s,c;if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(t);for(c=0;c<u.length;c++)s=u[c],!(n.indexOf(s)>=0)&&Object.prototype.propertyIsEnumerable.call(t,s)&&(o[s]=t[s])}return o}function Jt(t,n){if(t==null)return{};var o={};for(var s in t)if(Object.prototype.hasOwnProperty.call(t,s)){if(n.indexOf(s)>=0)continue;o[s]=t[s]}return o}function ie(){return ie=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var o=arguments[n];for(var s in o)Object.prototype.hasOwnProperty.call(o,s)&&(t[s]=o[s])}return t},ie.apply(this,arguments)}function Xe(t,n){var o=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);n&&(s=s.filter(function(c){return Object.getOwnPropertyDescriptor(t,c).enumerable})),o.push.apply(o,s)}return o}function le(t){for(var n=1;n<arguments.length;n++){var o=arguments[n]!=null?arguments[n]:{};n%2?Xe(Object(o),!0).forEach(function(s){Kt(t,s,o[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):Xe(Object(o)).forEach(function(s){Object.defineProperty(t,s,Object.getOwnPropertyDescriptor(o,s))})}return t}function Kt(t,n,o){return n=Gt(n),n in t?Object.defineProperty(t,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[n]=o,t}function Gt(t){var n=Ht(t,"string");return typeof n=="symbol"?n:n+""}function Ht(t,n){if(typeof t!="object"||!t)return t;var o=t[Symbol.toPrimitive];if(o!==void 0){var s=o.call(t,n||"default");if(typeof s!="object")return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(t)}function ot(t){return t&&t.map((n,o)=>d.createElement(n.tag,le({key:o},n.attr),ot(n.child)))}function ee(t){return n=>d.createElement(Xt,ie({attr:le({},t.attr)},n),ot(t.child))}function Xt(t){var n=o=>{var{attr:s,size:c,title:u}=t,p=qt(t,Yt),v=c||o.size||"1em",f;return o.className&&(f=o.className),t.className&&(f=(f?f+" ":"")+t.className),d.createElement("svg",ie({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},o.attr,s,p,{className:f,style:le(le({color:t.color||o.color},o.style),t.style),height:v,width:v,xmlns:"http://www.w3.org/2000/svg"}),u&&d.createElement("title",null,u),t.children)};return He!==void 0?d.createElement(He.Consumer,null,o=>n(o)):n(nt)}function Zt(t){return ee({tag:"svg",attr:{version:"1.1",viewBox:"0 0 16 16"},child:[{tag:"path",attr:{d:"M8 0c-4.355 0-7.898 3.481-7.998 7.812 0.092-3.779 2.966-6.812 6.498-6.812 3.59 0 6.5 3.134 6.5 7 0 0.828 0.672 1.5 1.5 1.5s1.5-0.672 1.5-1.5c0-4.418-3.582-8-8-8zM8 16c4.355 0 7.898-3.481 7.998-7.812-0.092 3.779-2.966 6.812-6.498 6.812-3.59 0-6.5-3.134-6.5-7 0-0.828-0.672-1.5-1.5-1.5s-1.5 0.672-1.5 1.5c0 4.418 3.582 8 8 8z"},child:[]}]})(t)}const at=()=>i.jsxs("div",{className:"fixed top-0 bottom-0 left-0 right-0 flex items-center justify-center bg-[#00000080]",children:[i.jsx(Zt,{className:"text-[20rem] relative animate-spin text-white"}),i.jsx("p",{className:"text-white text-2xl select-none absolute",children:"Loading..."})]});function Qt(t){return ee({tag:"svg",attr:{viewBox:"0 0 15 15",fill:"none"},child:[{tag:"path",attr:{fillRule:"evenodd",clipRule:"evenodd",d:"M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z",fill:"currentColor"},child:[]}]})(t)}function er(t){return ee({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm32 664c0 4.4-3.6 8-8 8h-48c-4.4 0-8-3.6-8-8V456c0-4.4 3.6-8 8-8h48c4.4 0 8 3.6 8 8v272zm-32-344a48.01 48.01 0 0 1 0-96 48.01 48.01 0 0 1 0 96z"},child:[]}]})(t)}function tr(t){return ee({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M955.7 856l-416-720c-6.2-10.7-16.9-16-27.7-16s-21.6 5.3-27.7 16l-416 720C56 877.4 71.4 904 96 904h832c24.6 0 40-26.6 27.7-48zM480 416c0-4.4 3.6-8 8-8h48c4.4 0 8 3.6 8 8v184c0 4.4-3.6 8-8 8h-48c-4.4 0-8-3.6-8-8V416zm32 352a48.01 48.01 0 0 1 0-96 48.01 48.01 0 0 1 0 96z"},child:[]}]})(t)}function rr(t){return ee({tag:"svg",attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M17.47 250.9C88.82 328.1 158 397.6 224.5 485.5c72.3-143.8 146.3-288.1 268.4-444.37L460 26.06C356.9 135.4 276.8 238.9 207.2 361.9c-48.4-43.6-126.62-105.3-174.38-137z"},child:[]}]})(t)}const st=()=>{const{showAlert:t,setShowAlert:n,messageAlert:o,typeAlert:s}=K(),{alertTimeout:c}=ce(),[u,p]=d.useState(0),v={danger:{bgColor:"bg-red-50",textColor:"text-red-700",buttonBg:"bg-red-50",hoverBg:"hover:bg-red-200",focusRing:"focus:ring-red-400",progressColor:"bg-red-400"},info:{bgColor:"bg-blue-50",textColor:"text-blue-700",buttonBg:"bg-blue-50",hoverBg:"hover:bg-blue-200",focusRing:"focus:ring-blue-400",progressColor:"bg-blue-400"},success:{bgColor:"bg-green-50",textColor:"text-green-700",buttonBg:"bg-green-50",hoverBg:"hover:bg-green-200",focusRing:"focus:ring-green-400",progressColor:"bg-green-400"}},{bgColor:f,textColor:x,buttonBg:j,hoverBg:w,focusRing:S,progressColor:T}=v[s],k=P=>{switch(P){case"danger":return i.jsx(tr,{className:"text-xl"});case"info":return i.jsx(er,{className:"text-xl"});case"success":return i.jsx(rr,{className:"text-xl"})}},$=()=>{n(!t)};return d.useEffect(()=>{let P;const E=100/(c/100);P=setInterval(()=>{p(D=>D>=100?(clearInterval(P),100):D+E)},100);const N=setTimeout(()=>{$()},c);return()=>{clearTimeout(N),clearInterval(P)}},[]),i.jsxs("div",{className:`flex items-center p-4 pt-6 ${x} rounded-lg ${f} mx-auto fixed top-[calc(100vh-100px)] right-10`,role:"alert",children:[i.jsx("div",{className:"w-full bg-gray-200 rounded-t-lg overflow-hidden h-2.5 dark:bg-gray-700 absolute top-0 left-0 right-0",children:i.jsx("div",{className:`${T} h-2.5 rounded-t-lg`,style:{width:`${u}%`}})}),k(s),i.jsx("div",{className:"px-4 text-sm font-medium",children:o}),i.jsx("button",{type:"button",className:`ms-auto ${j} rounded-lg focus:ring-2 ${S} p-1.5 ${w} inline-flex items-center justify-center h-8 w-8 cursor-pointer`,title:"Close",onClick:$,children:i.jsx(Qt,{className:"text-xl"})})]})},nr=()=>{const{isLoading:t}=je(),{showAlert:n}=K();return i.jsxs(i.Fragment,{children:[t&&i.jsx(at,{}),i.jsxs("main",{className:t?"hidden":"",children:[n&&i.jsx(st,{}),i.jsx(J.Outlet,{})]})]})},ye=t=>{const{inputType:n,inputId:o,inputPlaceholder:s,inputRequired:c,inputValue:u,inputChange:p}=t,f=["text","email","password","search","tel","url"].includes(n)?n:"text";return i.jsx("input",{type:f,id:o,className:"bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5",placeholder:s,required:c??!0,value:u,onChange:p})},Ee=({label:t,labelId:n,labelStyle:o})=>i.jsx("label",{htmlFor:n,className:`${o??"block mb-2 text-sm font-medium text-gray-900"}`,children:t}),it=t=>{const{formStyle:n,userData:o,userInput:s,title:c,buttonStyle:u,formData:p,changeValue:v,submitForm:f}=t;return i.jsxs("form",{onSubmit:f,className:`${n.size} ${n.rounded} ${n.shadow} ${n.bgColor}`,children:[i.jsx("h1",{className:`${c.size} ${c.position} ${c.spacing}`,children:c.text}),i.jsxs("div",{className:"flex justify-center flex-col gap-1 my-4 w-1/2 mx-auto",children:[i.jsx(Ee,{labelId:"user-email",label:s.label}),i.jsx(ye,{inputType:s.label,inputId:"user-email",inputPlaceholder:s.placeholder,inputValue:o?p[o]:p.email,inputChange:x=>{v(o||"email",x.target.value)}})]}),i.jsxs("div",{className:"flex justify-center flex-col gap-1 my-4 w-1/2 mx-auto",children:[i.jsx(Ee,{labelId:"password",label:"Password"}),i.jsx(ye,{inputType:"password",inputId:"password",inputPlaceholder:"Password",inputValue:p.password,inputChange:x=>{v("password",x.target.value)}})]}),i.jsx("div",{className:`flex ${u.position} items-center ${u.spacing}`,children:i.jsx("button",{className:`${u.color} ${u.hoverColor} ${u.textColor} font-bold cursor-pointer ${u.size} ${u.rounded}`,children:u.text})})]})},or=t=>{const{formStyle:n={size:"w-[800px]",bgColor:"bg-slate-50",rounded:"rounded-lg",shadow:"shadow-lg"},userData:o,userInput:s={label:"Email",type:"email",placeholder:"email@email.it"},title:c={text:"Login",size:"text-4xl",position:"text-center",spacing:"my-12"},buttonStyle:u={position:"justify-center",spacing:"my-12",color:"bg-blue-500",hoverColor:"hover:bg-blue-700",textColor:"text-white",size:"py-2 px-4",rounded:"rounded-full",text:"Login"}}=t,{login:p}=we(),{setShowAlert:v,setTypeAlert:f,setMessageAlert:x}=K(),{clearLoginFormOnError:j}=ce(),w=J.useNavigate(),S={email:"",password:""},[T,k]=d.useState(S),$=(m,E)=>{k(N=>({...N,[m]:E}))},P=m=>{p(m,T),j&&k(S)};return d.useEffect(()=>{const m=localStorage.getItem("id");localStorage.getItem("accessToken")&&m&&(w(`/dashboard/${m}`),v(!0),f("info"),x("Sei già loggato"))},[]),i.jsx("section",{children:i.jsx("div",{className:"container mx-auto flex items-center justify-center h-screen",children:i.jsx(it,{submitForm:P,formData:T,changeValue:$,formStyle:n,userData:o,userInput:s,title:c,buttonStyle:u})})})},ar=()=>{const{id:t}=J.useParams(),{logout:n,setCurrentToken:o}=we(),{usersEndpoint:s}=ce(),{setIsLoading:c}=je(),{setShowAlert:u,setTypeAlert:p,setMessageAlert:v}=K(),[f,x]=d.useState({}),[j,w]=d.useState(null),[S,T]=d.useState(!1),k=async()=>{try{c(!0);const m=localStorage.getItem("accessToken");if(!m){n(),u(!0),p("danger"),v("Sessione scaduta");return}o(m);const D=(await(await Q(u,p,v)).get(`${s}${t}`,{headers:{Authorization:m}})).data;x(D),c(!1)}catch(m){console.error(m),c(!1),n()}},$=async()=>{try{T(!0);const m=localStorage.getItem("accessToken");if(!m){n(),u(!0),p("danger"),v("Sessione scaduta");return}const D=(await(await Q(u,p,v)).get(`${s}`,{headers:{Authorization:m}})).data;w(D),D&&T(!1)}catch(m){console.error(m),c(!1),m.status===401&&n(),T(!1)}},P=()=>{n(),u(!0),p("info"),v("Hai effettuato il logout")};return d.useEffect(()=>{k()},[]),i.jsx("section",{children:i.jsxs("div",{className:"container mx-auto py-8",children:[i.jsxs("div",{className:"flex items-center justify-center gap-8 h-20",children:[i.jsxs("h1",{className:"text-4xl text-center text-slate-800",children:["Email: ",f.email]}),i.jsx("button",{onClick:P,className:"bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded-full cursor-pointer",children:"Logout"})]}),i.jsx("div",{className:"flex justify-center items-center my-12",children:i.jsx("button",{onClick:$,className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full disabled:bg-blue-300 disabled:text-gray-500 disabled:cursor-not-allowed cursor-pointer",disabled:S,children:"Lista degli utenti"})}),i.jsx("div",{className:"flex justify-center items-center",children:j&&i.jsx("ul",{children:j.map(m=>i.jsxs("li",{className:"text-xl my-4",children:[m.id," - ",m.email]},`user-${m.id}`))})})]})})};exports.Alert=st;exports.AlertProvider=Vt;exports.AuthPage=Ut;exports.AuthProvider=Bt;exports.ConfigProvider=Wt;exports.Dashboard=ar;exports.DefaultLayout=nr;exports.ErrorPage=Qe;exports.Input=ye;exports.InputLabel=Ee;exports.Loading=at;exports.LoadingProvider=zt;exports.Login=or;exports.LoginForm=it;exports.fetchAxiosConfig=Q;
|
|
47
|
+
}`,p=async()=>{try{const f=await(await fetch("/config.json")).json();o(f)}catch(v){console.error(v),c(!0)}};return d.useEffect(()=>{p()},[]),Object.keys(n).length===0?i.jsx(Qe,{errorShow:s,errorMessage:u}):i.jsx(et.Provider,{value:n,children:t})},fe=()=>{const t=d.useContext(et);if(t===void 0)throw new Error("Non puoi leggere i config");return t},tt=d.createContext(),Bt=({children:t})=>{const[n,o]=d.useState(!1),[s,c]=d.useState(),[u,p]=d.useState(),v={showAlert:n,setShowAlert:o,typeAlert:s,setTypeAlert:c,messageAlert:u,setMessageAlert:p};return i.jsx(tt.Provider,{value:v,children:t})},G=()=>{const t=d.useContext(tt);if(t===void 0)throw new Error("Non puoi modificare l'alert");return t};let J;const te=async(t,n,o)=>{if(J)return J;try{const c=await(await fetch("/config.json")).json(),u=c.baseUri,{unauthorized:p,notFound:v,defaultMessage:f}=c.axiosErrors;return J=$t.create({baseURL:u,timeout:5e3}),J.interceptors.request.use(b=>b),J.interceptors.response.use(b=>b,b=>{if(b.response)switch(t(!0),n("danger"),b.response.status){case 401:localStorage.removeItem("accessToken"),o(p);break;case 404:o(v);break;default:o(`${f} ${b.response.status} ${b.response.data.error}`)}return Promise.reject(b)}),J}catch(s){console.error(s)}},rt=d.createContext(),Ut=({children:t})=>{const{heartbeatEndpoint:n,infiniteSession:o,timeDeducted:s,authenticatedEndpoint:c}=fe(),{setIsLoading:u}=je(),{setShowAlert:p,setMessageAlert:v,setTypeAlert:f}=G(),b=K.useNavigate(),[j,w]=d.useState(null),[R,_]=d.useState(),[I,D]=d.useState(),[P,x]=d.useState(),E=async(A,L)=>{A.preventDefault();try{u(!0),p(!1);const F=await(await te(p,f,v)).post(c,{auth:L}),ne=F.data.id,V=F.headers.token;V&&(localStorage.setItem("accessToken",V),localStorage.setItem("id",ne),w(!0),_(V),b(`/dashboard/${ne}`))}catch(M){console.error(M),u(!1)}},$=()=>{localStorage.removeItem("accessToken"),localStorage.removeItem("id"),w(!1),_(null)},T=async()=>{try{const A=localStorage.getItem("accessToken"),F=(await(await te(p,f,v)).get(`${n}`,{headers:{Authorization:A}})).headers.token;localStorage.setItem("accessToken",F),_(F)}catch(A){console.error(A),$()}},U=()=>{if(!R)return;const L=Dt(R).exp,M=Math.floor(Date.now()/1e3),F=(L-M)*1e3;x(F),D(F-s)};d.useEffect(()=>{if(localStorage.getItem("accessToken"))w(!0);else{w(!1);return}},[]),d.useEffect(()=>{U();let A;o&&R&&I&&(A=setInterval(()=>{T()},I));let L;return!o&&R&&P&&(L=setTimeout(()=>{$(),p(!0),f("danger"),v("Sessione scaduta")},P)),()=>{A&&clearInterval(A),L&&clearTimeout(L)}},[R,I]);const H={isAuthenticated:j,setIsAuthenticated:w,login:E,logout:$,setCurrentToken:_};return i.jsx(rt.Provider,{value:H,children:t})},we=()=>{const t=d.useContext(rt);if(t===void 0)throw new Error("Non sei dentro al Auth Provider");return t},Vt=()=>{const{isAuthenticated:t}=we(),{setShowAlert:n,setTypeAlert:o,setMessageAlert:s}=G(),c=localStorage.getItem("accessToken");return d.useEffect(()=>{!t&&!c&&(n(!0),o("danger"),s("Non sei autorizzato"))},[]),t===null?null:t?i.jsx(K.Outlet,{}):i.jsx(K.Navigate,{to:"/"})};var nt={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},He=d.createContext&&d.createContext(nt),Yt=["attr","size","title"];function qt(t,n){if(t==null)return{};var o=Jt(t,n),s,c;if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(t);for(c=0;c<u.length;c++)s=u[c],!(n.indexOf(s)>=0)&&Object.prototype.propertyIsEnumerable.call(t,s)&&(o[s]=t[s])}return o}function Jt(t,n){if(t==null)return{};var o={};for(var s in t)if(Object.prototype.hasOwnProperty.call(t,s)){if(n.indexOf(s)>=0)continue;o[s]=t[s]}return o}function ce(){return ce=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var o=arguments[n];for(var s in o)Object.prototype.hasOwnProperty.call(o,s)&&(t[s]=o[s])}return t},ce.apply(this,arguments)}function Xe(t,n){var o=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);n&&(s=s.filter(function(c){return Object.getOwnPropertyDescriptor(t,c).enumerable})),o.push.apply(o,s)}return o}function ue(t){for(var n=1;n<arguments.length;n++){var o=arguments[n]!=null?arguments[n]:{};n%2?Xe(Object(o),!0).forEach(function(s){Kt(t,s,o[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):Xe(Object(o)).forEach(function(s){Object.defineProperty(t,s,Object.getOwnPropertyDescriptor(o,s))})}return t}function Kt(t,n,o){return n=Gt(n),n in t?Object.defineProperty(t,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[n]=o,t}function Gt(t){var n=Ht(t,"string");return typeof n=="symbol"?n:n+""}function Ht(t,n){if(typeof t!="object"||!t)return t;var o=t[Symbol.toPrimitive];if(o!==void 0){var s=o.call(t,n||"default");if(typeof s!="object")return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(t)}function ot(t){return t&&t.map((n,o)=>d.createElement(n.tag,ue({key:o},n.attr),ot(n.child)))}function re(t){return n=>d.createElement(Xt,ce({attr:ue({},t.attr)},n),ot(t.child))}function Xt(t){var n=o=>{var{attr:s,size:c,title:u}=t,p=qt(t,Yt),v=c||o.size||"1em",f;return o.className&&(f=o.className),t.className&&(f=(f?f+" ":"")+t.className),d.createElement("svg",ce({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},o.attr,s,p,{className:f,style:ue(ue({color:t.color||o.color},o.style),t.style),height:v,width:v,xmlns:"http://www.w3.org/2000/svg"}),u&&d.createElement("title",null,u),t.children)};return He!==void 0?d.createElement(He.Consumer,null,o=>n(o)):n(nt)}function Zt(t){return re({tag:"svg",attr:{version:"1.1",viewBox:"0 0 16 16"},child:[{tag:"path",attr:{d:"M8 0c-4.355 0-7.898 3.481-7.998 7.812 0.092-3.779 2.966-6.812 6.498-6.812 3.59 0 6.5 3.134 6.5 7 0 0.828 0.672 1.5 1.5 1.5s1.5-0.672 1.5-1.5c0-4.418-3.582-8-8-8zM8 16c4.355 0 7.898-3.481 7.998-7.812-0.092 3.779-2.966 6.812-6.498 6.812-3.59 0-6.5-3.134-6.5-7 0-0.828-0.672-1.5-1.5-1.5s-1.5 0.672-1.5 1.5c0 4.418 3.582 8 8 8z"},child:[]}]})(t)}const at=()=>i.jsxs("div",{className:"fixed top-0 bottom-0 left-0 right-0 flex items-center justify-center bg-[#00000080]",children:[i.jsx(Zt,{className:"text-[20rem] relative animate-spin text-white"}),i.jsx("p",{className:"text-white text-2xl select-none absolute",children:"Loading..."})]});function Qt(t){return re({tag:"svg",attr:{viewBox:"0 0 15 15",fill:"none"},child:[{tag:"path",attr:{fillRule:"evenodd",clipRule:"evenodd",d:"M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z",fill:"currentColor"},child:[]}]})(t)}function er(t){return re({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm32 664c0 4.4-3.6 8-8 8h-48c-4.4 0-8-3.6-8-8V456c0-4.4 3.6-8 8-8h48c4.4 0 8 3.6 8 8v272zm-32-344a48.01 48.01 0 0 1 0-96 48.01 48.01 0 0 1 0 96z"},child:[]}]})(t)}function tr(t){return re({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M955.7 856l-416-720c-6.2-10.7-16.9-16-27.7-16s-21.6 5.3-27.7 16l-416 720C56 877.4 71.4 904 96 904h832c24.6 0 40-26.6 27.7-48zM480 416c0-4.4 3.6-8 8-8h48c4.4 0 8 3.6 8 8v184c0 4.4-3.6 8-8 8h-48c-4.4 0-8-3.6-8-8V416zm32 352a48.01 48.01 0 0 1 0-96 48.01 48.01 0 0 1 0 96z"},child:[]}]})(t)}function rr(t){return re({tag:"svg",attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M17.47 250.9C88.82 328.1 158 397.6 224.5 485.5c72.3-143.8 146.3-288.1 268.4-444.37L460 26.06C356.9 135.4 276.8 238.9 207.2 361.9c-48.4-43.6-126.62-105.3-174.38-137z"},child:[]}]})(t)}const st=()=>{const{showAlert:t,setShowAlert:n,messageAlert:o,typeAlert:s}=G(),{alertTimeout:c}=fe(),[u,p]=d.useState(0),v={danger:{bgColor:"bg-red-50",textColor:"text-red-700",buttonBg:"bg-red-50",hoverBg:"hover:bg-red-200",focusRing:"focus:ring-red-400",progressColor:"bg-red-400"},info:{bgColor:"bg-blue-50",textColor:"text-blue-700",buttonBg:"bg-blue-50",hoverBg:"hover:bg-blue-200",focusRing:"focus:ring-blue-400",progressColor:"bg-blue-400"},success:{bgColor:"bg-green-50",textColor:"text-green-700",buttonBg:"bg-green-50",hoverBg:"hover:bg-green-200",focusRing:"focus:ring-green-400",progressColor:"bg-green-400"}},{bgColor:f,textColor:b,buttonBg:j,hoverBg:w,focusRing:R,progressColor:_}=v[s],I=P=>{switch(P){case"danger":return i.jsx(tr,{className:"text-xl"});case"info":return i.jsx(er,{className:"text-xl"});case"success":return i.jsx(rr,{className:"text-xl"})}},D=()=>{n(!t)};return d.useEffect(()=>{let P;const E=100/(c/100);P=setInterval(()=>{p(T=>T>=100?(clearInterval(P),100):T+E)},100);const $=setTimeout(()=>{D()},c);return()=>{clearTimeout($),clearInterval(P)}},[]),i.jsxs("div",{className:`flex items-center p-4 pt-6 ${b} rounded-lg ${f} mx-auto fixed top-[calc(100vh-100px)] right-10`,role:"alert",children:[i.jsx("div",{className:"w-full bg-gray-200 rounded-t-lg overflow-hidden h-2.5 dark:bg-gray-700 absolute top-0 left-0 right-0",children:i.jsx("div",{className:`${_} h-2.5 rounded-t-lg`,style:{width:`${u}%`}})}),I(s),i.jsx("div",{className:"px-4 text-sm font-medium",children:o}),i.jsx("button",{type:"button",className:`ms-auto ${j} rounded-lg focus:ring-2 ${R} p-1.5 ${w} inline-flex items-center justify-center h-8 w-8 cursor-pointer`,title:"Close",onClick:D,children:i.jsx(Qt,{className:"text-xl"})})]})},nr=()=>{const{isLoading:t}=je(),{showAlert:n}=G();return i.jsxs(i.Fragment,{children:[t&&i.jsx(at,{}),i.jsxs("main",{className:t?"hidden":"",children:[n&&i.jsx(st,{}),i.jsx(K.Outlet,{})]})]})},ye=t=>{const{inputType:n,inputId:o,inputPlaceholder:s,inputRequired:c,inputValue:u,inputChange:p}=t,f=["text","email","password","search","tel","url"].includes(n)?n:"text";return i.jsx("input",{type:f,id:o,className:"bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5",placeholder:s,required:c??!0,value:u,onChange:p})},Ee=({label:t,labelId:n,labelStyle:o})=>i.jsx("label",{htmlFor:n,className:`${o??"block mb-2 text-sm font-medium text-gray-900"}`,children:t}),it=t=>{const{formStyle:n,userData:o,userInput:s,title:c,buttonStyle:u,formData:p,changeValue:v,submitForm:f}=t;return i.jsxs("form",{onSubmit:f,className:`${n.size} ${n.rounded} ${n.shadow} ${n.bgColor}`,children:[i.jsx("h1",{className:`${c.size} ${c.position} ${c.spacing}`,children:c.text}),i.jsxs("div",{className:"flex justify-center flex-col gap-1 my-4 w-1/2 mx-auto",children:[i.jsx(Ee,{labelId:"user-email",label:s.label}),i.jsx(ye,{inputType:s.label,inputId:"user-email",inputPlaceholder:s.placeholder,inputValue:o?p[o]:p.email,inputChange:b=>{v(o||"email",b.target.value)}})]}),i.jsxs("div",{className:"flex justify-center flex-col gap-1 my-4 w-1/2 mx-auto",children:[i.jsx(Ee,{labelId:"password",label:"Password"}),i.jsx(ye,{inputType:"password",inputId:"password",inputPlaceholder:"Password",inputValue:p.password,inputChange:b=>{v("password",b.target.value)}})]}),i.jsx("div",{className:`flex ${u.position} items-center ${u.spacing}`,children:i.jsx("button",{className:`${u.color} ${u.hoverColor} ${u.textColor} font-bold cursor-pointer ${u.size} ${u.rounded}`,children:u.text})})]})},or=({formStyle:t,userData:n,userInput:o,title:s,buttonStyle:c})=>{const u={size:"w-[800px]",bgColor:"bg-slate-50",rounded:"rounded-lg",shadow:"shadow-lg",...t},p={label:"Email",type:"email",placeholder:"email@email.it",...o},v={text:"Login",size:"text-4xl",position:"text-center",spacing:"my-12",...s},f={position:"justify-center",spacing:"my-12",color:"bg-blue-500",hoverColor:"hover:bg-blue-700",textColor:"text-white",size:"py-2 px-4",rounded:"rounded-full",text:"Login",...c},{login:b}=we(),{setShowAlert:j,setTypeAlert:w,setMessageAlert:R}=G(),{clearLoginFormOnError:_}=fe(),I=K.useNavigate(),D={email:"",password:""},[P,x]=d.useState(D),E=(T,U)=>{x(H=>({...H,[T]:U}))},$=T=>{b(T,P),_&&x(D)};return d.useEffect(()=>{const T=localStorage.getItem("id");localStorage.getItem("accessToken")&&T&&(I(`/dashboard/${T}`),j(!0),w("info"),R("Sei già loggato"))},[]),i.jsx("section",{children:i.jsx("div",{className:"container mx-auto flex items-center justify-center h-screen",children:i.jsx(it,{submitForm:$,formData:P,changeValue:E,formStyle:u,userData:n,userInput:p,title:v,buttonStyle:f})})})},ar=()=>{const{id:t}=K.useParams(),{logout:n,setCurrentToken:o}=we(),{usersEndpoint:s}=fe(),{setIsLoading:c}=je(),{setShowAlert:u,setTypeAlert:p,setMessageAlert:v}=G(),[f,b]=d.useState({}),[j,w]=d.useState(null),[R,_]=d.useState(!1),I=async()=>{try{c(!0);const x=localStorage.getItem("accessToken");if(!x){n(),u(!0),p("danger"),v("Sessione scaduta");return}o(x);const T=(await(await te(u,p,v)).get(`${s}${t}`,{headers:{Authorization:x}})).data;b(T),c(!1)}catch(x){console.error(x),c(!1),n()}},D=async()=>{try{_(!0);const x=localStorage.getItem("accessToken");if(!x){n(),u(!0),p("danger"),v("Sessione scaduta");return}const T=(await(await te(u,p,v)).get(`${s}`,{headers:{Authorization:x}})).data;w(T),T&&_(!1)}catch(x){console.error(x),c(!1),x.status===401&&n(),_(!1)}},P=()=>{n(),u(!0),p("info"),v("Hai effettuato il logout")};return d.useEffect(()=>{I()},[]),i.jsx("section",{children:i.jsxs("div",{className:"container mx-auto py-8",children:[i.jsxs("div",{className:"flex items-center justify-center gap-8 h-20",children:[i.jsxs("h1",{className:"text-4xl text-center text-slate-800",children:["Email: ",f.email]}),i.jsx("button",{onClick:P,className:"bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded-full cursor-pointer",children:"Logout"})]}),i.jsx("div",{className:"flex justify-center items-center my-12",children:i.jsx("button",{onClick:D,className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full disabled:bg-blue-300 disabled:text-gray-500 disabled:cursor-not-allowed cursor-pointer",disabled:R,children:"Lista degli utenti"})}),i.jsx("div",{className:"flex justify-center items-center",children:j&&i.jsx("ul",{children:j.map(x=>i.jsxs("li",{className:"text-xl my-4",children:[x.id," - ",x.email]},`user-${x.id}`))})})]})})};exports.Alert=st;exports.AlertProvider=Bt;exports.AuthPage=Vt;exports.AuthProvider=Ut;exports.ConfigProvider=Wt;exports.Dashboard=ar;exports.DefaultLayout=nr;exports.ErrorPage=Qe;exports.Input=ye;exports.InputLabel=Ee;exports.Loading=at;exports.LoadingProvider=zt;exports.Login=or;exports.LoginForm=it;exports.fetchAxiosConfig=te;
|