@instincthub/react-ui 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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/IHubTable.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/IHubTable.d.ts +7 -1
- package/dist/src/types/components/ui/tables/IHubTableServer.d.ts +6 -0
- package/dist/src/types/types/index.d.ts +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -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 n,defineProperty as t,toConsumableArray as i,asyncToGenerator as r,regeneratorRuntime as c}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as o,jsxs as a}from"react/jsx-runtime";import l,{useRef as u,useState as s,useCallback as d,useEffect as h,useMemo as m}from"react";import f from"@mui/icons-material/FileDownloadOutlined";import b from"@mui/icons-material/RefreshOutlined";import p from"@mui/icons-material/InventoryOutlined";import v from"@mui/icons-material/FilterAltOutlined";import g from"@mui/icons-material/FilterAltOffOutlined";import N from"@mui/icons-material/ExpandMoreOutlined";import x from"@mui/icons-material/ExpandLessOutlined";import y from"@mui/icons-material/VisibilityOutlined";import C from"@mui/icons-material/EditOutlined";import k from"@mui/icons-material/DeleteOutlined";import w from"@mui/icons-material/UnfoldLessOutlined";var S=function(S){var O=S.columns,L=S.data,E=S.isLoading,P=void 0!==E&&E,M=S.emptyStateMessage,R=void 0===M?"No data available":M,F=S.emptyStateIcon,j=void 0===F?o(p,{}):F,A=S.title,D=S.showSearch,H=void 0!==D&&D,U=S.pagination,V=void 0===U||U,B=S.rowsPerPageOptions,I=void 0===B?[10,25,50]:B,J=S.defaultRowsPerPage,T=void 0===J?10:J,_=S.actions,G=S.onRowClick,X=S.keyExtractor,Y=void 0===X?function(e,n){return n}:X,q=S.hideHeaderOnMobile,z=void 0!==q&&q,K=S.stickyHeader,Q=void 0!==K&&K,W=S.maxHeight,Z=S.sortable,$=void 0===Z||Z,ee=S.defaultSortColumn,ne=S.defaultSortDirection,te=void 0===ne?"asc":ne,ie=S.onSort,re=S.onFilter,ce=S.selectable,oe=void 0!==ce&&ce,ae=S.onSelectionChange,le=S.expandable,ue=void 0!==le&&le,se=S.renderExpandedRow,de=S.exportOptions,he=S.refreshable,me=void 0!==he&&he,fe=S.onRefresh,be=u(null),pe=u(!0),ve=s(""),ge=e(ve,2),Ne=ge[0],xe=ge[1],ye=s(1),Ce=e(ye,2),ke=Ce[0],we=Ce[1],Se=s(T),Oe=e(Se,2),Le=Oe[0],Ee=Oe[1],Pe=s({column:ee,direction:te}),Me=e(Pe,2),Re=Me[0],Fe=Me[1],je=s({}),Ae=e(je,2),De=Ae[0],He=Ae[1],Ue=s(null),Ve=e(Ue,2),Be=Ve[0],Ie=Ve[1],Je=s([]),Te=e(Je,2),_e=Te[0],Ge=Te[1],Xe=s([]),Ye=e(Xe,2),qe=Ye[0],ze=Ye[1],Ke=s(!1),Qe=e(Ke,2),We=Qe[0],Ze=Qe[1],$e=s({visible:!1,x:0,y:0,row:null}),en=e($e,2),nn=en[0],tn=en[1],rn=d((function(e,n){return Y(e,n)}),[]);h((function(){var e=function(e){Be&&be.current&&!be.current.contains(e.target)&&Ie(null),nn.visible&&tn((function(e){return n(n({},e),{},{visible:!1})}))};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[Be,nn.visible]),h((function(){pe.current?pe.current=!1:0!==(L||[]).length?Ge((function(e){if(0===(e||[]).length)return e;var n=e.filter((function(e){return L.some((function(n){return JSON.stringify(n)===JSON.stringify(e)}))}));return(n||[]).length!==(e||[]).length?n:e})):Ge([])}),[L]),h((function(){ae&&!pe.current&&ae(_e)}),[_e]);var cn=d((function(e){if($&&e.sortable&&"string"==typeof e.accessor){var n=e.accessor;Fe((function(e){if(e.column===n){var t="asc"===e.direction?"desc":"asc";return ie&&ie(n,t),{column:n,direction:t}}return ie&&ie(n,"asc"),{column:n,direction:"asc"}}))}}),[$,ie]),on=d((function(e,i){He((function(r){var c=n(n({},r),{},t({},e,i.length>0?i:null));return re&&re(c),c}))}),[re]),an=d((function(e,n,t){Ge((function(r){return n?[].concat(i(r),[e]):r.filter((function(n,i){return rn(n,i)!==rn(e,t)}))}))}),[rn]),ln=d((function(e){Ge(e?i(L):[])}),[L]),un=d((function(e,n){return _e.some((function(t,i){return rn(t,i)===rn(e,n)}))}),[_e,rn]),sn=d((function(e,n){n.stopPropagation(),ze((function(n){return n.includes(e)?n.filter((function(n){return n!==e})):[].concat(i(n),[e])}))}),[]),dn=d((function(e,n){e.preventDefault(),tn({visible:!0,x:e.clientX,y:e.clientY,row:n})}),[]),hn=d(r(c().mark((function e(){return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!fe){e.next=13;break}return Ze(!0),e.prev=2,e.next=5,fe();case 5:e.next=10;break;case 7:e.prev=7,e.t0=e.catch(2),console.error("Error refreshing data:",e.t0);case 10:return e.prev=10,Ze(!1),e.finish(10);case 13:case"end":return e.stop()}}),e,null,[[2,7,10,13]])}))),[fe]),mn=d((function(e){if(de){var n=de.fileName||"table-export";if("csv"===e){var t=O.filter((function(e){return"string"==typeof e.accessor})).map((function(e){return e.header})),r=L.map((function(e){return O.filter((function(e){return"string"==typeof e.accessor})).map((function(n){var t,i=n.accessor;return String(null!==(t=e[i])&&void 0!==t?t:"")})).join(",")})),c=[t.join(",")].concat(i(r)).join("\n"),o=new Blob([c],{type:"text/csv;charset=utf-8;"}),a=document.createElement("a"),l=URL.createObjectURL(o);a.setAttribute("href",l),a.setAttribute("download","".concat(n,".csv")),a.style.visibility="hidden",document.body.appendChild(a),a.click(),document.body.removeChild(a)}}}),[O,L,de]),fn=m((function(){var n=L;return Ne.trim()&&(n=n.filter((function(e){return O.some((function(n){if("string"==typeof n.accessor){var t=e[n.accessor];return String(t).toLowerCase().includes(Ne.toLowerCase())}return!1}))}))),Object.entries(De).forEach((function(t){var i=e(t,2),r=i[0],c=i[1];null!==c&&(n=n.filter((function(e){return String(e[r]||"").toLowerCase().includes(String(c).toLowerCase())})))})),n}),[L,Ne,O,De]),bn=m((function(){return Re.column?i(fn).sort((function(e,n){var t=Re.column,i=e[t],r=n[t];if(i===r)return 0;var c=i<r?-1:1;return"asc"===Re.direction?c:-c})):fn}),[fn,Re.column,Re.direction]),pn=m((function(){if(!V)return bn;var e=(ke-1)*Le;return bn.slice(e,e+Le)}),[bn,V,ke,Le]),vn=m((function(){return V?Math.ceil(bn.length/Le):1}),[bn.length,Le,V]);return h((function(){we(1)}),[Ne,Le,De]),P||We?a("div",{className:"ihub-data-list-container",children:[A&&o("h2",{children:A}),o("div",{className:"ihub-loading-state",children:o("p",{children:"Loading data..."})})]}):P||L&&0!==L.length?a("div",{className:"ihub-data-list-container",ref:be,children:[(A||_||H||de||me)&&a("div",{className:"ihub-data-list-header ihub-table-header ihub-p-0",children:[o("div",{children:A&&o("h2",{children:A})}),a("div",{className:"ihub-table-controls",children:[H&&o("div",{className:"ihub-table-search",children:o("input",{type:"text",placeholder:"Search...",value:Ne,onChange:function(e){return xe(e.target.value)},className:"ihub-search-input"})}),de&&a("div",{className:"ihub-export-buttons",children:[de.csv&&a("button",{className:"ihub-export-button ihub-export-csv",onClick:function(){return mn("csv")},children:[o(f,{}),"CSV"]}),de.excel&&a("button",{className:"ihub-export-button ihub-export-excel",onClick:function(){return mn("excel")},children:[o(f,{}),"Excel"]}),de.pdf&&a("button",{className:"ihub-export-button ihub-export-pdf",onClick:function(){return mn("pdf")},children:[o(f,{}),"PDF"]})]}),me&&fe&&a("button",{className:"ihub-export-button",onClick:hn,disabled:We,children:[o(b,{}),"Refresh"]}),_&&o("div",{className:"ihub-data-controls ihub-mb-0",children:_})]})]}),oe&&_e.length>0&&a("div",{className:"ihub-selection-summary",children:[a("p",{children:[_e.length," item(s) selected"]}),o("button",{className:"ihub-outlined-btn",onClick:function(){return Ge([])},children:"Clear Selection"})]}),o("div",{className:"ihub-scroll-container ".concat(Q?"ihub-sticky-header":""),style:W?{maxHeight:W}:void 0,children:a("table",{className:"ihub-table ihub-scroll-container",children:[o("thead",{className:z?"ihub-hide-on-mobile":"",children:a("tr",{children:[oe&&o("th",{className:"ihub-checkbox-cell",children:o("div",{className:"ihub-checkbox-header",children:o("input",{type:"checkbox",checked:_e.length===L.length&&L.length>0,onChange:function(e){return ln(e.target.checked)}})})}),ue&&se&&o("th",{style:{width:"40px"},children:o(w,{})}),O.map((function(e,n){return o("th",{className:"".concat(e.sortable&&$?"ihub-sortable-column":""," ").concat(Re.column===e.accessor?"ihub-sorted-".concat(Re.direction):""),style:e.width?{width:e.width}:void 0,children:a("div",{className:"ihub-column-header",children:[o("span",{onClick:function(){return e.sortable&&$?cn(e):void 0},style:{cursor:e.sortable&&$?"pointer":"default"},children:e.header}),e.sortable&&$&&o("span",{className:"ihub-sort-icon",onClick:function(){return cn(e)},children:Re.column===e.accessor&&"asc"===Re.direction?"▲":Re.column===e.accessor&&"desc"===Re.direction?"▼":"⇅"}),e.filterable&&"string"==typeof e.accessor&&a("div",{className:"ihub-column-filter",children:[o("button",{className:"ihub-filter-button",onClick:function(n){n.stopPropagation(),Ie(Be===e.accessor?null:e.accessor)},children:De[e.accessor]?o(g,{}):o(v,{})}),Be===e.accessor&&a("div",{className:"ihub-filter-dropdown",onClick:function(e){return e.stopPropagation()},children:[a("label",{children:["Filter ",e.header]}),o("input",{type:"text",className:"ihub-filter-input",value:De[e.accessor]||"",onChange:function(n){return on(e.accessor,n.target.value)},placeholder:"Filter by ".concat(e.header.toLowerCase()),autoFocus:!0}),a("div",{className:"ihub-filter-actions",children:[o("button",{className:"ihub-outlined-btn",onClick:function(){on(e.accessor,""),Ie(null)},children:"Clear"}),o("button",{className:"ihub-important-btn",onClick:function(){return Ie(null)},children:"Apply"})]})]})]})]})},n)}))]})}),o("tbody",{children:pn.map((function(e,n){var t=rn(e,n),i=qe.includes(t);return a(l.Fragment,{children:[a("tr",{onClick:function(){return G&&G(e)},onContextMenu:function(n){return dn(n,e)},className:"\n ".concat(G?"ihub-clickable-row":"","\n ").concat(un(e,n)?"ihub-selected-row":"","\n "),children:[oe&&o("td",{className:"ihub-checkbox-cell",onClick:function(e){return e.stopPropagation()},children:o("input",{type:"checkbox",checked:un(e,n),onChange:function(t){return an(e,t.target.checked,n)}})}),ue&&se&&o("td",{onClick:function(e){return sn(t,e)},children:o(i?x:N,{})}),O.map((function(n,t){var i,r,c;return o("td",{"data-label":z?n.header:void 0,children:n.tooltip&&"string"==typeof n.accessor?o("div",{className:"ihub-cell-tooltip","data-tooltip":String(null!==(i=e[n.accessor])&&void 0!==i?i:""),children:n.cell?n.cell(e):String(null!==(r=e[n.accessor])&&void 0!==r?r:"")}):n.cell?n.cell(e):"function"==typeof n.accessor?n.accessor(e):String(null!==(c=e[n.accessor])&&void 0!==c?c:"")},t)}))]}),ue&&se&&i&&o("tr",{className:"ihub-expanded-row",children:o("td",{colSpan:O.length+(oe?1:0)+1,children:o("div",{className:"ihub-row-details",children:se(e)})})})]},t)}))})]})}),nn.visible&&nn.row&&a("div",{className:"ihub-context-menu",style:{top:nn.y,left:nn.x},children:[a("div",{className:"ihub-context-menu-item",onClick:function(){nn.row&&G&&G(nn.row),tn((function(e){return n(n({},e),{},{visible:!1})}))},children:[o(y,{}),"View"]}),a("div",{className:"ihub-context-menu-item",onClick:function(){tn((function(e){return n(n({},e),{},{visible:!1})}))},children:[o(C,{}),"Edit"]}),o("div",{className:"ihub-context-menu-separator"}),a("div",{className:"ihub-context-menu-item",onClick:function(){tn((function(e){return n(n({},e),{},{visible:!1})}))},children:[o(k,{}),"Delete"]})]}),V&&vn>1&&a("div",{className:"ihub-table-pagination",children:[a("div",{className:"ihub-pagination-info",children:["Showing"," ",Math.min((ke-1)*Le+1,bn.length)," ","to ",Math.min(ke*Le,bn.length)," of"," ",bn.length," entries"]}),a("div",{className:"ihub-pagination-controls",children:[o("button",{className:"ihub-pagination-button",disabled:1===ke,onClick:function(){return we(1)},children:"«"}),o("button",{className:"ihub-pagination-button",disabled:1===ke,onClick:function(){return we((function(e){return Math.max(1,e-1)}))},children:"‹"}),Array.from({length:Math.min(5,vn)},(function(e,n){var t;return o("button",{className:"ihub-pagination-button ".concat(ke===(t=vn<=5||ke<=3?n+1:ke>=vn-2?vn-4+n:ke-2+n)?"ihub-active":""),onClick:function(){return we(Number(t))},children:t},t)})),o("button",{className:"ihub-pagination-button",disabled:ke===vn,onClick:function(){return we((function(e){return Math.min(vn,e+1)}))},children:"›"}),o("button",{className:"ihub-pagination-button",disabled:ke===vn,onClick:function(){return we(vn)},children:"»"})]}),a("div",{className:"ihub-rows-per-page",children:[o("span",{children:"Rows per page:"}),o("select",{value:Le,onChange:function(e){return Ee(Number(e.target.value))},className:"ihub-rows-select",children:I.map((function(e){return o("option",{value:e,children:e},e)}))})]})]})]}):a("div",{className:"ihub-data-list-container",children:[A&&o("h2",{children:A}),_&&o("div",{className:"ihub-data-controls ihub-mb-0",children:_}),o("div",{className:"ihub-empty-state",children:a("div",{children:[j,o("p",{children:R})]})})]})};export{S as IHubTable,S as default};
|
|
1
|
+
import{slicedToArray as e,objectSpread2 as n,defineProperty as t,toConsumableArray as i,asyncToGenerator as r,regeneratorRuntime as c}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as o,jsxs as a}from"react/jsx-runtime";import l,{useRef as u,useState as s,useCallback as d,useEffect as h,useMemo as m}from"react";import b from"@mui/icons-material/FileDownloadOutlined";import f from"@mui/icons-material/RefreshOutlined";import p from"@mui/icons-material/InventoryOutlined";import v from"@mui/icons-material/FilterAltOutlined";import g from"@mui/icons-material/FilterAltOffOutlined";import N from"@mui/icons-material/ExpandMoreOutlined";import x from"@mui/icons-material/ExpandLessOutlined";import y from"@mui/icons-material/VisibilityOutlined";import C from"@mui/icons-material/EditOutlined";import k from"@mui/icons-material/DeleteOutlined";import w from"@mui/icons-material/UnfoldLessOutlined";var S=function(S){var O=S.columns,L=S.data,E=S.isLoading,P=void 0!==E&&E,R=S.emptyStateMessage,A=void 0===R?"No data available":R,F=S.emptyStateIcon,M=void 0===F?o(p,{}):F,j=S.title,D=S.showSearch,H=void 0!==D&&D,U=S.pagination,V=void 0===U||U,B=S.rowsPerPageOptions,I=void 0===B?[10,25,50]:B,J=S.defaultRowsPerPage,T=void 0===J?10:J,_=S.actions,G=S.onRowClick,W=S.keyExtractor,X=void 0===W?function(e,n){return n}:W,Y=S.hideHeaderOnMobile,q=void 0!==Y&&Y,z=S.stickyHeader,K=void 0!==z&&z,Q=S.maxHeight,Z=S.sortable,$=void 0===Z||Z,ee=S.defaultSortColumn,ne=S.defaultSortDirection,te=void 0===ne?"asc":ne,ie=S.onSort,re=S.onFilter,ce=S.selectable,oe=void 0!==ce&&ce,ae=S.onSelectionChange,le=S.expandable,ue=void 0!==le&&le,se=S.renderExpandedRow,de=S.exportOptions,he=S.refreshable,me=void 0!==he&&he,be=S.onRefresh,fe=S.showRowNumbers,pe=void 0!==fe&&fe,ve=S.rowNumberStartFrom,ge=void 0===ve?1:ve,Ne=u(null),xe=u(!0),ye=s(""),Ce=e(ye,2),ke=Ce[0],we=Ce[1],Se=s(1),Oe=e(Se,2),Le=Oe[0],Ee=Oe[1],Pe=s(T),Re=e(Pe,2),Ae=Re[0],Fe=Re[1],Me=s({column:ee,direction:te}),je=e(Me,2),De=je[0],He=je[1],Ue=s({}),Ve=e(Ue,2),Be=Ve[0],Ie=Ve[1],Je=s(null),Te=e(Je,2),_e=Te[0],Ge=Te[1],We=s([]),Xe=e(We,2),Ye=Xe[0],qe=Xe[1],ze=s([]),Ke=e(ze,2),Qe=Ke[0],Ze=Ke[1],$e=s(!1),en=e($e,2),nn=en[0],tn=en[1],rn=s({visible:!1,x:0,y:0,row:null}),cn=e(rn,2),on=cn[0],an=cn[1],ln=d((function(e,n){return X(e,n)}),[]);h((function(){var e=function(e){_e&&Ne.current&&!Ne.current.contains(e.target)&&Ge(null),on.visible&&an((function(e){return n(n({},e),{},{visible:!1})}))};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[_e,on.visible]),h((function(){xe.current?xe.current=!1:0!==(L||[]).length?qe((function(e){if(0===(e||[]).length)return e;var n=e.filter((function(e){return L.some((function(n){return JSON.stringify(n)===JSON.stringify(e)}))}));return(n||[]).length!==(e||[]).length?n:e})):qe([])}),[L]),h((function(){ae&&!xe.current&&ae(Ye)}),[Ye]);var un=d((function(e){if($&&e.sortable&&"string"==typeof e.accessor){var n=e.accessor;He((function(e){if(e.column===n){var t="asc"===e.direction?"desc":"asc";return ie&&ie(n,t),{column:n,direction:t}}return ie&&ie(n,"asc"),{column:n,direction:"asc"}}))}}),[$,ie]),sn=d((function(e,i){Ie((function(r){var c=n(n({},r),{},t({},e,i.length>0?i:null));return re&&re(c),c}))}),[re]),dn=d((function(e,n,t){qe((function(r){return n?[].concat(i(r),[e]):r.filter((function(n,i){return ln(n,i)!==ln(e,t)}))}))}),[ln]),hn=d((function(e){qe(e?i(L):[])}),[L]),mn=d((function(e,n){return Ye.some((function(t,i){return ln(t,i)===ln(e,n)}))}),[Ye,ln]),bn=d((function(e,n){n.stopPropagation(),Ze((function(n){return n.includes(e)?n.filter((function(n){return n!==e})):[].concat(i(n),[e])}))}),[]),fn=d((function(e,n){e.preventDefault(),an({visible:!0,x:e.clientX,y:e.clientY,row:n})}),[]),pn=d(r(c().mark((function e(){return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!be){e.next=13;break}return tn(!0),e.prev=2,e.next=5,be();case 5:e.next=10;break;case 7:e.prev=7,e.t0=e.catch(2),console.error("Error refreshing data:",e.t0);case 10:return e.prev=10,tn(!1),e.finish(10);case 13:case"end":return e.stop()}}),e,null,[[2,7,10,13]])}))),[be]),vn=d((function(e){if(de){var n=de.fileName||"table-export";if("csv"===e){var t=[].concat(i(pe?["#"]:[]),i(O.filter((function(e){return"string"==typeof e.accessor})).map((function(e){return e.header})))),r=L.map((function(e,n){return[].concat(i(pe?[String(n+ge)]:[]),i(O.filter((function(e){return"string"==typeof e.accessor})).map((function(n){var t,i=n.accessor;return String(null!==(t=e[i])&&void 0!==t?t:"")})))).join(",")})),c=[t.join(",")].concat(i(r)).join("\n"),o=new Blob([c],{type:"text/csv;charset=utf-8;"}),a=document.createElement("a"),l=URL.createObjectURL(o);a.setAttribute("href",l),a.setAttribute("download","".concat(n,".csv")),a.style.visibility="hidden",document.body.appendChild(a),a.click(),document.body.removeChild(a)}}}),[O,L,de]),gn=m((function(){var n=L;return ke.trim()&&(n=n.filter((function(e){return O.some((function(n){if("string"==typeof n.accessor){var t=e[n.accessor];return String(t).toLowerCase().includes(ke.toLowerCase())}return!1}))}))),Object.entries(Be).forEach((function(t){var i=e(t,2),r=i[0],c=i[1];null!==c&&(n=n.filter((function(e){return String(e[r]||"").toLowerCase().includes(String(c).toLowerCase())})))})),n}),[L,ke,O,Be]),Nn=m((function(){return De.column?i(gn).sort((function(e,n){var t=De.column,i=e[t],r=n[t];if(i===r)return 0;var c=i<r?-1:1;return"asc"===De.direction?c:-c})):gn}),[gn,De.column,De.direction]),xn=m((function(){if(!V)return Nn;var e=(Le-1)*Ae;return Nn.slice(e,e+Ae)}),[Nn,V,Le,Ae]),yn=m((function(){return V?Math.ceil(Nn.length/Ae):1}),[Nn.length,Ae,V]);return h((function(){Ee(1)}),[ke,Ae,Be]),P||nn?a("div",{className:"ihub-data-list-container",children:[j&&o("h2",{children:j}),o("div",{className:"ihub-loading-state",children:o("p",{children:"Loading data..."})})]}):P||L&&0!==L.length?a("div",{className:"ihub-data-list-container",ref:Ne,children:[(j||_||H||de||me)&&a("div",{className:"ihub-data-list-header ihub-table-header ihub-p-0",children:[o("div",{children:j&&o("h2",{children:j})}),a("div",{className:"ihub-table-controls",children:[H&&o("div",{className:"ihub-table-search",children:o("input",{type:"text",placeholder:"Search...",value:ke,onChange:function(e){return we(e.target.value)},className:"ihub-search-input"})}),de&&a("div",{className:"ihub-export-buttons",children:[de.csv&&a("button",{className:"ihub-export-button ihub-export-csv",onClick:function(){return vn("csv")},children:[o(b,{}),"CSV"]}),de.excel&&a("button",{className:"ihub-export-button ihub-export-excel",onClick:function(){return vn("excel")},children:[o(b,{}),"Excel"]}),de.pdf&&a("button",{className:"ihub-export-button ihub-export-pdf",onClick:function(){return vn("pdf")},children:[o(b,{}),"PDF"]})]}),me&&be&&a("button",{className:"ihub-export-button",onClick:pn,disabled:nn,children:[o(f,{}),"Refresh"]}),_&&o("div",{className:"ihub-data-controls ihub-mb-0",children:_})]})]}),oe&&Ye.length>0&&a("div",{className:"ihub-selection-summary",children:[a("p",{children:[Ye.length," item(s) selected"]}),o("button",{className:"ihub-outlined-btn",onClick:function(){return qe([])},children:"Clear Selection"})]}),o("div",{className:"ihub-scroll-container ".concat(K?"ihub-sticky-header":""),style:Q?{maxHeight:Q}:void 0,children:a("table",{className:"ihub-table ihub-scroll-container",children:[o("thead",{className:q?"ihub-hide-on-mobile":"",children:a("tr",{children:[pe&&o("th",{style:{width:"60px",textAlign:"center"},children:"#"}),oe&&o("th",{className:"ihub-checkbox-cell",children:o("div",{className:"ihub-checkbox-header",children:o("input",{type:"checkbox",checked:Ye.length===L.length&&L.length>0,onChange:function(e){return hn(e.target.checked)}})})}),ue&&se&&o("th",{style:{width:"40px"},children:o(w,{})}),O.map((function(e,n){return o("th",{className:"".concat(e.sortable&&$?"ihub-sortable-column":""," ").concat(De.column===e.accessor?"ihub-sorted-".concat(De.direction):""),style:e.width?{width:e.width}:void 0,children:a("div",{className:"ihub-column-header",children:[o("span",{onClick:function(){return e.sortable&&$?un(e):void 0},style:{cursor:e.sortable&&$?"pointer":"default"},children:e.header}),e.sortable&&$&&o("span",{className:"ihub-sort-icon",onClick:function(){return un(e)},children:De.column===e.accessor&&"asc"===De.direction?"▲":De.column===e.accessor&&"desc"===De.direction?"▼":"⇅"}),e.filterable&&"string"==typeof e.accessor&&a("div",{className:"ihub-column-filter",children:[o("button",{className:"ihub-filter-button",onClick:function(n){n.stopPropagation(),Ge(_e===e.accessor?null:e.accessor)},children:Be[e.accessor]?o(g,{}):o(v,{})}),_e===e.accessor&&a("div",{className:"ihub-filter-dropdown",onClick:function(e){return e.stopPropagation()},children:[a("label",{children:["Filter ",e.header]}),o("input",{type:"text",className:"ihub-filter-input",value:Be[e.accessor]||"",onChange:function(n){return sn(e.accessor,n.target.value)},placeholder:"Filter by ".concat(e.header.toLowerCase()),autoFocus:!0}),a("div",{className:"ihub-filter-actions",children:[o("button",{className:"ihub-outlined-btn",onClick:function(){sn(e.accessor,""),Ge(null)},children:"Clear"}),o("button",{className:"ihub-important-btn",onClick:function(){return Ge(null)},children:"Apply"})]})]})]})]})},n)}))]})}),o("tbody",{children:xn.map((function(e,n){var t=ln(e,n),i=Qe.includes(t);return a(l.Fragment,{children:[a("tr",{onClick:function(){return G&&G(e)},onContextMenu:function(n){return fn(n,e)},className:"\n ".concat(G?"ihub-clickable-row":"","\n ").concat(mn(e,n)?"ihub-selected-row":"","\n "),children:[pe&&o("td",{style:{textAlign:"center",fontWeight:"500"},children:(Le-1)*Ae+n+ge}),oe&&o("td",{className:"ihub-checkbox-cell",onClick:function(e){return e.stopPropagation()},children:o("input",{type:"checkbox",checked:mn(e,n),onChange:function(t){return dn(e,t.target.checked,n)}})}),ue&&se&&o("td",{onClick:function(e){return bn(t,e)},children:o(i?x:N,{})}),O.map((function(n,t){var i,r,c;return o("td",{"data-label":q?n.header:void 0,children:n.tooltip&&"string"==typeof n.accessor?o("div",{className:"ihub-cell-tooltip","data-tooltip":String(null!==(i=e[n.accessor])&&void 0!==i?i:""),children:n.cell?n.cell(e):String(null!==(r=e[n.accessor])&&void 0!==r?r:"")}):n.cell?n.cell(e):"function"==typeof n.accessor?n.accessor(e):String(null!==(c=e[n.accessor])&&void 0!==c?c:"")},t)}))]}),ue&&se&&i&&o("tr",{className:"ihub-expanded-row",children:o("td",{colSpan:O.length+(oe?1:0)+1+(pe?1:0),children:o("div",{className:"ihub-row-details",children:se(e)})})})]},t)}))})]})}),on.visible&&on.row&&a("div",{className:"ihub-context-menu",style:{top:on.y,left:on.x},children:[a("div",{className:"ihub-context-menu-item",onClick:function(){on.row&&G&&G(on.row),an((function(e){return n(n({},e),{},{visible:!1})}))},children:[o(y,{}),"View"]}),a("div",{className:"ihub-context-menu-item",onClick:function(){an((function(e){return n(n({},e),{},{visible:!1})}))},children:[o(C,{}),"Edit"]}),o("div",{className:"ihub-context-menu-separator"}),a("div",{className:"ihub-context-menu-item",onClick:function(){an((function(e){return n(n({},e),{},{visible:!1})}))},children:[o(k,{}),"Delete"]})]}),V&&yn>1&&a("div",{className:"ihub-table-pagination",children:[a("div",{className:"ihub-pagination-info",children:["Showing"," ",Math.min((Le-1)*Ae+1,Nn.length)," ","to ",Math.min(Le*Ae,Nn.length)," of"," ",Nn.length," entries"]}),a("div",{className:"ihub-pagination-controls",children:[o("button",{className:"ihub-pagination-button",disabled:1===Le,onClick:function(){return Ee(1)},children:"«"}),o("button",{className:"ihub-pagination-button",disabled:1===Le,onClick:function(){return Ee((function(e){return Math.max(1,e-1)}))},children:"‹"}),Array.from({length:Math.min(5,yn)},(function(e,n){var t;return o("button",{className:"ihub-pagination-button ".concat(Le===(t=yn<=5||Le<=3?n+1:Le>=yn-2?yn-4+n:Le-2+n)?"ihub-active":""),onClick:function(){return Ee(Number(t))},children:t},t)})),o("button",{className:"ihub-pagination-button",disabled:Le===yn,onClick:function(){return Ee((function(e){return Math.min(yn,e+1)}))},children:"›"}),o("button",{className:"ihub-pagination-button",disabled:Le===yn,onClick:function(){return Ee(yn)},children:"»"})]}),a("div",{className:"ihub-rows-per-page",children:[o("span",{children:"Rows per page:"}),o("select",{value:Ae,onChange:function(e){return Fe(Number(e.target.value))},className:"ihub-rows-select",children:I.map((function(e){return o("option",{value:e,children:e},e)}))})]})]})]}):a("div",{className:"ihub-data-list-container",children:[j&&o("h2",{children:j}),_&&o("div",{className:"ihub-data-controls ihub-mb-0",children:_}),o("div",{className:"ihub-empty-state",children:a("div",{children:[M,o("p",{children:A})]})})]})};export{S as IHubTable,S as default};
|
|
2
2
|
//# sourceMappingURL=IHubTable.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 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};
|
|
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 l,useRef as s,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 g from"@mui/icons-material/ExpandMoreOutlined";import v 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 w=l((function(l,w){var k,C,S=l.token,E=l.columns,j=l.defaultData,R=l.endpointPath,O=l.initialParams,M=void 0===O?{}:O,A=l.searchParams,F=l.dataAdapter,H=l.title,L=l.emptyStateMessage,D=void 0===L?"No data available":L,I=l.emptyStateIcon,T=void 0===I?i(f,{}):I,U=l.actions,_=l.showSearch,B=void 0===_||_,G=l.searchPlaceholder,J=void 0===G?"Search...":G,V=l.searchDebounceMs,W=void 0===V?1e3:V,q=l.enableSorting,z=void 0===q||q,K=l.enableExport,Q=void 0!==K&&K,X=l.exportOptions,Y=void 0===X?{csv:!0}:X,Z=l.rowsPerPageOptions,$=void 0===Z?[10,25,50,100]:Z,ee=l.defaultRowsPerPage,te=void 0===ee?10:ee,ne=l.onRowClick,re=l.onFetchError,ae=l.expandable,ie=void 0!==ae&&ae,oe=l.renderExpandedRow,ce=l.keyExtractor,le=void 0===ce?function(e){return JSON.stringify(e)}:ce,se=l.stickyHeader,ue=void 0!==se&&se,de=l.maxHeight,he=l.hideHeaderOnMobile,pe=void 0!==he&&he,be=l.showRowNumbers,me=void 0!==be&&be,fe=l.rowNumberStartFrom,ge=void 0===fe?1:fe,ve=s(!0),Ne=s(null),xe=u(j||[]),Pe=e(xe,2),ye=Pe[0],we=Pe[1],ke=u(!0),Ce=e(ke,2),Se=Ce[0],Ee=Ce[1],je=u(null),Re=e(je,2),Oe=Re[0],Me=Re[1],Ae=u({totalCount:0,currentPage:1,perPage:te,totalPages:0}),Fe=e(Ae,2),He=Fe[0],Le=Fe[1],De=u(t({page:1,limit:te},M)),Ie=e(De,2),Te=Ie[0],Ue=Ie[1],_e=u([]),Be=e(_e,2),Ge=Be[0],Je=Be[1],Ve=u(M.search||""),We=e(Ve,2),qe=We[0],ze=We[1],Ke=d(y.exports.debounce((function(e){Ue((function(n){return t(t({},n),{},{search:e,page:1})}))}),W),[]),Qe={data:j||[],pagination:{totalCount:null===(k=j||[])||void 0===k?void 0:k.length,currentPage:"",perPage:10,totalPages:Math.ceil(((null===(C=j||[])||void 0===C?void 0:C.length)||10)/10)},links:{next:"",previous:""}},Xe=d(function(){var t=r(a().mark((function t(n){var r,i,o,c,l,s;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(Ee(!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=x("GET",null,S),c="".concat(P).concat(R,"?").concat(r.toString()),t.next=12,fetch(c,o);case 12:return l=t.sent,t.next=15,l.json();case 15:return s=t.sent,t.abrupt("return",{data:s.results,pagination:{totalCount:s.count,currentPage:Math.floor(parseInt(new URLSearchParams(s.next).get("offset")||"0")/n.limit),perPage:n.limit,totalPages:Math.ceil(s.count/n.limit)},links:{next:s.next,previous:s.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,Ee(!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]),Ye=d((function(e){var t=e.target.value;ze(t),Ke(t)}),[Ke]),Ze=d((function(e){Ue((function(n){return t(t({},n),{},{page:e})}))}),[]),$e=d((function(e){Ue((function(n){return t(t({},n),{},{page:1,limit:e})}))}),[]),et=d((function(e){if(z&&e.sortable&&"string"==typeof e.accessor){var n=e.accessor;Ue((function(e){return e.sort===n?t(t({},e),{},{direction:"asc"===e.direction?"desc":"asc"}):t(t({},e),{},{sort:n,direction:"asc"})}))}}),[z]),tt=d((function(){Ue((function(e){return t({},e)}))}),[]);h(w,(function(){return{refresh:tt}}),[tt]);var nt=d(function(){var e=r(a().mark((function e(r){var i,o,c,l,s,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,Ee(!0),i=t(t({},Te),{},{page:1,limit:1e3,export:r}),e.next=7,Xe(i);case 7:(o=e.sent)&&(c=F?F(o).data:o.data,l=Y.fileName||"table-export","csv"===r&&(s=[].concat(n(me?["#"]:[]),n(E.filter((function(e){return"string"==typeof e.accessor})).map((function(e){return e.header})))),u=c.map((function(e,t){return[].concat(n(me?[String(t+ge)]:[]),n(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=[s.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(l,".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,Ee(!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,Te,Q,Y,F,re]),rt=d((function(e,t){t.stopPropagation(),Je((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,Ee(!0),t.next=4,Xe(Te);case 4:n=t.sent,e&&(F?(r=F(n),we(r.data),r.pagination&&Le(r.pagination)):n&&(we(n.data),n.pagination&&Le(n.pagination)),Me(null)),t.next=12;break;case 8:t.prev=8,t.t0=t.catch(0),console.error("Error fetching data:",t.t0),e&&(Me(t.t0),re&&re(t.t0));case 12:return t.prev=12,e&&(Ee(!1),ve.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}}),[Te,F,re]),p((function(){A&&!ve.current&&Ue((function(e){return t({},e)}))}),[A]),Se&&ve.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..."})})]}):Oe&&!Se&&0===(ye||[]).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:tt,children:"Retry"})]})]}):o("div",{className:"ihub-data-list-container",ref:Ne,children:[(H||U||B||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:[B&&i("div",{className:"ihub-table-search",children:o("div",{className:"ihub-search-input-wrapper",children:[i("input",{type:"text",placeholder:J,value:qe,onChange:Ye,className:"ihub-search-input"}),Se&&i("div",{className:"ihub-search-loading-indicator",children:i("span",{className:"ihub-loading-dot"})})]})}),Q&&o("div",{className:"ihub-export-buttons",children:[Y.csv&&o("button",{className:"ihub-export-button ihub-export-csv",onClick:function(){return nt("csv")},disabled:Se,children:[i(b,{}),"CSV"]}),Y.excel&&o("button",{className:"ihub-export-button ihub-export-excel",onClick:function(){return nt("excel")},disabled:Se,children:[i(b,{}),"Excel"]}),Y.pdf&&o("button",{className:"ihub-export-button ihub-export-pdf",onClick:function(){return nt("pdf")},disabled:Se,children:[i(b,{}),"PDF"]})]}),o("button",{className:"ihub-refresh-button",onClick:tt,disabled:Se,children:[i(m,{}),"Refresh"]}),U&&i("div",{className:"ihub-data-controls ihub-mb-0",children:U})]})]}),Se&&!ve.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:[me&&i("th",{style:{width:"60px",textAlign:"center"},children:"#"}),ie&&oe&&i("th",{style:{width:"40px"}}),E.map((function(e,t){return i("th",{className:"".concat(e.sortable&&z?"ihub-sortable-column":""," ").concat(Te.sort===e.accessor?"ihub-sorted-".concat(Te.direction):""),style:e.width?{width:e.width}:void 0,onClick:function(){return e.sortable&&z?et(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:Te.sort===e.accessor&&"asc"===Te.direction?"▲":Te.sort===e.accessor&&"desc"===Te.direction?"▼":"⇅"})]})},t)}))]})}),Se||0!==(ye||[]).length?i("tbody",{children:ye.map((function(e,t){var n=le(e),r=Ge.includes(n);return o(c.Fragment,{children:[o("tr",{onClick:function(){return ne&&ne(e)},className:ne?"ihub-clickable-row":"",children:[me&&i("td",{style:{textAlign:"center",fontWeight:"500"},children:(He.currentPage-1)*He.perPage+t+ge}),ie&&oe&&i("td",{onClick:function(e){return rt(n,e)},children:i(r?v:g,{})}),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+(me?1:0),children:i("div",{className:"ihub-row-details",children:oe(e)})})})]},n)}))}):""]}),Se||0!==(ye||[]).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})]})})]})]}),He&&He.totalPages>1&&o("div",{className:"ihub-table-pagination",children:[o("div",{className:"ihub-pagination-info",children:["Showing ",(He.currentPage-1)*He.perPage+1," to"," ",Math.min(He.currentPage*He.perPage,He.totalCount)," ","of ",He.totalCount," entries"]}),o("div",{className:"ihub-pagination-controls",children:[i("button",{className:"ihub-pagination-button",disabled:1===He.currentPage||Se,onClick:function(){return Ze(1)},children:"«"}),i("button",{className:"ihub-pagination-button",disabled:1===He.currentPage||Se,onClick:function(){return Ze(He.currentPage-1)},children:"‹"}),Array.from({length:Math.min(5,He.totalPages)},(function(e,t){var n;return n=He.totalPages<=5||He.currentPage<=3?t+1:He.currentPage>=He.totalPages-2?He.totalPages-4+t:He.currentPage-2+t,i("button",{className:"ihub-pagination-button ".concat(He.currentPage===n?"ihub-active":""),onClick:function(){return Ze(Number(n))},disabled:Se,children:n},n)})),i("button",{className:"ihub-pagination-button",disabled:He.currentPage===He.totalPages||Se,onClick:function(){return Ze(He.currentPage+1)},children:"›"}),i("button",{className:"ihub-pagination-button",disabled:He.currentPage===He.totalPages||Se,onClick:function(){return Ze(He.totalPages)},children:"»"})]}),o("div",{className:"ihub-rows-per-page",children:[i("span",{children:"Rows per page:"}),i("select",{value:He.perPage,onChange:function(e){return $e(Number(e.target.value))},className:"ihub-rows-select",disabled:Se,children:$.map((function(e){return i("option",{value:e,children:e},e)}))})]})]})]})}));w.displayName="IHubTableServer";export{w as IHubTableServer,w 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;
|
|
@@ -41,6 +41,8 @@ export interface TableProps<T> {
|
|
|
41
41
|
};
|
|
42
42
|
refreshable?: boolean;
|
|
43
43
|
onRefresh?: () => Promise<void>;
|
|
44
|
+
showRowNumbers?: boolean;
|
|
45
|
+
rowNumberStartFrom?: number;
|
|
44
46
|
}
|
|
45
47
|
/**
|
|
46
48
|
* Enhanced reusable table component for InstinctHub applications
|
|
@@ -76,6 +78,8 @@ export interface TableProps<T> {
|
|
|
76
78
|
* exportOptions={exportOptions}
|
|
77
79
|
* refreshable={refreshable}
|
|
78
80
|
* onRefresh={onRefresh}
|
|
81
|
+
* showRowNumbers={true}
|
|
82
|
+
* rowNumberStartFrom={1}
|
|
79
83
|
* />
|
|
80
84
|
* ```
|
|
81
85
|
* @prop {TableColumnType<T>[]} columns - The columns to display in the table
|
|
@@ -106,8 +110,10 @@ export interface TableProps<T> {
|
|
|
106
110
|
* @prop {object} exportOptions - The options for exporting the table
|
|
107
111
|
* @prop {boolean} refreshable - Whether to allow refreshing the table
|
|
108
112
|
* @prop {function} onRefresh - The function to call when the table is refreshed
|
|
113
|
+
* @prop {boolean} showRowNumbers - Whether to show row numbers for each record
|
|
114
|
+
* @prop {number} rowNumberStartFrom - The starting number for row numbering (defaults to 1)
|
|
109
115
|
*
|
|
110
116
|
* @link https://github.com/instincthub/instincthub-react-ui/blob/main/src/__examples__/src/components/ui/TableExamples.tsx
|
|
111
117
|
*/
|
|
112
|
-
export declare const IHubTable: <T extends object>({ columns, data, isLoading, emptyStateMessage, emptyStateIcon, title, showSearch, pagination, rowsPerPageOptions, defaultRowsPerPage, actions, onRowClick, keyExtractor, hideHeaderOnMobile, stickyHeader, maxHeight, sortable, defaultSortColumn, defaultSortDirection, onSort, onFilter, selectable, onSelectionChange, expandable, renderExpandedRow, exportOptions, refreshable, onRefresh, }: TableProps<T>) => JSX.Element;
|
|
118
|
+
export declare const IHubTable: <T extends object>({ columns, data, isLoading, emptyStateMessage, emptyStateIcon, title, showSearch, pagination, rowsPerPageOptions, defaultRowsPerPage, actions, onRowClick, keyExtractor, hideHeaderOnMobile, stickyHeader, maxHeight, sortable, defaultSortColumn, defaultSortDirection, onSort, onFilter, selectable, onSelectionChange, expandable, renderExpandedRow, exportOptions, refreshable, onRefresh, showRowNumbers, rowNumberStartFrom, }: TableProps<T>) => JSX.Element;
|
|
113
119
|
export default IHubTable;
|
|
@@ -39,6 +39,8 @@ interface IHubTableServerPropsType<T> {
|
|
|
39
39
|
stickyHeader?: boolean;
|
|
40
40
|
maxHeight?: string;
|
|
41
41
|
hideHeaderOnMobile?: boolean;
|
|
42
|
+
showRowNumbers?: boolean;
|
|
43
|
+
rowNumberStartFrom?: number;
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
46
|
* Server-side table component for InstinctHub applications
|
|
@@ -62,6 +64,8 @@ interface IHubTableServerPropsType<T> {
|
|
|
62
64
|
* stickyHeader={true}
|
|
63
65
|
* maxHeight="600px"
|
|
64
66
|
* hideHeaderOnMobile={true}
|
|
67
|
+
* showRowNumbers={true}
|
|
68
|
+
* rowNumberStartFrom={1}
|
|
65
69
|
* token={process.env.NEXT_PUBLIC_TOKEN}
|
|
66
70
|
* dataAdapter={dataAdapter}
|
|
67
71
|
* rowsPerPageOptions={[10, 25, 50, 100]}
|
|
@@ -104,6 +108,8 @@ interface IHubTableServerPropsType<T> {
|
|
|
104
108
|
* @prop {boolean} stickyHeader - Whether to enable sticky header
|
|
105
109
|
* @prop {string} maxHeight - The maximum height of the table
|
|
106
110
|
* @prop {boolean} hideHeaderOnMobile - Whether to hide the header on mobile
|
|
111
|
+
* @prop {boolean} showRowNumbers - Whether to show row numbers for each record
|
|
112
|
+
* @prop {number} rowNumberStartFrom - The starting number for row numbering (defaults to 1)
|
|
107
113
|
*
|
|
108
114
|
* @link https://github.com/instincthub/instincthub-react-ui/blob/main/src/__examples__/src/components/ui/TableServerExamples.tsx
|
|
109
115
|
*/
|
|
@@ -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;
|