@instincthub/react-ui 0.1.10 → 0.1.12
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/src/assets/css/bootstrap/display.css +92 -0
- package/dist/src/assets/css/forms/forms-index.css +1 -0
- package/dist/src/assets/css/forms/icon-btn.css +60 -0
- package/dist/src/components/auth/LoginForm.js +1 -1
- package/dist/src/components/ui/tables/IHubTableServer.js +1 -1
- package/dist/src/types/components/forms/FileField.d.ts +61 -0
- package/dist/src/types/components/ui/tables/IHubTableServer.d.ts +5 -1
- package/dist/src/types/types/index.d.ts +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -331,3 +331,95 @@
|
|
|
331
331
|
justify-content: flex-end;
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
+
.ihub-align-items-center{
|
|
335
|
+
align-items: center;
|
|
336
|
+
}
|
|
337
|
+
.ihub-align-items-start {
|
|
338
|
+
align-items: flex-start;
|
|
339
|
+
}
|
|
340
|
+
.ihub-align-items-end {
|
|
341
|
+
align-items: flex-end;
|
|
342
|
+
}
|
|
343
|
+
.ihub-align-items-baseline {
|
|
344
|
+
align-items: baseline;
|
|
345
|
+
}
|
|
346
|
+
.ihub-align-items-stretch {
|
|
347
|
+
align-items: stretch;
|
|
348
|
+
}
|
|
349
|
+
.ihub-flex-column {
|
|
350
|
+
flex-direction: column;
|
|
351
|
+
}
|
|
352
|
+
.ihub-flex-column-reverse {
|
|
353
|
+
flex-direction: column-reverse;
|
|
354
|
+
}
|
|
355
|
+
.ihub-flex-row {
|
|
356
|
+
flex-direction: row;
|
|
357
|
+
}
|
|
358
|
+
.ihub-flex-row-reverse {
|
|
359
|
+
flex-direction: row-reverse;
|
|
360
|
+
}
|
|
361
|
+
.ihub-flex-wrap {
|
|
362
|
+
flex-wrap: wrap;
|
|
363
|
+
}
|
|
364
|
+
.ihub-flex-nowrap {
|
|
365
|
+
flex-wrap: nowrap;
|
|
366
|
+
}
|
|
367
|
+
.ihub-flex-wrap-reverse {
|
|
368
|
+
flex-wrap: wrap-reverse;
|
|
369
|
+
}
|
|
370
|
+
.ihub-flex-grow {
|
|
371
|
+
flex-grow: 1;
|
|
372
|
+
}
|
|
373
|
+
.ihub-flex-shrink {
|
|
374
|
+
flex-shrink: 1;
|
|
375
|
+
}
|
|
376
|
+
.ihub-flex-basis {
|
|
377
|
+
flex-basis: auto;
|
|
378
|
+
}
|
|
379
|
+
.ihub-flex-auto {
|
|
380
|
+
flex: 1 1 auto;
|
|
381
|
+
}
|
|
382
|
+
.ihub-flex-none {
|
|
383
|
+
flex: none;
|
|
384
|
+
}
|
|
385
|
+
.ihub-flex-fill {
|
|
386
|
+
flex: 1 1 100%;
|
|
387
|
+
}
|
|
388
|
+
.ihub-flex-1 {
|
|
389
|
+
flex: 1;
|
|
390
|
+
}
|
|
391
|
+
.ihub-flex-2 {
|
|
392
|
+
flex: 2;
|
|
393
|
+
}
|
|
394
|
+
.ihub-flex-3 {
|
|
395
|
+
flex: 3;
|
|
396
|
+
}
|
|
397
|
+
.ihub-flex-4 {
|
|
398
|
+
flex: 4;
|
|
399
|
+
}
|
|
400
|
+
.ihub-flex-5 {
|
|
401
|
+
flex: 5;
|
|
402
|
+
}
|
|
403
|
+
.ihub-flex-6 {
|
|
404
|
+
flex: 6;
|
|
405
|
+
}
|
|
406
|
+
.ihub-flex-7 {
|
|
407
|
+
flex: 7;
|
|
408
|
+
}
|
|
409
|
+
.ihub-flex-8 {
|
|
410
|
+
flex: 8;
|
|
411
|
+
}
|
|
412
|
+
.ihub-flex-9 {
|
|
413
|
+
flex: 9;
|
|
414
|
+
}
|
|
415
|
+
.ihub-flex-10 {
|
|
416
|
+
flex: 10;
|
|
417
|
+
}
|
|
418
|
+
.ihub-flex-11 {
|
|
419
|
+
flex: 11;
|
|
420
|
+
}
|
|
421
|
+
.ihub-flex-12 {
|
|
422
|
+
flex: 12;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* Action buttons */
|
|
2
|
+
.ihub-action-controls {
|
|
3
|
+
display: flex;
|
|
4
|
+
gap: 0.5rem;
|
|
5
|
+
align-items: center;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.ihub-action-buttons {
|
|
9
|
+
display: flex;
|
|
10
|
+
gap: 0.25rem;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.ihub-icon-btn {
|
|
14
|
+
padding: 0.25rem;
|
|
15
|
+
border: none;
|
|
16
|
+
background: transparent;
|
|
17
|
+
cursor: pointer;
|
|
18
|
+
border-radius: 4px;
|
|
19
|
+
transition: all 0.2s;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.ihub-icon-btn:hover {
|
|
23
|
+
opacity: 0.8;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.ihub-icon-btn-info {
|
|
27
|
+
color: #0fabbc;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.ihub-icon-btn-info:hover {
|
|
31
|
+
background: #0fabbc;
|
|
32
|
+
color: white;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.ihub-icon-btn-primary {
|
|
36
|
+
color: #00838f;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.ihub-icon-btn-primary:hover {
|
|
40
|
+
background: #00838f;
|
|
41
|
+
color: white;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.ihub-icon-btn-secondary {
|
|
45
|
+
color: #009ba2;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.ihub-icon-btn-secondary:hover {
|
|
49
|
+
background: #009ba2;
|
|
50
|
+
color: white;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.ihub-icon-btn-danger {
|
|
54
|
+
color: #ea5f5e;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.ihub-icon-btn-danger:hover {
|
|
58
|
+
background: #ea5f5e;
|
|
59
|
+
color: white;
|
|
60
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{slicedToArray as e,typeof as t,asyncToGenerator as r,regeneratorRuntime as n,objectSpread2 as a}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as i,jsxs as o,Fragment as u}from"react/jsx-runtime";import{useState as s,useRef as l,useCallback as c,useEffect as d,useMemo as m}from"react";import{signOut as h,signIn as b}from"../../../node_modules/next-auth/react.js";import{useRouter as f}from"next/navigation";import{getData as v}from"../lib/auth/dbRequestst.js";import{getCookie as p,setCookie as k,handleResendOTP as g,reqOptions as w}from"../lib/helpFunction.js";import{openConfirmModal as y,openToast as x}from"../lib/modals/modals.js";import"../lib/utils.js";import N from"../forms/PasswordField.js";import C from"../forms/InputText.js";import T from"../ui/OrDivider.js";import S from"./FromInstinctHub.js";import P from"../forms/SubmitButton.js";var A=function(e){return e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"").trim()};function j(t,r){var n=s(t),a=e(n,2),i=a[0],o=a[1];return d((function(){var e=setTimeout((function(){o(t)}),r);return function(){clearTimeout(e)}}),[t,r]),i}var L="loginForm_preservedData",R=function(){try{localStorage.removeItem(L)}catch(e){console.warn("Failed to clear form data:",e)}},O=function(){return o("div",{className:"ihub-loading-skeleton",children:[i("div",{className:"ihub-skeleton-line ihub-skeleton-title"}),i("div",{className:"ihub-skeleton-line ihub-skeleton-input"}),i("div",{className:"ihub-skeleton-line ihub-skeleton-input"}),i("div",{className:"ihub-skeleton-line ihub-skeleton-button"})]})},E=function(E){var F=E.session;E.params;var I=E.searchParams,U=E.endpointPath,M=E.verificationPath,V=E.redirectPath,q=E.hideResetPassword,D=void 0!==q&&q,_=E.hideSignup,H=void 0!==_&&_,Y=E.type,B=E.channelUsername,W=void 0===B?"skills":B,J=E.isLoading,X=void 0!==J&&J,z=E.onSubmitStart,G=E.onSubmitComplete,K=E.loadingText,Z=void 0===K?"Loading...":K,$=E.preserveFormData,Q=void 0!==$&&$,ee=E.onSuccessRedirect,te=E.onFailureRedirect,re=E.customValidationHandler,ne=E.autoRedirectOnSession,ae=void 0===ne||ne,ie=E.title,oe=void 0===ie?"Login Form":ie,ue=E.subtitle,se=E.showTitle,le=void 0===se||se,ce=E.className,de=E.formClassName,me=E.enableClientValidation,he=void 0!==me&&me,be=E.customValidationRules,fe=E.onError,ve=E.sessionCheckInterval,pe=void 0===ve?3e4:ve,ke=E.clearCallbackAfterUse,ge=void 0===ke||ke,we=E.submitButtonText,ye=void 0===we?"Login":we,xe=E.submitButtonVariant,Ne=void 0===xe?"primary":xe,Ce=E.showRememberMe,Te=void 0!==Ce&&Ce,Se=E.rememberMeText,Pe=void 0===Se?"Remember me":Se,Ae=E.enableOAuth,je=void 0!==Ae&&Ae,Le=E.oauthProviders,Re=void 0===Le?[]:Le,Oe=E.oauthConfig,Ee=void 0===Oe?{}:Oe,Fe=E.enableCaptcha,Ie=void 0!==Fe&&Fe;E.captchaProvider;var Ue=E.enableRateLimiting,Me=void 0!==Ue&&Ue,Ve=E.maxAttempts,qe=void 0===Ve?5:Ve,De=E.lockoutDuration,_e=void 0===De?3e5:De,He=E.trackingEnabled,Ye=void 0!==He&&He,Be=E.onLoginAttempt,We=E.onLoginSuccess,Je=E.onLoginFailure,Xe=E.ariaLabel,ze=E.ariaDescribedBy,Ge=E.focusOnMount,Ke=void 0!==Ge&&Ge;E.autoComplete;var Ze=E.validateOnBlur,$e=void 0!==Ze&&Ze,Qe=E.debounceValidation,et=void 0===Qe?300:Qe,tt=E.showPasswordStrength,rt=void 0!==tt&&tt,nt=E.enableFormReset,at=void 0!==nt&&nt,it=E.autoSave,ot=void 0!==it&&it,ut=E.autoSaveInterval,st=void 0===ut?5e3:ut,lt=E.offlineSupport,ct=void 0!==lt&<,dt=E.retryAttempts,mt=void 0===dt?3:dt,ht=E.retryDelay,bt=void 0===ht?1e3:ht,ft=E.sessionTimeoutWarning,vt=void 0!==ft&&ft,pt=E.sessionTimeoutDuration,kt=void 0===pt?18e5:pt,gt=E.csrfToken,wt=E.sanitizeInputs,yt=void 0===wt||wt,xt=E.highContrastMode,Nt=void 0!==xt&&xt,Ct=E.showLoadingSkeleton,Tt=void 0!==Ct&&Ct,St=E.preventMultipleSubmissions,Pt=void 0===St||St,At=f(),jt=I.error,Lt=I.callbackUrl,Rt=Lt?decodeURIComponent(Lt):void 0,Ot=s(""),Et=e(Ot,2),Ft=Et[0],It=Et[1],Ut=s(1),Mt=e(Ut,2),Vt=Mt[0],qt=Mt[1],Dt=s(""),_t=e(Dt,2),Ht=_t[0],Yt=_t[1],Bt=s(""),Wt=e(Bt,2),Jt=Wt[0],Xt=Wt[1],zt=s(!1),Gt=e(zt,2),Kt=Gt[0],Zt=Gt[1],$t=s(!1),Qt=e($t,2),er=Qt[0],tr=Qt[1],rr=s(0),nr=e(rr,2),ar=nr[0],ir=nr[1],or=s(!1),ur=e(or,2),sr=ur[0],lr=ur[1],cr=s({}),dr=e(cr,2),mr=dr[0],hr=dr[1],br=s(!1),fr=e(br,2),vr=fr[0],pr=fr[1],kr=s({score:0,feedback:[]}),gr=e(kr,2),wr=gr[0],yr=gr[1],xr=s(!1),Nr=e(xr,2),Cr=Nr[0],Tr=Nr[1],Sr=s(!1),Pr=e(Sr,2),Ar=Pr[0],jr=Pr[1],Lr=s(!1),Rr=e(Lr,2),Or=Rr[0],Er=Rr[1],Fr=s(""),Ir=e(Fr,2),Ur=Ir[0],Mr=Ir[1],Vr=s((function(){return Math.random().toString(36).substr(2,9)})),qr=e(Vr,1)[0],Dr=l(null),_r=l(null),Hr=l(null),Yr=l(null),Br=l(null),Wr=l(!0),Jr=l(null),Xr=l(0),zr=F,Gr=j(Ht,et),Kr=j(Jt,et),Zr=X||Kt||Cr,$r=c((function(){Dr.current&&Dr.current.abort(),[_r,Hr,Yr,Br].forEach((function(e){e.current&&clearTimeout(e.current)}))}),[]);d((function(){if(Q){var e=function(){try{var e=localStorage.getItem(L);return e?JSON.parse(e):null}catch(e){return console.warn("Failed to load form data:",e),null}}();e&&(Yt(e.username),tr(e.rememberMe))}}),[Q]),d((function(){if(ot&&Or)return Yr.current=setTimeout((function(){Q&&function(e){try{localStorage.setItem(L,JSON.stringify(e))}catch(e){console.warn("Failed to save form data:",e)}}({username:Ht,rememberMe:er})}),st),function(){Yr.current&&clearTimeout(Yr.current)}}),[ot,st,Ht,er,Or,Q]),d((function(){if(ct){var e=function(){return pr(!1)},t=function(){return pr(!0)};return window.addEventListener("online",e),window.addEventListener("offline",t),pr(!navigator.onLine),function(){window.removeEventListener("online",e),window.removeEventListener("offline",t)}}}),[ct]);var Qr=m((function(){return function(e){return e&&"object"===t(e)&&"token"in e}(zr)?zr:null}),[zr]),en=m((function(){var e,r,n,a,i;return{handle:"object"===t(null==Qr?void 0:Qr.channels)?null==Qr||null===(e=Qr.channels)||void 0===e||null===(e=e.active)||void 0===e?void 0:e.username:"",token:null==Qr?void 0:Qr.accessToken,uuid:null==Qr||null===(r=Qr.user)||void 0===r?void 0:r.uuid,email:(null==Qr||null===(n=Qr.user)||void 0===n?void 0:n.email)||(null==Qr||null===(a=Qr.user)||void 0===a?void 0:a.email),verifyEmail:null==Qr||null===(i=Qr.user)||void 0===i?void 0:i.emailVerified}}),[Qr,F]),tn=en.handle,rn=en.token,nn=en.uuid,an=en.email,on=en.verifyEmail;d((function(){if(vt&&rn&&!Ar)return Br.current=setTimeout((function(){Wr.current&&y("Your session will expire in 5 minutes. Do you want to extend it?").then((function(e){jr(!0)}))}),kt-3e5),function(){Br.current&&clearTimeout(Br.current)}}),[vt,kt,rn,Ar]),d((function(){rt&&Jt&&yr(function(e){var t={score:0,feedback:[]};return e.length>=8?t.score+=1:t.feedback.push("At least 8 characters"),/[A-Z]/.test(e)?t.score+=1:t.feedback.push("Include uppercase letter"),/[a-z]/.test(e)?t.score+=1:t.feedback.push("Include lowercase letter"),/\d/.test(e)?t.score+=1:t.feedback.push("Include number"),/[!@#$%^&*(),.?":{}|<>]/.test(e)?t.score+=1:t.feedback.push("Include special character"),t}(Jt))}),[Jt,rt]);var un=c((function(){if(!he)return!0;var e={},t=yt?A(Ht):Ht,r=yt?A(Jt):Jt;if(null!=be&&be.username){var n=be.username(t);n&&(e.username=n)}else t.trim()?t.length<3&&(e.username="Username must be at least 3 characters"):e.username="Username is required";if(null!=be&&be.password){var a=be.password(r);a&&(e.password=a)}else r.trim()?r.length<6&&(e.password="Password must be at least 6 characters"):e.password="Password is required";if(hr(e),Object.keys(e).length>0){var i=Object.values(e).join(". "),o=document.createElement("div");o.setAttribute("aria-live","polite"),o.setAttribute("aria-atomic","true"),o.style.position="absolute",o.style.left="-10000px",o.textContent="Form validation errors: ".concat(i),document.body.appendChild(o),setTimeout((function(){document.body.contains(o)&&document.body.removeChild(o)}),1e3)}return 0===Object.keys(e).length}),[he,be,Ht,Jt,yt]);d((function(){$e&&Or&&he&&un()}),[Gr,Kr,$e,Or,he,un]);var sn=c((function(){return!Me||(!(ar>=qe)||(lr(!0),_r.current=setTimeout((function(){Wr.current&&(lr(!1),ir(0))}),_e),!1))}),[Me,ar,qe,_e]),ln=c(function(){var e=r(n().mark((function e(t){var r,a,i;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=n().mark((function e(r){return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t();case 3:return e.t0=e.sent,e.abrupt("return",{v:e.t0});case 7:if(e.prev=7,e.t1=e.catch(0),r!==mt&&"AbortError"!==e.t1.name){e.next=11;break}throw e.t1;case 11:return e.next=13,new Promise((function(e){return setTimeout(e,bt*Math.pow(2,r))}));case 13:case"end":return e.stop()}}),e,null,[[0,7]])})),i=0;case 2:if(!(i<=mt)){e.next=10;break}return e.delegateYield(r(i),"t0",4);case 4:if(!(a=e.t0)){e.next=7;break}return e.abrupt("return",a.v);case 7:i++,e.next=2;break;case 10:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),[mt,bt]),cn=c(function(){var e=r(n().mark((function e(t){var i,o,u,s,l,c,d,m,h,f,v,p,g;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.preventDefault(),!Pt||!Cr){e.next=3;break}return e.abrupt("return");case 3:if(Er(!0),un()){e.next=7;break}return null==fe||fe("Validation failed","validation"),e.abrupt("return");case 7:if(!ct||!vr){e.next=11;break}return It("You are offline. Please check your connection and try again."),null==fe||fe("Offline","network"),e.abrupt("return");case 11:if(sn()){e.next=16;break}return o="Too many attempts. Please wait ".concat(Math.ceil(_e/6e4)," minutes."),It(o),null==fe||fe(o,"auth"),e.abrupt("return");case 16:if(!Ie||Ur){e.next=20;break}return It("Please complete the CAPTCHA verification."),null==fe||fe("CAPTCHA required","validation"),e.abrupt("return");case 20:return $r(),Dr.current=new AbortController,qt(0),It(""),Zt(!0),Tr(!0),hr({}),Xr.current=0,null==z||z(),Ye&&(null==Be||Be(Ht)),Me&&ir((function(e){return e+1})),u=yt?A(Ht):Ht,s=yt?A(Jt):Jt,l={username:u,password:s,provider:"credentials",channel:W,formId:qr},Te&&(l.rememberMe=er),gt&&(l._token=gt),Ie&&Ur&&(l.captchaToken=Ur),(c=w("POST",JSON.stringify(l),null,"json")).signal=null===(i=Dr.current)||void 0===i?void 0:i.signal,c.headers=a(a({},c.headers),{},{"X-Requested-With":"XMLHttpRequest","X-Form-ID":qr}),gt&&(c.headers["X-CSRF-Token"]=gt),d=function(){var e=r(n().mark((function e(){var t;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fetch(U||"/api/auth/login",c);case 2:return t=e.sent,e.t0=t,e.next=6,t.json();case 6:return e.t1=e.sent,e.abrupt("return",{req:e.t0,res:e.t1});case 8:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),e.prev=42,e.next=45,ln(d);case 45:if(m=e.sent,h=m.req,f=m.res,200!==h.status&&!h.ok){e.next=60;break}return v={username:JSON.stringify(f),password:"instincthub",redirect:!1},Rt&&(v.callbackUrl=Rt,k("callbackUrl",Rt,30)),null==G||G(!0),Ye&&(null==We||We(f)),Me&&ir(0),Q||R(),e.next=57,b("credentials",v);case 57:qt(1),e.next=66;break;case 60:p=f.message||f.detail||"An error occurred",It(p),qt(f.status),null==fe||fe(p,"auth"),null==G||G(!1),Ye&&(null==Je||Je(p,Ht));case 66:e.next=78;break;case 68:if(e.prev=68,e.t0=e.catch(42),"AbortError"!==e.t0.name){e.next=72;break}return e.abrupt("return");case 72:x(g="Couldn't login. Please try again.",400),qt(3),null==fe||fe(g,"network"),null==G||G(!1),Ye&&(null==Je||Je(g,Ht));case 78:return e.prev=78,Wr.current&&(Zt(!1),Tr(!1)),e.finish(78);case 81:case"end":return e.stop()}}),e,null,[[42,68,78,81]])})));return function(t){return e.apply(this,arguments)}}(),[Ht,Jt,W,Rt,U,un,sn,$r,z,Be,G,We,fe,Je,Me,Te,er,yt,gt,Ie,Ur,qr,Pt,Cr,ct,vr,ln,Q,Ye]),dn=c((function(){at&&(Yt(""),Xt(""),tr(!1),It(""),hr({}),yr({score:0,feedback:[]}),Er(!1),Q&&R(),setTimeout((function(){var e,t=null===(e=Jr.current)||void 0===e?void 0:e.querySelector('input[name="username"]');t&&t.focus()}),100))}),[at,Q]),mn=c((function(e,t){if(ee)ee(e,t);else{var r=p("callbackUrl"),n=t||r;if(n)ge&&k("callbackUrl","",-1),At.push(n);else if(V)At.push(V);else if("skills"===Y)At.push("/library");else if("lms"===Y)if(tn){var a="You are currently logged in with ".concat(tn," channel. Would you like to proceed to the dashboard?");y(a).then((function(e){e&&At.push("/".concat(tn))}))}else{y("You do not have an active channel for this account. Would you like to create one?").then((function(e){e?At.push("/auth/create-channel"):h()}))}else At.push("/")}}),[ee,ge,V,Y,tn,At]),hn=c(r(n().mark((function e(){var t,r,a;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(rn&&Qr){e.next=2;break}return e.abrupt("return");case 2:if(!re){e.next=17;break}return e.prev=3,e.next=6,re(Qr);case 6:if(e.sent){e.next=10;break}return null==te||te("Custom validation failed"),e.abrupt("return");case 10:e.next=17;break;case 12:return e.prev=12,e.t0=e.catch(3),console.error("Custom validation error:",e.t0),null==te||te("Validation error occurred"),e.abrupt("return");case 17:return $r(),Dr.current=new AbortController,e.prev=19,t={path:"auth/skills/validate-user-token/?access_token=".concat(rn,"&user_uuid=").concat(nn),token:rn},e.next=23,v(t);case 23:if("Unauthorized"!==(null==(r=e.sent)?void 0:r.detail)&&"Not found."!==(null==r?void 0:r.detail)){e.next=30;break}return x("Couldn't login. Please try again.",400),null==te||te("Token validation failed"),e.abrupt("return");case 30:!1===on?(a="".concat(M||"/auth/verify-email","?email=").concat(an),y("You need to verify your email address, click okay to request for a one time password (OTP).").then((function(e){e&&an?(g(an),At.push(a)):h()}))):mn(Qr,Rt);case 31:e.next=40;break;case 33:if(e.prev=33,e.t1=e.catch(19),"AbortError"!==e.t1.name){e.next=37;break}return e.abrupt("return");case 37:console.error("Validation error:",e.t1),x("Validation failed. Please try again.",400),null==te||te("Network error during validation");case 40:case"end":return e.stop()}}),e,null,[[3,12],[19,33]])}))),[rn,nn,Qr,re,te,$r,M,an,on,mn,Rt,At]),bn=c((function(e){Er(!0);var t=e.target.value;Yt(t),mr.username&&hr((function(e){return a(a({},e),{},{username:void 0})}))}),[mr.username]),fn=c((function(e){Er(!0);var t=e.target.value;Xt(t),mr.password&&hr((function(e){return a(a({},e),{},{password:void 0})}))}),[mr.password]);c((function(e){$e&&he&&setTimeout((function(){return un()}),100)}),[$e,he,un]);var vn=c((function(e){var t=Ee[e]||{},r=a({callbackUrl:Rt},t);Ye&&(null==Be||Be("oauth_".concat(e))),b(e,r)}),[Ee,Rt,Ye,Be]);return d((function(){Rt&&k("callbackUrl",Rt,30)}),[Rt]),d((function(){if(ae&&!Zr&&F)if(Qr&&rn)re||nn?hn():mn(Qr,Rt);else if(null!=F&&F.user){var e={name:F.user};mn(e,Rt)}}),[F,Qr,rn,nn,ae,Zr,re,hn,mn,Rt]),d((function(){if(pe>0&&rn){var e=function(){Hr.current=setTimeout((function(){Wr.current&&rn&&(hn(),e())}),pe)};return e(),function(){Hr.current&&clearTimeout(Hr.current)}}}),[pe,rn,hn]),d((function(){if(Ke){var e=document.querySelector('input[name="username"]');e&&e.focus()}}),[Ke]),d((function(){return function(){Wr.current=!1,$r()}}),[$r]),d((function(){return Nt?document.body.classList.add("ihub-high-contrast"):document.body.classList.remove("ihub-high-contrast"),function(){document.body.classList.remove("ihub-high-contrast")}}),[Nt]),i("div",Tt&&Zr?{className:"ihub-max-w-500 ihub-mx-auto ".concat(ce||""),children:i(O,{})}:Zr&&Tt?{className:"ihub-max-w-500 ihub-mx-auto ".concat(ce||""),children:i("div",{className:"ihub-loading-state",children:i("p",{children:Z})})}:sr?{className:"ihub-max-w-500 ihub-mx-auto ".concat(ce||""),children:o("div",{className:"ihub-error-state",children:[o("p",{children:["Too many login attempts. Please wait"," ",Math.ceil(_e/6e4)," minutes before trying again."]}),at&&i("button",{onClick:dn,className:"ihub-reset-btn ihub-mt-3",type:"button",children:"Reset Form"})]})}:ct&&vr?{className:"ihub-max-w-500 ihub-mx-auto ".concat(ce||""),children:o("div",{className:"ihub-offline-state",children:[i("p",{children:"You are currently offline. Please check your internet connection and try again."}),i("button",{onClick:function(){return window.location.reload()},className:"ihub-retry-btn ihub-mt-3",type:"button",children:"Retry"})]})}:{className:"".concat(ce||""," ").concat(Nt?"ihub-high-contrast":""),children:o("form",{ref:Jr,onSubmit:cn,className:"ihub-max-w-500 ihub-mx-auto ".concat(de||""),"aria-label":Xe||"Login form","aria-describedby":ze,noValidate:he,children:[le&&o(u,{children:[i("h1",{className:"ihub-fs-32",children:oe}),ue&&i("p",{className:"ihub-subtitle",children:ue})]}),jt&&i("div",{className:"err",role:"alert","aria-live":"polite",children:"Sign in failed. Check the details you provided are correct."}),i(C,{name:"username",type:"text",label:"Email or Username",required:!0,textTransform:"lowercase",value:Ht,onChange:bn}),mr.username&&i("p",{className:"err",id:"username-error",role:"alert",children:mr.username}),i(N,{name:"password",label:"Password",required:!0,id:"password",value:Jt,onChange:fn}),mr.password&&i("p",{className:"err",id:"password-error",role:"alert",children:mr.password}),rt&&Jt&&o("div",{className:"ihub-password-strength ihub-mt-2",id:"password-strength",children:[i("div",{className:"ihub-strength-meter",children:i("div",{className:"ihub-strength-bar ihub-strength-".concat(wr.score),style:{width:"".concat(wr.score/5*100,"%")}})}),o("p",{className:"ihub-strength-text",children:["Password strength:"," ",["Very Weak","Weak","Fair","Good","Strong"][wr.score]]}),wr.feedback.length>0&&i("ul",{className:"ihub-strength-feedback",children:wr.feedback.map((function(e,t){return i("li",{children:e},t)}))})]}),Te&&o("div",{className:"ihub-remember-me ihub-mt-3",children:[o("label",{className:"ihub-checkbox-label",children:[i("input",{type:"checkbox",checked:er,onChange:function(e){tr(e.target.checked),Er(!0)},"aria-describedby":"remember-me-help"}),Pe]}),i("small",{id:"remember-me-help",className:"ihub-help-text",children:"Keep me signed in on this device"})]}),Ie&&i("div",{className:"ihub-captcha ihub-mt-3",children:o("div",{className:"ihub-captcha-placeholder",children:[i("p",{children:"CAPTCHA verification would be loaded here"}),i("button",{type:"button",onClick:function(){return Mr("mock-captcha-token")},className:"ihub-verify-btn",children:"Verify (Mock)"})]})}),Ft&&i("div",{className:"err",role:"alert","aria-live":"polite",children:Ft}),o("div",{className:"action ihub-mt-4 ihub-mb-5",children:[i(P,{label:ye,type:"submit",status:Vt,disabled:Zr||sr||Pt&&Cr,variant:Ne}),at&&i("button",{type:"button",onClick:dn,className:"ihub-reset-btn ihub-ml-3",disabled:Zr,children:"Reset"}),(!D||!H||je)&&i(T,{labels:"or sign with"}),je&&Re.length>0&&i("div",{className:"ihub-oauth-buttons ihub-mt-3",role:"group","aria-label":"Social login options",children:Re.map((function(e){return o("button",{type:"button",className:"ihub-oauth-btn ihub-oauth-".concat(e),onClick:function(){return vn(e)},disabled:Zr,"aria-label":"Continue with ".concat(e),children:["Continue with"," ",e.charAt(0).toUpperCase()+e.slice(1)]},e)}))}),!D&&o("p",{className:"ihub-text-center ihub-fs-14",children:["Can't remember password?"," ",i("a",{href:"/auth/reset-password",children:"Reset Password"})]}),!H&&o("p",{className:"ihub-text-center ihub-fs-14",children:["New user? ",i("a",{href:"/auth/signup",children:"Create an account."})]})]}),i(S,{showText:!0}),"development"===process.env.NODE_ENV&&o("details",{className:"ihub-dev-info ihub-mt-4",children:[i("summary",{children:"Development Info"}),i("pre",{className:"ihub-dev-details",children:JSON.stringify({formTouched:Or,isOffline:ct?vr:"disabled",passwordStrength:rt?wr:"disabled",attemptCount:Me?ar:"disabled",validationErrors:mr,formId:qr},null,2)})]})]})})};export{E as default};
|
|
1
|
+
import{slicedToArray as e,typeof as t,asyncToGenerator as r,regeneratorRuntime as n,objectSpread2 as a}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as i,jsxs as o,Fragment as u}from"react/jsx-runtime";import{useState as s,useRef as l,useCallback as c,useEffect as d,useMemo as m}from"react";import{signOut as h,signIn as b}from"../../../node_modules/next-auth/react.js";import{useRouter as f}from"next/navigation";import{getData as v}from"../lib/auth/dbRequestst.js";import{getCookie as p,setCookie as k,handleResendOTP as g,reqOptions as w}from"../lib/helpFunction.js";import{openConfirmModal as y,openToast as x}from"../lib/modals/modals.js";import"../lib/utils.js";import N from"../forms/PasswordField.js";import C from"../forms/InputText.js";import T from"../ui/OrDivider.js";import S from"./FromInstinctHub.js";import P from"../forms/SubmitButton.js";var A=function(e){return e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"").trim()};function j(t,r){var n=s(t),a=e(n,2),i=a[0],o=a[1];return d((function(){var e=setTimeout((function(){o(t)}),r);return function(){clearTimeout(e)}}),[t,r]),i}var L="loginForm_preservedData",R=function(){try{localStorage.removeItem(L)}catch(e){console.warn("Failed to clear form data:",e)}},O=function(){return o("div",{className:"ihub-loading-skeleton",children:[i("div",{className:"ihub-skeleton-line ihub-skeleton-title"}),i("div",{className:"ihub-skeleton-line ihub-skeleton-input"}),i("div",{className:"ihub-skeleton-line ihub-skeleton-input"}),i("div",{className:"ihub-skeleton-line ihub-skeleton-button"})]})},E=function(E){var F=E.session;E.params;var I=E.searchParams,U=E.endpointPath,M=E.verificationPath,V=E.redirectPath,q=E.hideResetPassword,D=void 0!==q&&q,_=E.hideSignup,H=void 0!==_&&_,Y=E.type,B=E.channelUsername,W=void 0===B?"skills":B,J=E.isLoading,X=void 0!==J&&J,z=E.onSubmitStart,G=E.onSubmitComplete,K=E.loadingText,Z=void 0===K?"Loading...":K,$=E.preserveFormData,Q=void 0!==$&&$,ee=E.onSuccessRedirect,te=E.onFailureRedirect,re=E.customValidationHandler,ne=E.autoRedirectOnSession,ae=void 0===ne||ne,ie=E.title,oe=void 0===ie?"Login Form":ie,ue=E.subtitle,se=E.showTitle,le=void 0===se||se,ce=E.className,de=E.formClassName,me=E.enableClientValidation,he=void 0!==me&&me,be=E.customValidationRules,fe=E.onError,ve=E.sessionCheckInterval,pe=void 0===ve?3e4:ve,ke=E.clearCallbackAfterUse,ge=void 0===ke||ke,we=E.submitButtonText,ye=void 0===we?"Login":we,xe=E.submitButtonVariant,Ne=void 0===xe?"primary":xe,Ce=E.showRememberMe,Te=void 0!==Ce&&Ce,Se=E.rememberMeText,Pe=void 0===Se?"Remember me":Se,Ae=E.enableOAuth,je=void 0!==Ae&&Ae,Le=E.oauthProviders,Re=void 0===Le?[]:Le,Oe=E.oauthConfig,Ee=void 0===Oe?{}:Oe,Fe=E.enableCaptcha,Ie=void 0!==Fe&&Fe;E.captchaProvider;var Ue=E.enableRateLimiting,Me=void 0!==Ue&&Ue,Ve=E.maxAttempts,qe=void 0===Ve?5:Ve,De=E.lockoutDuration,_e=void 0===De?3e5:De,He=E.trackingEnabled,Ye=void 0!==He&&He,Be=E.onLoginAttempt,We=E.onLoginSuccess,Je=E.onLoginFailure,Xe=E.ariaLabel,ze=E.ariaDescribedBy,Ge=E.focusOnMount,Ke=void 0!==Ge&&Ge;E.autoComplete;var Ze=E.validateOnBlur,$e=void 0!==Ze&&Ze,Qe=E.debounceValidation,et=void 0===Qe?300:Qe,tt=E.showPasswordStrength,rt=void 0!==tt&&tt,nt=E.enableFormReset,at=void 0!==nt&&nt,it=E.autoSave,ot=void 0!==it&&it,ut=E.autoSaveInterval,st=void 0===ut?5e3:ut,lt=E.offlineSupport,ct=void 0!==lt&<,dt=E.retryAttempts,mt=void 0===dt?3:dt,ht=E.retryDelay,bt=void 0===ht?1e3:ht,ft=E.sessionTimeoutWarning,vt=void 0!==ft&&ft,pt=E.sessionTimeoutDuration,kt=void 0===pt?18e5:pt,gt=E.csrfToken,wt=E.sanitizeInputs,yt=void 0===wt||wt,xt=E.highContrastMode,Nt=void 0!==xt&&xt,Ct=E.showLoadingSkeleton,Tt=void 0!==Ct&&Ct,St=E.preventMultipleSubmissions,Pt=void 0===St||St,At=f(),jt=I.error,Lt=I.callbackUrl,Rt=Lt?decodeURIComponent(Lt):void 0,Ot=s(""),Et=e(Ot,2),Ft=Et[0],It=Et[1],Ut=s(1),Mt=e(Ut,2),Vt=Mt[0],qt=Mt[1],Dt=s(""),_t=e(Dt,2),Ht=_t[0],Yt=_t[1],Bt=s(""),Wt=e(Bt,2),Jt=Wt[0],Xt=Wt[1],zt=s(!1),Gt=e(zt,2),Kt=Gt[0],Zt=Gt[1],$t=s(!1),Qt=e($t,2),er=Qt[0],tr=Qt[1],rr=s(0),nr=e(rr,2),ar=nr[0],ir=nr[1],or=s(!1),ur=e(or,2),sr=ur[0],lr=ur[1],cr=s({}),dr=e(cr,2),mr=dr[0],hr=dr[1],br=s(!1),fr=e(br,2),vr=fr[0],pr=fr[1],kr=s({score:0,feedback:[]}),gr=e(kr,2),wr=gr[0],yr=gr[1],xr=s(!1),Nr=e(xr,2),Cr=Nr[0],Tr=Nr[1],Sr=s(!1),Pr=e(Sr,2),Ar=Pr[0],jr=Pr[1],Lr=s(!1),Rr=e(Lr,2),Or=Rr[0],Er=Rr[1],Fr=s(""),Ir=e(Fr,2),Ur=Ir[0],Mr=Ir[1],Vr=s((function(){return Math.random().toString(36).substr(2,9)})),qr=e(Vr,1)[0],Dr=l(null),_r=l(null),Hr=l(null),Yr=l(null),Br=l(null),Wr=l(!0),Jr=l(null),Xr=l(0),zr=F,Gr=j(Ht,et),Kr=j(Jt,et),Zr=X||Kt||Cr,$r=c((function(){Dr.current&&Dr.current.abort(),[_r,Hr,Yr,Br].forEach((function(e){e.current&&clearTimeout(e.current)}))}),[]);d((function(){if(Q){var e=function(){try{var e=localStorage.getItem(L);return e?JSON.parse(e):null}catch(e){return console.warn("Failed to load form data:",e),null}}();e&&(Yt(e.username),tr(e.rememberMe))}}),[Q]),d((function(){if(ot&&Or)return Yr.current=setTimeout((function(){Q&&function(e){try{localStorage.setItem(L,JSON.stringify(e))}catch(e){console.warn("Failed to save form data:",e)}}({username:Ht,rememberMe:er})}),st),function(){Yr.current&&clearTimeout(Yr.current)}}),[ot,st,Ht,er,Or,Q]),d((function(){if(ct){var e=function(){return pr(!1)},t=function(){return pr(!0)};return window.addEventListener("online",e),window.addEventListener("offline",t),pr(!navigator.onLine),function(){window.removeEventListener("online",e),window.removeEventListener("offline",t)}}}),[ct]);var Qr=m((function(){return function(e){return e&&"object"===t(e)&&"token"in e}(zr)?zr:null}),[zr]),en=m((function(){var e,r,n,a,i;return{handle:"object"===t(null==Qr?void 0:Qr.channels)?null==Qr||null===(e=Qr.channels)||void 0===e||null===(e=e.active)||void 0===e?void 0:e.username:"",token:null==Qr?void 0:Qr.accessToken,uuid:null==Qr||null===(r=Qr.user)||void 0===r?void 0:r.uuid,email:(null==Qr||null===(n=Qr.user)||void 0===n?void 0:n.email)||(null==Qr||null===(a=Qr.user)||void 0===a?void 0:a.email),verifyEmail:null==Qr||null===(i=Qr.user)||void 0===i?void 0:i.emailVerified}}),[Qr,F]),tn=en.handle,rn=en.token,nn=en.uuid,an=en.email,on=en.verifyEmail;d((function(){if(vt&&rn&&!Ar)return Br.current=setTimeout((function(){Wr.current&&y("Your session will expire in 5 minutes. Do you want to extend it?").then((function(e){jr(!0)}))}),kt-3e5),function(){Br.current&&clearTimeout(Br.current)}}),[vt,kt,rn,Ar]),d((function(){rt&&Jt&&yr(function(e){var t={score:0,feedback:[]};return e.length>=8?t.score+=1:t.feedback.push("At least 8 characters"),/[A-Z]/.test(e)?t.score+=1:t.feedback.push("Include uppercase letter"),/[a-z]/.test(e)?t.score+=1:t.feedback.push("Include lowercase letter"),/\d/.test(e)?t.score+=1:t.feedback.push("Include number"),/[!@#$%^&*(),.?":{}|<>]/.test(e)?t.score+=1:t.feedback.push("Include special character"),t}(Jt))}),[Jt,rt]);var un=c((function(){if(!he)return!0;var e={},t=yt?A(Ht):Ht,r=yt?A(Jt):Jt;if(null!=be&&be.username){var n=be.username(t);n&&(e.username=n)}else t.trim()?t.length<3&&(e.username="Username must be at least 3 characters"):e.username="Username is required";if(null!=be&&be.password){var a=be.password(r);a&&(e.password=a)}else r.trim()?r.length<6&&(e.password="Password must be at least 6 characters"):e.password="Password is required";if(hr(e),Object.keys(e).length>0){var i=Object.values(e).join(". "),o=document.createElement("div");o.setAttribute("aria-live","polite"),o.setAttribute("aria-atomic","true"),o.style.position="absolute",o.style.left="-10000px",o.textContent="Form validation errors: ".concat(i),document.body.appendChild(o),setTimeout((function(){document.body.contains(o)&&document.body.removeChild(o)}),1e3)}return 0===Object.keys(e).length}),[he,be,Ht,Jt,yt]);d((function(){$e&&Or&&he&&un()}),[Gr,Kr,$e,Or,he,un]);var sn=c((function(){return!Me||(!(ar>=qe)||(lr(!0),_r.current=setTimeout((function(){Wr.current&&(lr(!1),ir(0))}),_e),!1))}),[Me,ar,qe,_e]),ln=c(function(){var e=r(n().mark((function e(t){var r,a,i;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=n().mark((function e(r){return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t();case 3:return e.t0=e.sent,e.abrupt("return",{v:e.t0});case 7:if(e.prev=7,e.t1=e.catch(0),r!==mt&&"AbortError"!==e.t1.name){e.next=11;break}throw e.t1;case 11:return e.next=13,new Promise((function(e){return setTimeout(e,bt*Math.pow(2,r))}));case 13:case"end":return e.stop()}}),e,null,[[0,7]])})),i=0;case 2:if(!(i<=mt)){e.next=10;break}return e.delegateYield(r(i),"t0",4);case 4:if(!(a=e.t0)){e.next=7;break}return e.abrupt("return",a.v);case 7:i++,e.next=2;break;case 10:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),[mt,bt]),cn=c(function(){var e=r(n().mark((function e(t){var i,o,u,s,l,c,d,m,h,f,v,p,g;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.preventDefault(),!Pt||!Cr){e.next=3;break}return e.abrupt("return");case 3:if(Er(!0),un()){e.next=7;break}return null==fe||fe("Validation failed","validation"),e.abrupt("return");case 7:if(!ct||!vr){e.next=11;break}return It("You are offline. Please check your connection and try again."),null==fe||fe("Offline","network"),e.abrupt("return");case 11:if(sn()){e.next=16;break}return o="Too many attempts. Please wait ".concat(Math.ceil(_e/6e4)," minutes."),It(o),null==fe||fe(o,"auth"),e.abrupt("return");case 16:if(!Ie||Ur){e.next=20;break}return It("Please complete the CAPTCHA verification."),null==fe||fe("CAPTCHA required","validation"),e.abrupt("return");case 20:return $r(),Dr.current=new AbortController,qt(0),It(""),Zt(!0),Tr(!0),hr({}),Xr.current=0,null==z||z(),Ye&&(null==Be||Be(Ht)),Me&&ir((function(e){return e+1})),u=yt?A(Ht):Ht,s=yt?A(Jt):Jt,l={username:u,password:s,provider:"credentials",channel:W,formId:qr},Te&&(l.rememberMe=er),gt&&(l._token=gt),Ie&&Ur&&(l.captchaToken=Ur),(c=w("POST",JSON.stringify(l),null,"json")).signal=null===(i=Dr.current)||void 0===i?void 0:i.signal,c.headers=a(a({},c.headers),{},{"X-Requested-With":"XMLHttpRequest","X-Form-ID":qr}),gt&&(c.headers["X-CSRF-Token"]=gt),d=function(){var e=r(n().mark((function e(){var t;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fetch(U||"/api/auth/login",c);case 2:return t=e.sent,e.t0=t,e.next=6,t.json();case 6:return e.t1=e.sent,e.abrupt("return",{req:e.t0,res:e.t1});case 8:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),e.prev=42,e.next=45,ln(d);case 45:if(m=e.sent,h=m.req,f=m.res,200!==h.status&&!h.ok){e.next=61;break}return v={username:JSON.stringify(f),password:"instincthub",redirect:!1},Rt&&(v.callbackUrl=Rt,k("callbackUrl",Rt,30)),null==G||G(!0),Ye&&(null==We||We(f)),Me&&ir(0),Q||R(),e.next=57,b("credentials",v);case 57:qt(1),At.refresh(),e.next=67;break;case 61:p=f.message||f.detail||"An error occurred",It(p),qt(f.status),null==fe||fe(p,"auth"),null==G||G(!1),Ye&&(null==Je||Je(p,Ht));case 67:e.next=79;break;case 69:if(e.prev=69,e.t0=e.catch(42),"AbortError"!==e.t0.name){e.next=73;break}return e.abrupt("return");case 73:x(g="Couldn't login. Please try again.",400),qt(3),null==fe||fe(g,"network"),null==G||G(!1),Ye&&(null==Je||Je(g,Ht));case 79:return e.prev=79,Wr.current&&(Zt(!1),Tr(!1)),e.finish(79);case 82:case"end":return e.stop()}}),e,null,[[42,69,79,82]])})));return function(t){return e.apply(this,arguments)}}(),[Ht,Jt,W,Rt,U,un,sn,$r,z,Be,G,We,fe,Je,Me,Te,er,yt,gt,Ie,Ur,qr,Pt,Cr,ct,vr,ln,Q,Ye]),dn=c((function(){at&&(Yt(""),Xt(""),tr(!1),It(""),hr({}),yr({score:0,feedback:[]}),Er(!1),Q&&R(),setTimeout((function(){var e,t=null===(e=Jr.current)||void 0===e?void 0:e.querySelector('input[name="username"]');t&&t.focus()}),100))}),[at,Q]),mn=c((function(e,t){if(ee)ee(e,t);else{var r=p("callbackUrl"),n=t||r;if(n)ge&&k("callbackUrl","",-1),At.push(n);else if(V)At.push(V);else if("skills"===Y)At.push("/library");else if("lms"===Y)if(tn){var a="You are currently logged in with ".concat(tn," channel. Would you like to proceed to the dashboard?");y(a).then((function(e){e&&At.push("/".concat(tn))}))}else{y("You do not have an active channel for this account. Would you like to create one?").then((function(e){e?At.push("/auth/create-channel"):h()}))}else At.push("/")}}),[ee,ge,V,Y,tn,At]),hn=c(r(n().mark((function e(){var t,r,a;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(rn&&Qr){e.next=2;break}return e.abrupt("return");case 2:if(!re){e.next=17;break}return e.prev=3,e.next=6,re(Qr);case 6:if(e.sent){e.next=10;break}return null==te||te("Custom validation failed"),e.abrupt("return");case 10:e.next=17;break;case 12:return e.prev=12,e.t0=e.catch(3),console.error("Custom validation error:",e.t0),null==te||te("Validation error occurred"),e.abrupt("return");case 17:return $r(),Dr.current=new AbortController,e.prev=19,t={path:"auth/skills/validate-user-token/?access_token=".concat(rn,"&user_uuid=").concat(nn),token:rn},e.next=23,v(t);case 23:if("Unauthorized"!==(null==(r=e.sent)?void 0:r.detail)&&"Not found."!==(null==r?void 0:r.detail)){e.next=30;break}return x("Couldn't login. Please try again.",400),null==te||te("Token validation failed"),e.abrupt("return");case 30:!1===on?(a="".concat(M||"/auth/verify-email","?email=").concat(an),y("You need to verify your email address, click okay to request for a one time password (OTP).").then((function(e){e&&an?(g(an),At.push(a)):h()}))):mn(Qr,Rt);case 31:e.next=40;break;case 33:if(e.prev=33,e.t1=e.catch(19),"AbortError"!==e.t1.name){e.next=37;break}return e.abrupt("return");case 37:console.error("Validation error:",e.t1),x("Validation failed. Please try again.",400),null==te||te("Network error during validation");case 40:case"end":return e.stop()}}),e,null,[[3,12],[19,33]])}))),[rn,nn,Qr,re,te,$r,M,an,on,mn,Rt,At]),bn=c((function(e){Er(!0);var t=e.target.value;Yt(t),mr.username&&hr((function(e){return a(a({},e),{},{username:void 0})}))}),[mr.username]),fn=c((function(e){Er(!0);var t=e.target.value;Xt(t),mr.password&&hr((function(e){return a(a({},e),{},{password:void 0})}))}),[mr.password]);c((function(e){$e&&he&&setTimeout((function(){return un()}),100)}),[$e,he,un]);var vn=c((function(e){var t=Ee[e]||{},r=a({callbackUrl:Rt},t);Ye&&(null==Be||Be("oauth_".concat(e))),b(e,r)}),[Ee,Rt,Ye,Be]);return d((function(){Rt&&k("callbackUrl",Rt,30)}),[Rt]),d((function(){if(ae&&!Zr&&F)if(Qr&&rn)re||nn?hn():mn(Qr,Rt);else if(null!=F&&F.user){var e={name:F.user};mn(e,Rt)}}),[F,Qr,rn,nn,ae,Zr,re,hn,mn,Rt]),d((function(){if(pe>0&&rn){var e=function(){Hr.current=setTimeout((function(){Wr.current&&rn&&(hn(),e())}),pe)};return e(),function(){Hr.current&&clearTimeout(Hr.current)}}}),[pe,rn,hn]),d((function(){if(Ke){var e=document.querySelector('input[name="username"]');e&&e.focus()}}),[Ke]),d((function(){return function(){Wr.current=!1,$r()}}),[$r]),d((function(){return Nt?document.body.classList.add("ihub-high-contrast"):document.body.classList.remove("ihub-high-contrast"),function(){document.body.classList.remove("ihub-high-contrast")}}),[Nt]),i("div",Tt&&Zr?{className:"ihub-max-w-500 ihub-mx-auto ".concat(ce||""),children:i(O,{})}:Zr&&Tt?{className:"ihub-max-w-500 ihub-mx-auto ".concat(ce||""),children:i("div",{className:"ihub-loading-state",children:i("p",{children:Z})})}:sr?{className:"ihub-max-w-500 ihub-mx-auto ".concat(ce||""),children:o("div",{className:"ihub-error-state",children:[o("p",{children:["Too many login attempts. Please wait"," ",Math.ceil(_e/6e4)," minutes before trying again."]}),at&&i("button",{onClick:dn,className:"ihub-reset-btn ihub-mt-3",type:"button",children:"Reset Form"})]})}:ct&&vr?{className:"ihub-max-w-500 ihub-mx-auto ".concat(ce||""),children:o("div",{className:"ihub-offline-state",children:[i("p",{children:"You are currently offline. Please check your internet connection and try again."}),i("button",{onClick:function(){return window.location.reload()},className:"ihub-retry-btn ihub-mt-3",type:"button",children:"Retry"})]})}:{className:"".concat(ce||""," ").concat(Nt?"ihub-high-contrast":""),children:o("form",{ref:Jr,onSubmit:cn,className:"ihub-max-w-500 ihub-mx-auto ".concat(de||""),"aria-label":Xe||"Login form","aria-describedby":ze,noValidate:he,children:[le&&o(u,{children:[i("h1",{className:"ihub-fs-32",children:oe}),ue&&i("p",{className:"ihub-subtitle",children:ue})]}),jt&&i("div",{className:"err",role:"alert","aria-live":"polite",children:"Sign in failed. Check the details you provided are correct."}),i(C,{name:"username",type:"text",label:"Email or Username",required:!0,textTransform:"lowercase",value:Ht,onChange:bn}),mr.username&&i("p",{className:"err",id:"username-error",role:"alert",children:mr.username}),i(N,{name:"password",label:"Password",required:!0,id:"password",value:Jt,onChange:fn}),mr.password&&i("p",{className:"err",id:"password-error",role:"alert",children:mr.password}),rt&&Jt&&o("div",{className:"ihub-password-strength ihub-mt-2",id:"password-strength",children:[i("div",{className:"ihub-strength-meter",children:i("div",{className:"ihub-strength-bar ihub-strength-".concat(wr.score),style:{width:"".concat(wr.score/5*100,"%")}})}),o("p",{className:"ihub-strength-text",children:["Password strength:"," ",["Very Weak","Weak","Fair","Good","Strong"][wr.score]]}),wr.feedback.length>0&&i("ul",{className:"ihub-strength-feedback",children:wr.feedback.map((function(e,t){return i("li",{children:e},t)}))})]}),Te&&o("div",{className:"ihub-remember-me ihub-mt-3",children:[o("label",{className:"ihub-checkbox-label",children:[i("input",{type:"checkbox",checked:er,onChange:function(e){tr(e.target.checked),Er(!0)},"aria-describedby":"remember-me-help"}),Pe]}),i("small",{id:"remember-me-help",className:"ihub-help-text",children:"Keep me signed in on this device"})]}),Ie&&i("div",{className:"ihub-captcha ihub-mt-3",children:o("div",{className:"ihub-captcha-placeholder",children:[i("p",{children:"CAPTCHA verification would be loaded here"}),i("button",{type:"button",onClick:function(){return Mr("mock-captcha-token")},className:"ihub-verify-btn",children:"Verify (Mock)"})]})}),Ft&&i("div",{className:"err",role:"alert","aria-live":"polite",children:Ft}),o("div",{className:"action ihub-mt-4 ihub-mb-5",children:[i(P,{label:ye,type:"submit",status:Vt,disabled:Zr||sr||Pt&&Cr,variant:Ne}),at&&i("button",{type:"button",onClick:dn,className:"ihub-reset-btn ihub-ml-3",disabled:Zr,children:"Reset"}),(!D||!H||je)&&i(T,{labels:"or sign with"}),je&&Re.length>0&&i("div",{className:"ihub-oauth-buttons ihub-mt-3",role:"group","aria-label":"Social login options",children:Re.map((function(e){return o("button",{type:"button",className:"ihub-oauth-btn ihub-oauth-".concat(e),onClick:function(){return vn(e)},disabled:Zr,"aria-label":"Continue with ".concat(e),children:["Continue with"," ",e.charAt(0).toUpperCase()+e.slice(1)]},e)}))}),!D&&o("p",{className:"ihub-text-center ihub-fs-14",children:["Can't remember password?"," ",i("a",{href:"/auth/reset-password",children:"Reset Password"})]}),!H&&o("p",{className:"ihub-text-center ihub-fs-14",children:["New user? ",i("a",{href:"/auth/signup",children:"Create an account."})]})]}),i(S,{showText:!0}),"development"===process.env.NODE_ENV&&o("details",{className:"ihub-dev-info ihub-mt-4",children:[i("summary",{children:"Development Info"}),i("pre",{className:"ihub-dev-details",children:JSON.stringify({formTouched:Or,isOffline:ct?vr:"disabled",passwordStrength:rt?wr:"disabled",attemptCount:Me?ar:"disabled",validationErrors:mr,formId:qr},null,2)})]})]})})};export{E as default};
|
|
2
2
|
//# sourceMappingURL=LoginForm.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{slicedToArray as e,objectSpread2 as t,toConsumableArray as n,asyncToGenerator as r,regeneratorRuntime as a}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as i,jsxs as o}from"react/jsx-runtime";import c,{forwardRef as s,useRef as l,useState as u,useCallback as d,useImperativeHandle as h,useEffect as p}from"react";import b from"@mui/icons-material/FileDownloadOutlined";import m from"@mui/icons-material/RefreshOutlined";import f from"@mui/icons-material/InventoryOutlined";import v from"@mui/icons-material/ExpandMoreOutlined";import g from"@mui/icons-material/ExpandLessOutlined";import"../../../../node_modules/lodash/lodash.js";import{getNestedValue as N,reqOptions as x,API_HOST_URL as P}from"../../lib/helpFunction.js";import"../../lib/utils.js";import{l as y}from"../../../../_virtual/lodash.js";var k=s((function(s,k){var w,C,S=s.token,E=s.columns,j=s.defaultData,R=s.endpointPath,O=s.initialParams,M=void 0===O?{}:O,A=s.dataAdapter,H=s.title,L=s.emptyStateMessage,F=void 0===L?"No data available":L,D=s.emptyStateIcon,I=void 0===D?i(f,{}):D,T=s.actions,U=s.showSearch,_=void 0===U||U,B=s.searchPlaceholder,G=void 0===B?"Search...":B,J=s.searchDebounceMs,V=void 0===J?1e3:J,q=s.enableSorting,z=void 0===q||q,K=s.enableExport,Q=void 0!==K&&K,W=s.exportOptions,X=void 0===W?{csv:!0}:W,Y=s.rowsPerPageOptions,Z=void 0===Y?[10,25,50,100]:Y,$=s.defaultRowsPerPage,ee=void 0===$?10:$,te=s.onRowClick,ne=s.onFetchError,re=s.expandable,ae=void 0!==re&&re,ie=s.renderExpandedRow,oe=s.keyExtractor,ce=void 0===oe?function(e){return JSON.stringify(e)}:oe,se=s.stickyHeader,le=void 0!==se&&se,ue=s.maxHeight,de=s.hideHeaderOnMobile,he=void 0!==de&&de,pe=l(!0),be=l(null),me=u(j||[]),fe=e(me,2),ve=fe[0],ge=fe[1],Ne=u(!0),xe=e(Ne,2),Pe=xe[0],ye=xe[1],ke=u(null),we=e(ke,2),Ce=we[0],Se=we[1],Ee=u({totalCount:0,currentPage:1,perPage:ee,totalPages:0}),je=e(Ee,2),Re=je[0],Oe=je[1],Me=u(t({page:1,limit:ee},M)),Ae=e(Me,2),He=Ae[0],Le=Ae[1],Fe=u([]),De=e(Fe,2),Ie=De[0],Te=De[1],Ue=u(M.search||""),_e=e(Ue,2),Be=_e[0],Ge=_e[1],Je=d(y.exports.debounce((function(e){Le((function(n){return t(t({},n),{},{search:e,page:1})}))}),V),[]),Ve={data:j||[],pagination:{totalCount:null===(w=j||[])||void 0===w?void 0:w.length,currentPage:"",perPage:10,totalPages:Math.ceil(((null===(C=j||[])||void 0===C?void 0:C.length)||10)/10)},links:{next:"",previous:""}},qe=d(function(){var e=r(a().mark((function e(t){var n,r,i,o,c,s;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(ye(!0),e.prev=1,R){e.next=4;break}return e.abrupt("return",Ve);case 4:return n=new URLSearchParams({limit:t.limit.toString(),offset:((t.page-1)*t.limit).toString()}),t.search&&n.append("search",t.search),t.sort&&(r="desc"===t.direction?"-":"",n.append("ordering","".concat(r).concat(t.sort))),i=x("GET",null,S),o="".concat(P).concat(R,"?").concat(n.toString()),e.next=11,fetch(o,i);case 11:return c=e.sent,e.next=14,c.json();case 14:return s=e.sent,e.abrupt("return",{data:s.results,pagination:{totalCount:s.count,currentPage:Math.floor(parseInt(new URLSearchParams(s.next).get("offset")||"0")/t.limit),perPage:t.limit,totalPages:Math.ceil(s.count/t.limit)},links:{next:s.next,previous:s.previous}});case 18:throw e.prev=18,e.t0=e.catch(1),console.error("Error fetching program courses:",e.t0),e.t0;case 22:return e.prev=22,ye(!1),e.finish(22);case 25:case"end":return e.stop()}}),e,null,[[1,18,22,25]])})));return function(t){return e.apply(this,arguments)}}(),[]),ze=d((function(e){var t=e.target.value;Ge(t),Je(t)}),[Je]),Ke=d((function(e){Le((function(n){return t(t({},n),{},{page:e})}))}),[]),Qe=d((function(e){Le((function(n){return t(t({},n),{},{page:1,limit:e})}))}),[]),We=d((function(e){if(z&&e.sortable&&"string"==typeof e.accessor){var n=e.accessor;Le((function(e){return e.sort===n?t(t({},e),{},{direction:"asc"===e.direction?"desc":"asc"}):t(t({},e),{},{sort:n,direction:"asc"})}))}}),[z]),Xe=d((function(){Le((function(e){return t({},e)}))}),[]);h(k,(function(){return{refresh:Xe}}),[Xe]);var Ye=d(function(){var e=r(a().mark((function e(r){var i,o,c,s,l,u,d,h,p,b;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Q){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,ye(!0),i=t(t({},He),{},{page:1,limit:1e3,export:r}),e.next=7,qe(i);case 7:(o=e.sent)&&(c=A?A(o).data:o.data,s=X.fileName||"table-export","csv"===r&&(l=E.filter((function(e){return"string"==typeof e.accessor})).map((function(e){return e.header})),u=c.map((function(e){return E.filter((function(e){return"string"==typeof e.accessor})).map((function(t){var n,r=t.accessor;return String(null!==(n=e[r])&&void 0!==n?n:"")})).join(",")})),d=[l.join(",")].concat(n(u)).join("\n"),h=new Blob([d],{type:"text/csv;charset=utf-8;"}),p=document.createElement("a"),b=URL.createObjectURL(h),p.setAttribute("href",b),p.setAttribute("download","".concat(s,".csv")),p.style.visibility="hidden",document.body.appendChild(p),p.click(),document.body.removeChild(p))),e.next=15;break;case 11:e.prev=11,e.t0=e.catch(2),console.error("Export error:",e.t0),ne&&ne(e.t0);case 15:return e.prev=15,ye(!1),e.finish(15);case 18:case"end":return e.stop()}}),e,null,[[2,11,15,18]])})));return function(t){return e.apply(this,arguments)}}(),[E,He,Q,X,A,ne]),Ze=d((function(e,t){t.stopPropagation(),Te((function(t){return t.includes(e)?t.filter((function(t){return t!==e})):[].concat(n(t),[e])}))}),[]);return p((function(){var e=!0,t=function(){var t=r(a().mark((function t(){var n,r;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,ye(!0),t.next=4,qe(He);case 4:n=t.sent,e&&(A?(r=A(n),ge(r.data),r.pagination&&Oe(r.pagination)):n&&(ge(n.data),n.pagination&&Oe(n.pagination)),Se(null)),t.next=12;break;case 8:t.prev=8,t.t0=t.catch(0),console.error("Error fetching data:",t.t0),e&&(Se(t.t0),ne&&ne(t.t0));case 12:return t.prev=12,e&&(ye(!1),pe.current=!1),t.finish(12);case 15:case"end":return t.stop()}}),t,null,[[0,8,12,15]])})));return function(){return t.apply(this,arguments)}}();return t(),function(){e=!1}}),[He,A,ne]),Pe&&pe.current?o("div",{className:"ihub-data-list-container",children:[H&&i("h2",{children:H}),i("div",{className:"ihub-loading-state",children:i("p",{children:"Loading data..."})})]}):Ce&&!Pe&&0===(ve||[]).length?o("div",{className:"ihub-data-list-container",children:[H&&i("h2",{children:H}),o("div",{className:"ihub-error-state",children:[i("p",{children:"Error loading data. Please try again."}),i("button",{className:"ihub-important-btn",onClick:Xe,children:"Retry"})]})]}):o("div",{className:"ihub-data-list-container",ref:be,children:[(H||T||_||Q)&&o("div",{className:"ihub-data-list-header ihub-table-header ihub-p-0",children:[i("div",{children:H&&i("h2",{children:H})}),o("div",{className:"ihub-table-controls",children:[_&&i("div",{className:"ihub-table-search",children:o("div",{className:"ihub-search-input-wrapper",children:[i("input",{type:"text",placeholder:G,value:Be,onChange:ze,className:"ihub-search-input"}),Pe&&i("div",{className:"ihub-search-loading-indicator",children:i("span",{className:"ihub-loading-dot"})})]})}),Q&&o("div",{className:"ihub-export-buttons",children:[X.csv&&o("button",{className:"ihub-export-button ihub-export-csv",onClick:function(){return Ye("csv")},disabled:Pe,children:[i(b,{}),"CSV"]}),X.excel&&o("button",{className:"ihub-export-button ihub-export-excel",onClick:function(){return Ye("excel")},disabled:Pe,children:[i(b,{}),"Excel"]}),X.pdf&&o("button",{className:"ihub-export-button ihub-export-pdf",onClick:function(){return Ye("pdf")},disabled:Pe,children:[i(b,{}),"PDF"]})]}),o("button",{className:"ihub-refresh-button",onClick:Xe,disabled:Pe,children:[i(m,{}),"Refresh"]}),T&&i("div",{className:"ihub-data-controls ihub-mb-0",children:T})]})]}),Pe&&!pe.current&&i("div",{className:"ihub-table-loading-overlay",children:i("div",{className:"ihub-loading-spinner"})}),o("div",{className:"ihub-scroll-container ".concat(le?"ihub-sticky-header":""),style:ue?{maxHeight:ue}:void 0,children:[o("table",{className:"ihub-table ihub-scroll-container",children:[i("thead",{className:he?"ihub-hide-on-mobile":"",children:o("tr",{children:[ae&&ie&&i("th",{style:{width:"40px"}}),E.map((function(e,t){return i("th",{className:"".concat(e.sortable&&z?"ihub-sortable-column":""," ").concat(He.sort===e.accessor?"ihub-sorted-".concat(He.direction):""),style:e.width?{width:e.width}:void 0,onClick:function(){return e.sortable&&z?We(e):void 0},children:o("div",{className:"ihub-column-header",children:[i("span",{children:e.header}),e.sortable&&z&&i("span",{className:"ihub-sort-icon",children:He.sort===e.accessor&&"asc"===He.direction?"▲":He.sort===e.accessor&&"desc"===He.direction?"▼":"⇅"})]})},t)}))]})}),Pe||0!==(ve||[]).length?i("tbody",{children:ve.map((function(e,t){var n=ce(e),r=Ie.includes(n);return o(c.Fragment,{children:[o("tr",{onClick:function(){return te&&te(e)},className:te?"ihub-clickable-row":"",children:[ae&&ie&&i("td",{onClick:function(e){return Ze(n,e)},children:i(r?g:v,{})}),E.map((function(t,n){return i("td",{"data-label":he?t.header:void 0,children:t.tooltip&&"string"==typeof t.accessor?i("div",{className:"ihub-cell-tooltip","data-tooltip":String(N(e,t.accessor)),children:t.cell?t.cell(e):N(e,t.accessor)}):t.cell?t.cell(e):"function"==typeof t.accessor?t.accessor(e):N(e,t.accessor)},n)}))]}),ae&&ie&&r&&i("tr",{className:"ihub-expanded-row",children:i("td",{colSpan:(E||[]).length+1,children:i("div",{className:"ihub-row-details",children:ie(e)})})})]},n)}))}):""]}),Pe||0!==(ve||[]).length?"":o("div",{className:"ihub-data-list-container",children:[T&&i("div",{className:"ihub-data-controls ihub-mb-0",children:T}),i("div",{className:"ihub-empty-state",children:o("div",{children:[I,i("p",{children:F})]})})]})]}),Re&&Re.totalPages>1&&o("div",{className:"ihub-table-pagination",children:[o("div",{className:"ihub-pagination-info",children:["Showing ",(Re.currentPage-1)*Re.perPage+1," to"," ",Math.min(Re.currentPage*Re.perPage,Re.totalCount)," ","of ",Re.totalCount," entries"]}),o("div",{className:"ihub-pagination-controls",children:[i("button",{className:"ihub-pagination-button",disabled:1===Re.currentPage||Pe,onClick:function(){return Ke(1)},children:"«"}),i("button",{className:"ihub-pagination-button",disabled:1===Re.currentPage||Pe,onClick:function(){return Ke(Re.currentPage-1)},children:"‹"}),Array.from({length:Math.min(5,Re.totalPages)},(function(e,t){var n;return n=Re.totalPages<=5||Re.currentPage<=3?t+1:Re.currentPage>=Re.totalPages-2?Re.totalPages-4+t:Re.currentPage-2+t,i("button",{className:"ihub-pagination-button ".concat(Re.currentPage===n?"ihub-active":""),onClick:function(){return Ke(Number(n))},disabled:Pe,children:n},n)})),i("button",{className:"ihub-pagination-button",disabled:Re.currentPage===Re.totalPages||Pe,onClick:function(){return Ke(Re.currentPage+1)},children:"›"}),i("button",{className:"ihub-pagination-button",disabled:Re.currentPage===Re.totalPages||Pe,onClick:function(){return Ke(Re.totalPages)},children:"»"})]}),o("div",{className:"ihub-rows-per-page",children:[i("span",{children:"Rows per page:"}),i("select",{value:Re.perPage,onChange:function(e){return Qe(Number(e.target.value))},className:"ihub-rows-select",disabled:Pe,children:Z.map((function(e){return i("option",{value:e,children:e},e)}))})]})]})]})}));k.displayName="IHubTableServer";export{k as IHubTableServer,k as default};
|
|
1
|
+
import{slicedToArray as e,objectSpread2 as t,toConsumableArray as n,asyncToGenerator as r,regeneratorRuntime as a}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as i,jsxs as o}from"react/jsx-runtime";import c,{forwardRef as s,useRef as l,useState as u,useCallback as d,useImperativeHandle as h,useEffect as p}from"react";import b from"@mui/icons-material/FileDownloadOutlined";import m from"@mui/icons-material/RefreshOutlined";import f from"@mui/icons-material/InventoryOutlined";import v from"@mui/icons-material/ExpandMoreOutlined";import g from"@mui/icons-material/ExpandLessOutlined";import"../../../../node_modules/lodash/lodash.js";import{getNestedValue as N,reqOptions as P,API_HOST_URL as x}from"../../lib/helpFunction.js";import"../../lib/utils.js";import{l as y}from"../../../../_virtual/lodash.js";var k=s((function(s,k){var w,C,S=s.token,E=s.columns,j=s.defaultData,R=s.endpointPath,O=s.initialParams,M=void 0===O?{}:O,A=s.searchParams,H=s.dataAdapter,L=s.title,F=s.emptyStateMessage,D=void 0===F?"No data available":F,I=s.emptyStateIcon,T=void 0===I?i(f,{}):I,U=s.actions,_=s.showSearch,B=void 0===_||_,G=s.searchPlaceholder,J=void 0===G?"Search...":G,V=s.searchDebounceMs,q=void 0===V?1e3:V,z=s.enableSorting,K=void 0===z||z,Q=s.enableExport,W=void 0!==Q&&Q,X=s.exportOptions,Y=void 0===X?{csv:!0}:X,Z=s.rowsPerPageOptions,$=void 0===Z?[10,25,50,100]:Z,ee=s.defaultRowsPerPage,te=void 0===ee?10:ee,ne=s.onRowClick,re=s.onFetchError,ae=s.expandable,ie=void 0!==ae&&ae,oe=s.renderExpandedRow,ce=s.keyExtractor,se=void 0===ce?function(e){return JSON.stringify(e)}:ce,le=s.stickyHeader,ue=void 0!==le&&le,de=s.maxHeight,he=s.hideHeaderOnMobile,pe=void 0!==he&&he,be=l(!0),me=l(null),fe=u(j||[]),ve=e(fe,2),ge=ve[0],Ne=ve[1],Pe=u(!0),xe=e(Pe,2),ye=xe[0],ke=xe[1],we=u(null),Ce=e(we,2),Se=Ce[0],Ee=Ce[1],je=u({totalCount:0,currentPage:1,perPage:te,totalPages:0}),Re=e(je,2),Oe=Re[0],Me=Re[1],Ae=u(t({page:1,limit:te},M)),He=e(Ae,2),Le=He[0],Fe=He[1],De=u([]),Ie=e(De,2),Te=Ie[0],Ue=Ie[1],_e=u(M.search||""),Be=e(_e,2),Ge=Be[0],Je=Be[1],Ve=d(y.exports.debounce((function(e){Fe((function(n){return t(t({},n),{},{search:e,page:1})}))}),q),[]),qe={data:j||[],pagination:{totalCount:null===(w=j||[])||void 0===w?void 0:w.length,currentPage:"",perPage:10,totalPages:Math.ceil(((null===(C=j||[])||void 0===C?void 0:C.length)||10)/10)},links:{next:"",previous:""}},ze=d(function(){var t=r(a().mark((function t(n){var r,i,o,c,s,l;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(ke(!0),t.prev=1,R){t.next=4;break}return t.abrupt("return",qe);case 4:return r=new URLSearchParams({limit:n.limit.toString(),offset:((n.page-1)*n.limit).toString()}),n.search&&r.append("search",n.search),n.sort&&(i="desc"===n.direction?"-":"",r.append("ordering","".concat(i).concat(n.sort))),A&&Object.entries(A).forEach((function(t){var n=e(t,2),a=n[0],i=n[1];null!=i&&""!==i&&r.append(a,String(i))})),o=P("GET",null,S),c="".concat(x).concat(R,"?").concat(r.toString()),t.next=12,fetch(c,o);case 12:return s=t.sent,t.next=15,s.json();case 15:return l=t.sent,t.abrupt("return",{data:l.results,pagination:{totalCount:l.count,currentPage:Math.floor(parseInt(new URLSearchParams(l.next).get("offset")||"0")/n.limit),perPage:n.limit,totalPages:Math.ceil(l.count/n.limit)},links:{next:l.next,previous:l.previous}});case 19:throw t.prev=19,t.t0=t.catch(1),console.error("Error fetching program courses:",t.t0),t.t0;case 23:return t.prev=23,ke(!1),t.finish(23);case 26:case"end":return t.stop()}}),t,null,[[1,19,23,26]])})));return function(e){return t.apply(this,arguments)}}(),[A]),Ke=d((function(e){var t=e.target.value;Je(t),Ve(t)}),[Ve]),Qe=d((function(e){Fe((function(n){return t(t({},n),{},{page:e})}))}),[]),We=d((function(e){Fe((function(n){return t(t({},n),{},{page:1,limit:e})}))}),[]),Xe=d((function(e){if(K&&e.sortable&&"string"==typeof e.accessor){var n=e.accessor;Fe((function(e){return e.sort===n?t(t({},e),{},{direction:"asc"===e.direction?"desc":"asc"}):t(t({},e),{},{sort:n,direction:"asc"})}))}}),[K]),Ye=d((function(){Fe((function(e){return t({},e)}))}),[]);h(k,(function(){return{refresh:Ye}}),[Ye]);var Ze=d(function(){var e=r(a().mark((function e(r){var i,o,c,s,l,u,d,h,p,b;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(W){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,ke(!0),i=t(t({},Le),{},{page:1,limit:1e3,export:r}),e.next=7,ze(i);case 7:(o=e.sent)&&(c=H?H(o).data:o.data,s=Y.fileName||"table-export","csv"===r&&(l=E.filter((function(e){return"string"==typeof e.accessor})).map((function(e){return e.header})),u=c.map((function(e){return E.filter((function(e){return"string"==typeof e.accessor})).map((function(t){var n,r=t.accessor;return String(null!==(n=e[r])&&void 0!==n?n:"")})).join(",")})),d=[l.join(",")].concat(n(u)).join("\n"),h=new Blob([d],{type:"text/csv;charset=utf-8;"}),p=document.createElement("a"),b=URL.createObjectURL(h),p.setAttribute("href",b),p.setAttribute("download","".concat(s,".csv")),p.style.visibility="hidden",document.body.appendChild(p),p.click(),document.body.removeChild(p))),e.next=15;break;case 11:e.prev=11,e.t0=e.catch(2),console.error("Export error:",e.t0),re&&re(e.t0);case 15:return e.prev=15,ke(!1),e.finish(15);case 18:case"end":return e.stop()}}),e,null,[[2,11,15,18]])})));return function(t){return e.apply(this,arguments)}}(),[E,Le,W,Y,H,re]),$e=d((function(e,t){t.stopPropagation(),Ue((function(t){return t.includes(e)?t.filter((function(t){return t!==e})):[].concat(n(t),[e])}))}),[]);return p((function(){var e=!0,t=function(){var t=r(a().mark((function t(){var n,r;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,ke(!0),t.next=4,ze(Le);case 4:n=t.sent,e&&(H?(r=H(n),Ne(r.data),r.pagination&&Me(r.pagination)):n&&(Ne(n.data),n.pagination&&Me(n.pagination)),Ee(null)),t.next=12;break;case 8:t.prev=8,t.t0=t.catch(0),console.error("Error fetching data:",t.t0),e&&(Ee(t.t0),re&&re(t.t0));case 12:return t.prev=12,e&&(ke(!1),be.current=!1),t.finish(12);case 15:case"end":return t.stop()}}),t,null,[[0,8,12,15]])})));return function(){return t.apply(this,arguments)}}();return t(),function(){e=!1}}),[Le,H,re]),p((function(){A&&!be.current&&Fe((function(e){return t({},e)}))}),[A]),ye&&be.current?o("div",{className:"ihub-data-list-container",children:[L&&i("h2",{children:L}),i("div",{className:"ihub-loading-state",children:i("p",{children:"Loading data..."})})]}):Se&&!ye&&0===(ge||[]).length?o("div",{className:"ihub-data-list-container",children:[L&&i("h2",{children:L}),o("div",{className:"ihub-error-state",children:[i("p",{children:"Error loading data. Please try again."}),i("button",{className:"ihub-important-btn",onClick:Ye,children:"Retry"})]})]}):o("div",{className:"ihub-data-list-container",ref:me,children:[(L||U||B||W)&&o("div",{className:"ihub-data-list-header ihub-table-header ihub-p-0",children:[i("div",{children:L&&i("h2",{children:L})}),o("div",{className:"ihub-table-controls",children:[B&&i("div",{className:"ihub-table-search",children:o("div",{className:"ihub-search-input-wrapper",children:[i("input",{type:"text",placeholder:J,value:Ge,onChange:Ke,className:"ihub-search-input"}),ye&&i("div",{className:"ihub-search-loading-indicator",children:i("span",{className:"ihub-loading-dot"})})]})}),W&&o("div",{className:"ihub-export-buttons",children:[Y.csv&&o("button",{className:"ihub-export-button ihub-export-csv",onClick:function(){return Ze("csv")},disabled:ye,children:[i(b,{}),"CSV"]}),Y.excel&&o("button",{className:"ihub-export-button ihub-export-excel",onClick:function(){return Ze("excel")},disabled:ye,children:[i(b,{}),"Excel"]}),Y.pdf&&o("button",{className:"ihub-export-button ihub-export-pdf",onClick:function(){return Ze("pdf")},disabled:ye,children:[i(b,{}),"PDF"]})]}),o("button",{className:"ihub-refresh-button",onClick:Ye,disabled:ye,children:[i(m,{}),"Refresh"]}),U&&i("div",{className:"ihub-data-controls ihub-mb-0",children:U})]})]}),ye&&!be.current&&i("div",{className:"ihub-table-loading-overlay",children:i("div",{className:"ihub-loading-spinner"})}),o("div",{className:"ihub-scroll-container ".concat(ue?"ihub-sticky-header":""),style:de?{maxHeight:de}:void 0,children:[o("table",{className:"ihub-table ihub-scroll-container",children:[i("thead",{className:pe?"ihub-hide-on-mobile":"",children:o("tr",{children:[ie&&oe&&i("th",{style:{width:"40px"}}),E.map((function(e,t){return i("th",{className:"".concat(e.sortable&&K?"ihub-sortable-column":""," ").concat(Le.sort===e.accessor?"ihub-sorted-".concat(Le.direction):""),style:e.width?{width:e.width}:void 0,onClick:function(){return e.sortable&&K?Xe(e):void 0},children:o("div",{className:"ihub-column-header",children:[i("span",{children:e.header}),e.sortable&&K&&i("span",{className:"ihub-sort-icon",children:Le.sort===e.accessor&&"asc"===Le.direction?"▲":Le.sort===e.accessor&&"desc"===Le.direction?"▼":"⇅"})]})},t)}))]})}),ye||0!==(ge||[]).length?i("tbody",{children:ge.map((function(e,t){var n=se(e),r=Te.includes(n);return o(c.Fragment,{children:[o("tr",{onClick:function(){return ne&&ne(e)},className:ne?"ihub-clickable-row":"",children:[ie&&oe&&i("td",{onClick:function(e){return $e(n,e)},children:i(r?g:v,{})}),E.map((function(t,n){return i("td",{"data-label":pe?t.header:void 0,children:t.tooltip&&"string"==typeof t.accessor?i("div",{className:"ihub-cell-tooltip","data-tooltip":String(N(e,t.accessor)),children:t.cell?t.cell(e):N(e,t.accessor)}):t.cell?t.cell(e):"function"==typeof t.accessor?t.accessor(e):N(e,t.accessor)},n)}))]}),ie&&oe&&r&&i("tr",{className:"ihub-expanded-row",children:i("td",{colSpan:(E||[]).length+1,children:i("div",{className:"ihub-row-details",children:oe(e)})})})]},n)}))}):""]}),ye||0!==(ge||[]).length?"":o("div",{className:"ihub-data-list-container",children:[U&&i("div",{className:"ihub-data-controls ihub-mb-0",children:U}),i("div",{className:"ihub-empty-state",children:o("div",{children:[T,i("p",{children:D})]})})]})]}),Oe&&Oe.totalPages>1&&o("div",{className:"ihub-table-pagination",children:[o("div",{className:"ihub-pagination-info",children:["Showing ",(Oe.currentPage-1)*Oe.perPage+1," to"," ",Math.min(Oe.currentPage*Oe.perPage,Oe.totalCount)," ","of ",Oe.totalCount," entries"]}),o("div",{className:"ihub-pagination-controls",children:[i("button",{className:"ihub-pagination-button",disabled:1===Oe.currentPage||ye,onClick:function(){return Qe(1)},children:"«"}),i("button",{className:"ihub-pagination-button",disabled:1===Oe.currentPage||ye,onClick:function(){return Qe(Oe.currentPage-1)},children:"‹"}),Array.from({length:Math.min(5,Oe.totalPages)},(function(e,t){var n;return n=Oe.totalPages<=5||Oe.currentPage<=3?t+1:Oe.currentPage>=Oe.totalPages-2?Oe.totalPages-4+t:Oe.currentPage-2+t,i("button",{className:"ihub-pagination-button ".concat(Oe.currentPage===n?"ihub-active":""),onClick:function(){return Qe(Number(n))},disabled:ye,children:n},n)})),i("button",{className:"ihub-pagination-button",disabled:Oe.currentPage===Oe.totalPages||ye,onClick:function(){return Qe(Oe.currentPage+1)},children:"›"}),i("button",{className:"ihub-pagination-button",disabled:Oe.currentPage===Oe.totalPages||ye,onClick:function(){return Qe(Oe.totalPages)},children:"»"})]}),o("div",{className:"ihub-rows-per-page",children:[i("span",{children:"Rows per page:"}),i("select",{value:Oe.perPage,onChange:function(e){return We(Number(e.target.value))},className:"ihub-rows-select",disabled:ye,children:$.map((function(e){return i("option",{value:e,children:e},e)}))})]})]})]})}));k.displayName="IHubTableServer";export{k as IHubTableServer,k as default};
|
|
2
2
|
//# sourceMappingURL=IHubTableServer.js.map
|
|
@@ -1,16 +1,77 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Props for the FileField component
|
|
4
|
+
*/
|
|
2
5
|
interface FileFieldProps {
|
|
6
|
+
/**
|
|
7
|
+
* Callback function triggered when a file is selected
|
|
8
|
+
* @param file - The selected File object
|
|
9
|
+
*/
|
|
3
10
|
onChange?: (file: File) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Default image URL to display as preview
|
|
13
|
+
*/
|
|
4
14
|
defaultImageUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Label text displayed above the file input
|
|
17
|
+
*/
|
|
5
18
|
label?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Name attribute for the file input element
|
|
21
|
+
*/
|
|
6
22
|
name?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Whether the file input is required
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
7
27
|
required?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Data name attribute for the file input
|
|
30
|
+
*/
|
|
8
31
|
dataName?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Maximum file size limit in megabytes
|
|
34
|
+
* @default 10
|
|
35
|
+
*/
|
|
9
36
|
maxLimit?: number;
|
|
37
|
+
/**
|
|
38
|
+
* ID attribute for the file input element
|
|
39
|
+
*/
|
|
10
40
|
id?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Additional CSS classes to apply to the file input
|
|
43
|
+
*/
|
|
11
44
|
className?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Accepted file types (MIME types and extensions)
|
|
47
|
+
* @default "image/*, .pdf, .doc, .docx, .txt"
|
|
48
|
+
*/
|
|
12
49
|
acceptedTypes?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Helper text displayed below the input (currently unused in implementation)
|
|
52
|
+
*/
|
|
13
53
|
helperText?: string;
|
|
14
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* FileField component for file upload with preview functionality
|
|
57
|
+
*
|
|
58
|
+
* Provides a file input field with automatic preview generation for images
|
|
59
|
+
* and file size validation. Supports various file types and displays
|
|
60
|
+
* appropriate previews based on file type.
|
|
61
|
+
*
|
|
62
|
+
* @param props - The component props
|
|
63
|
+
* @returns A file input component with preview capabilities
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```tsx
|
|
67
|
+
* <FileField
|
|
68
|
+
* label="Upload Document"
|
|
69
|
+
* onChange={(file) => console.log('Selected file:', file)}
|
|
70
|
+
* maxLimit={5}
|
|
71
|
+
* acceptedTypes="image/*, .pdf"
|
|
72
|
+
* required
|
|
73
|
+
* />
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
15
76
|
declare const FileField: React.FC<FileFieldProps>;
|
|
16
77
|
export default FileField;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { ApiResponseType, TableColumnType } from "@/types";
|
|
2
|
+
import { ApiResponseType, SearchParamsType, TableColumnType } from "@/types";
|
|
3
3
|
import { FetchParamsType } from "@/types";
|
|
4
4
|
export interface IHubTableServerRef {
|
|
5
5
|
refresh: () => void;
|
|
@@ -11,6 +11,8 @@ interface IHubTableServerPropsType<T> {
|
|
|
11
11
|
defaultData?: any[];
|
|
12
12
|
endpointPath: string;
|
|
13
13
|
initialParams?: Partial<FetchParamsType>;
|
|
14
|
+
/** External search parameters that trigger table refetch when changed */
|
|
15
|
+
searchParams?: SearchParamsType;
|
|
14
16
|
dataAdapter?: (apiResponse: any) => ApiResponseType<T>;
|
|
15
17
|
title?: string;
|
|
16
18
|
emptyStateMessage?: string;
|
|
@@ -49,6 +51,7 @@ interface IHubTableServerPropsType<T> {
|
|
|
49
51
|
* columns={columns}
|
|
50
52
|
* endpointPath={"/api/program-courses"}
|
|
51
53
|
* initialParams={{ sort: "title", direction: "asc" }}
|
|
54
|
+
* searchParams={{ category: "active", status: "published" }}
|
|
52
55
|
* title="Program Courses"
|
|
53
56
|
* showSearch={true}
|
|
54
57
|
* enableSorting={true}
|
|
@@ -85,6 +88,7 @@ interface IHubTableServerPropsType<T> {
|
|
|
85
88
|
* @prop {any<T>[]} defaultData - The default data of the table
|
|
86
89
|
* @prop {string} endpointPath - The path to the API endpoint
|
|
87
90
|
* @prop {Partial<FetchParamsType>} initialParams - The initial parameters for the API request
|
|
91
|
+
* @prop {Record<string, any>} searchParams - External search parameters that trigger table refetch when changed
|
|
88
92
|
* @prop {string} title - The title of the table
|
|
89
93
|
* @prop {boolean} showSearch - Whether to show the search input
|
|
90
94
|
* @prop {boolean} enableSorting - Whether to enable sorting
|
|
@@ -182,7 +182,7 @@ export interface SearchObjectItemType {
|
|
|
182
182
|
}
|
|
183
183
|
export interface TableColumnType<T> {
|
|
184
184
|
header: string;
|
|
185
|
-
accessor: keyof T | ((row: T) => React.ReactNode);
|
|
185
|
+
accessor: keyof T | ((row: T, index?: number) => React.ReactNode);
|
|
186
186
|
sortable?: boolean;
|
|
187
187
|
filterable?: boolean;
|
|
188
188
|
width?: string;
|