add: page /dosen, /dosen/{id}
Browse filesFiles changed (14)
- resources/css/app.css+959-22
- resources/js/components/auth/register-role-form.tsx+200-7
- resources/js/components/dosen/dosen-shell.tsxAdded+200
- resources/js/components/student/question-composer.tsx+27-13
- resources/js/components/student/student-shell.tsx+276-160
- resources/js/lib/rag.ts+148
- resources/js/pages/auth/login.tsx+14-4
- resources/js/pages/dosen-detail.tsxAdded+618
- resources/js/pages/dosen.tsxAdded+541
- resources/js/pages/dosen/pengaturan.tsxAdded+22
- resources/js/pages/mahasiswa-chat.tsx+152-19
- resources/js/pages/mahasiswa.tsx+29-12
- routes/web.php+8
- tests/Feature/DosenDashboardTest.phpAdded+23
108 unmodified lines10911011111211311446 unmodified lines16116216316416516644 unmodified lines21121221321421521642 unmodified lines2592602612622632644 unmodified lines2692702712722732747 unmodified lines2822832842852862872886 unmodified lines29529629729829930030143 unmodified lines34534634734834935035113 unmodified lines36536636736836937037142 unmodified lines4144154164174184194203 unmodified lines4244254264274284294306 unmodified lines43743843944044144244318 unmodified lines46246346446546646730 unmodified lines49849950050150250350415 unmodified lines52052152252352452552621 unmodified lines54854955055155255355484 unmodified lines63964064164264364464510 unmodified lines6566576586596606615 unmodified lines66766866967067167267328 unmodified lines70270370470570670770857 unmodified lines76676776876977077177277377477577677777821 unmodified lines80080180280380480580611 unmodified lines81881982082182282382466 unmodified lines8918928938948958968978988999009019029039049059069076 unmodified lines91491591691791891992036 unmodified lines95795895996096196296341 unmodified lines1005100610071008100910106 unmodified lines10171018101910201021108 unmodified lines--app-primary-soft: #ccdcff;--app-primary-foreground: #ffffff;--app-danger: #ef4444;--app-placeholder: rgba(115, 115, 115, 0.42);--app-toggle-bg: rgba(255, 255, 255, 0.9);--app-shadow: 1px 1px 4.5px rgba(39, 100, 235, 0.36);46 unmodified lines--student-shadow: 0 24px 70px rgba(15, 23, 42, 0.08);--student-sidebar-shadow: 1px 0 0 rgba(15, 23, 42, 0.08);--student-composer-shadow: var(--app-composer-shadow);}.dark {44 unmodified lines--app-primary-soft: #c8d7ff;--app-primary-foreground: #ffffff;--app-danger: #ff4545;--app-placeholder: rgba(244, 244, 245, 0.42);--app-toggle-bg: #171717;--app-shadow: 0 0 20px rgba(52, 120, 255, 0.34);42 unmodified lines--student-shadow: 0 24px 70px rgba(0, 0, 0, 0.18);--student-sidebar-shadow: 1px 0 0 var(--app-border);--student-composer-shadow: var(--app-composer-shadow);}@layer base {4 unmodified linesbody {@apply bg-background text-foreground;}}@layer components {7 unmodified lines}.welcome-theme-toggle {@apply absolute top-4 right-4 h-10 w-10 rounded-[10px] shadow-none backdrop-blur sm:top-8 sm:right-8;background-color: var(--welcome-toggle-bg);border-color: var(--welcome-card-active-border);color: var(--welcome-accent);6 unmodified lines}.welcome-title {@apply text-center text-[34px] leading-tight font-bold tracking-[0.01em] sm:text-[40px];color: var(--welcome-title);}43 unmodified lines}.welcome-entry-title {@apply truncate text-left text-lg leading-tight font-semibold;color: var(--welcome-title);}13 unmodified lines}.welcome-register-link {@apply font-medium underline-offset-4 hover:underline focus-visible:ring-2 focus-visible:outline-none;color: var(--welcome-accent);--tw-ring-color: color-mix(in oklab,42 unmodified lines}.register-back-link {@apply inline-flex text-sm font-semibold underline-offset-4 transition-colors hover:underline focus-visible:ring-2 focus-visible:outline-none;color: var(--welcome-subtitle);--tw-ring-color: color-mix(in oklab,3 unmodified lines}.register-heading {@apply mt-2 text-center text-2xl leading-tight font-semibold;color: var(--welcome-title);}6 unmodified lines}.register-label {@apply text-base leading-none font-medium;color: var(--welcome-title);}18 unmodified lines);}.register-submit {@apply mt-1 h-[43px] w-full rounded-[6px] border text-base font-semibold shadow-none;background-color: var(--welcome-accent) !important;30 unmodified lines}.login-remember-label {@apply text-sm leading-none font-normal;color: var(--welcome-subtitle);}15 unmodified lines}.student-dashboard-shell {@apply min-h-svh;background-color: var(--student-bg);color: var(--student-text);}21 unmodified lines}.student-logo-action {@apply flex size-8 shrink-0 items-center justify-center rounded-[8px] transition-transform outline-none focus-visible:ring-2;--tw-ring-color: color-mix(in oklab,var(--student-primary) 45%,84 unmodified lines}.student-history-delete {@apply absolute top-1/2 right-2 flex size-6 -translate-y-1/2 items-center justify-center rounded-[6px] opacity-0 transition-opacity;color: var(--student-danger);}10 unmodified lines);}.student-history-menu-icon {@apply hidden;color: var(--student-text);5 unmodified lines}.student-history-title {@apply block truncate text-[11px] leading-tight font-medium;color: var(--student-text);}28 unmodified lines}.student-user-name {@apply block truncate text-[11px] leading-tight font-semibold;color: var(--student-text);}57 unmodified lines}.student-workspace {@apply flex min-w-0 flex-1 flex-col;background-color: var(--student-bg);color: var(--student-text);}.student-topbar {@apply flex h-[72px] shrink-0 items-center justify-between border-b px-5 sm:px-6;background-color: var(--student-surface);border-color: var(--student-border);}21 unmodified lines}.student-chat-stage {@apply flex flex-1 items-center justify-center px-4 py-10;}.student-empty-state {11 unmodified lines}.student-greeting h2 {@apply text-3xl leading-tight font-bold tracking-[-0.02em];color: var(--student-text);}66 unmodified lines}.student-floating-send {@apply absolute right-5 bottom-4 size-8 rounded-[8px] shadow-none;background-color: var(--student-primary) !important;color: var(--student-primary-foreground) !important;}.student-chat-stage--session {@apply flex-col items-stretch justify-between overflow-hidden px-5 py-0;}.student-chat-thread {@apply min-h-0 w-full flex-1 overflow-y-auto py-8;}.student-chat-messages {6 unmodified lines}.student-chat-status {@apply mt-0 mb-4;}.student-message {36 unmodified lines}.student-message-content {@apply leading-relaxed whitespace-pre-wrap;}.student-message-time {41 unmodified linescolor: var(--student-muted);}@media (max-width: 640px) {.student-chat-stage--session {@apply px-3;6 unmodified lines.student-chat-composer {@apply pb-4;}}}108 unmodified lines10911011111211311411546 unmodified lines16216316416516616716816917017117217317417517617717817918018118218344 unmodified lines22822923023123223323442 unmodified lines2772782792802812822832842852862872882892902912922932942952962972982993003013024 unmodified lines3073083093103113123133143153163173183193203213223237 unmodified lines3313323333343353363376 unmodified lines34434534634734834935043 unmodified lines39439539639739839940013 unmodified lines41441541641741841942042 unmodified lines4634644654664674684693 unmodified lines4734744754764774784796 unmodified lines48648748848949049149218 unmodified lines51151251351451551651751851952052152252352452552652752852953030 unmodified lines56156256356456556656715 unmodified lines58358458558658758858921 unmodified lines61161261361461561661784 unmodified lines70270370470570670770810 unmodified lines7197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887895 unmodified lines79579679779879980080128 unmodified lines83083183283383483583657 unmodified lines89489589689789889990090190290390490590621 unmodified lines92892993093193293393411 unmodified lines94694794894995095195266 unmodified lines101910201021102210231024102510261027102810291030103110321033103410356 unmodified lines104210431044104510461047104836 unmodified lines108510861087108810891090109141 unmodified lines11331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619076 unmodified lines191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958108 unmodified lines--app-primary-soft: #ccdcff;--app-primary-foreground: #ffffff;--app-danger: #ef4444;--app-success: #16a34a;--app-placeholder: rgba(115, 115, 115, 0.42);--app-toggle-bg: rgba(255, 255, 255, 0.9);--app-shadow: 1px 1px 4.5px rgba(39, 100, 235, 0.36);46 unmodified lines--student-shadow: 0 24px 70px rgba(15, 23, 42, 0.08);--student-sidebar-shadow: 1px 0 0 rgba(15, 23, 42, 0.08);--student-composer-shadow: var(--app-composer-shadow);--lecturer-bg: var(--app-bg);--lecturer-sidebar-bg: var(--app-sidebar-bg);--lecturer-surface: var(--app-surface);--lecturer-surface-soft: var(--app-surface-soft);--lecturer-border: var(--app-border);--lecturer-border-soft: var(--app-border-soft);--lecturer-border-strong: var(--app-border-strong);--lecturer-text: var(--app-text);--lecturer-muted: var(--app-muted);--lecturer-primary: var(--app-primary);--lecturer-primary-soft: var(--app-primary-soft);--lecturer-primary-foreground: var(--app-primary-foreground);--lecturer-danger: var(--app-danger);--lecturer-success: var(--app-success);--lecturer-shadow: 0 18px 42px rgba(15, 23, 42, 0.08);--lecturer-sidebar-shadow: 1px 0 0 rgba(15, 23, 42, 0.08);}.dark {44 unmodified lines--app-primary-soft: #c8d7ff;--app-primary-foreground: #ffffff;--app-danger: #ff4545;--app-success: #22c55e;--app-placeholder: rgba(244, 244, 245, 0.42);--app-toggle-bg: #171717;--app-shadow: 0 0 20px rgba(52, 120, 255, 0.34);42 unmodified lines--student-shadow: 0 24px 70px rgba(0, 0, 0, 0.18);--student-sidebar-shadow: 1px 0 0 var(--app-border);--student-composer-shadow: var(--app-composer-shadow);--lecturer-bg: var(--app-bg);--lecturer-sidebar-bg: var(--app-sidebar-bg);--lecturer-surface: var(--app-surface);--lecturer-surface-soft: var(--app-surface-soft);--lecturer-border: var(--app-border);--lecturer-border-soft: var(--app-border-soft);--lecturer-border-strong: var(--app-border-strong);--lecturer-text: var(--app-text);--lecturer-muted: var(--app-muted);--lecturer-primary: var(--app-primary);--lecturer-primary-soft: color-mix(in oklab,var(--app-primary) 22%,var(--app-surface));--lecturer-primary-foreground: var(--app-primary-foreground);--lecturer-danger: var(--app-danger);--lecturer-success: var(--app-success);--lecturer-shadow: 0 18px 42px rgba(0, 0, 0, 0.2);--lecturer-sidebar-shadow: 1px 0 0 var(--app-border);}@layer base {4 unmodified linesbody {@apply bg-background text-foreground;}button:not(:disabled),[role='button']:not([aria-disabled='true']),[data-slot='button']:not([aria-disabled='true']) {@apply cursor-pointer;}button:disabled,[aria-disabled='true'] {@apply cursor-not-allowed;}}@layer components {7 unmodified lines}.welcome-theme-toggle {@apply absolute right-4 top-4 h-10 w-10 rounded-[10px] shadow-none backdrop-blur sm:right-8 sm:top-8;background-color: var(--welcome-toggle-bg);border-color: var(--welcome-card-active-border);color: var(--welcome-accent);6 unmodified lines}.welcome-title {@apply text-center text-[34px] font-bold leading-tight tracking-[0.01em] sm:text-[40px];color: var(--welcome-title);}43 unmodified lines}.welcome-entry-title {@apply truncate text-left text-lg font-semibold leading-tight;color: var(--welcome-title);}13 unmodified lines}.welcome-register-link {@apply font-medium underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2;color: var(--welcome-accent);--tw-ring-color: color-mix(in oklab,42 unmodified lines}.register-back-link {@apply inline-flex text-sm font-semibold underline-offset-4 transition-colors hover:underline focus-visible:outline-none focus-visible:ring-2;color: var(--welcome-subtitle);--tw-ring-color: color-mix(in oklab,3 unmodified lines}.register-heading {@apply mt-2 text-center text-2xl font-semibold leading-tight;color: var(--welcome-title);}6 unmodified lines}.register-label {@apply text-base font-medium leading-none;color: var(--welcome-title);}18 unmodified lines);}.register-input[aria-invalid='true'] {border-color: var(--register-danger) !important;--tw-ring-color: color-mix(in oklab,var(--register-danger) 28%,transparent);}.register-error {@apply text-sm font-medium leading-snug;color: var(--register-danger);}.register-submit {@apply mt-1 h-[43px] w-full rounded-[6px] border text-base font-semibold shadow-none;background-color: var(--welcome-accent) !important;30 unmodified lines}.login-remember-label {@apply text-sm font-normal leading-none;color: var(--welcome-subtitle);}15 unmodified lines}.student-dashboard-shell {@apply h-svh min-h-svh overflow-hidden;background-color: var(--student-bg);color: var(--student-text);}21 unmodified lines}.student-logo-action {@apply flex size-8 shrink-0 items-center justify-center rounded-[8px] outline-none transition-transform focus-visible:ring-2;--tw-ring-color: color-mix(in oklab,var(--student-primary) 45%,84 unmodified lines}.student-history-delete {@apply absolute right-2 top-1/2 flex size-6 -translate-y-1/2 items-center justify-center rounded-[6px] opacity-0 transition-opacity;color: var(--student-danger);}10 unmodified lines);}.student-delete-dialog {@apply gap-5 rounded-[16px] border p-6 shadow-none sm:max-w-[440px];background-color: var(--student-surface);border-color: var(--student-border);box-shadow: var(--student-shadow);color: var(--student-text);}.student-delete-dialog-body {@apply flex flex-col gap-3;}.student-delete-copy {@apply text-sm leading-relaxed;color: var(--student-muted);}.student-delete-copy strong {color: var(--student-text);}.student-delete-error {@apply rounded-[10px] border px-4 py-3 text-sm font-medium;background-color: color-mix(in oklab,var(--student-danger) 8%,var(--student-surface));border-color: color-mix(in oklab,var(--student-danger) 24%,transparent);color: var(--student-danger);}.student-delete-dialog-footer {@apply gap-3 pt-1;}.student-delete-cancel {@apply h-10 rounded-[8px] px-5 text-sm font-semibold shadow-none;background-color: var(--student-surface) !important;border-color: var(--student-border) !important;color: var(--student-text) !important;}.student-delete-cancel:hover {background-color: var(--student-surface-soft) !important;}.student-delete-confirm {@apply h-10 rounded-[8px] px-5 text-sm font-semibold shadow-none;background-color: var(--student-danger) !important;color: var(--student-primary-foreground) !important;}.student-delete-confirm:hover {background-color: color-mix(in oklab,var(--student-danger) 86%,#000) !important;}.student-history-menu-icon {@apply hidden;color: var(--student-text);5 unmodified lines}.student-history-title {@apply block truncate text-[11px] font-medium leading-tight;color: var(--student-text);}28 unmodified lines}.student-user-name {@apply block truncate text-[11px] font-semibold leading-tight;color: var(--student-text);}57 unmodified lines}.student-workspace {@apply flex h-svh min-w-0 flex-1 flex-col overflow-hidden;background-color: var(--student-bg);color: var(--student-text);}.student-topbar {@apply sticky top-0 z-20 flex h-[72px] shrink-0 items-center justify-between border-b px-5 sm:px-6;background-color: var(--student-surface);border-color: var(--student-border);}21 unmodified lines}.student-chat-stage {@apply flex min-h-0 flex-1 items-center justify-center px-4 py-10;}.student-empty-state {11 unmodified lines}.student-greeting h2 {@apply text-3xl font-bold leading-tight tracking-[-0.02em];color: var(--student-text);}66 unmodified lines}.student-floating-send {@apply absolute bottom-4 right-5 size-8 rounded-[8px] shadow-none;background-color: var(--student-primary) !important;color: var(--student-primary-foreground) !important;}.student-chat-stage--session {@apply min-h-0 flex-col items-stretch justify-between overflow-hidden px-5 py-0;}.student-chat-thread {@apply min-h-0 w-full flex-1 overflow-y-auto overscroll-contain py-8;}.student-chat-messages {6 unmodified lines}.student-chat-status {@apply mb-4 mt-0;}.student-message {36 unmodified lines}.student-message-content {@apply whitespace-pre-wrap leading-relaxed;}.student-message-time {41 unmodified linescolor: var(--student-muted);}.lecturer-dashboard-shell {@apply min-h-svh;background-color: var(--lecturer-bg);color: var(--lecturer-text);}.lecturer-sidebar {border-color: var(--lecturer-border) !important;}.lecturer-sidebar [data-sidebar='sidebar'] {background-color: var(--lecturer-sidebar-bg);border-color: var(--lecturer-border);box-shadow: var(--lecturer-sidebar-shadow);}.lecturer-sidebar-header {@apply border-b;border-color: var(--lecturer-border);display: flex !important;height: 72px !important;flex-direction: row !important;align-items: center !important;justify-content: space-between !important;gap: 0 !important;padding: 0 20px !important;}.lecturer-brand {@apply flex min-w-0 items-center gap-3 rounded-[10px] text-left outline-none focus-visible:ring-2;color: var(--lecturer-text);flex: 1 1 auto;--tw-ring-color: color-mix(in oklab,var(--lecturer-primary) 45%,transparent);}.lecturer-brand-mark {@apply flex size-8 shrink-0 items-center justify-center rounded-[8px];background-color: var(--lecturer-primary);color: var(--lecturer-primary-foreground);}.lecturer-brand-copy {@apply truncate text-base font-bold;}.lecturer-sidebar-trigger {@apply rounded-[8px] shadow-none;color: var(--lecturer-text);width: 32px !important;height: 32px !important;}.lecturer-sidebar-trigger:hover {background-color: var(--lecturer-surface-soft);color: var(--lecturer-text);}.lecturer-sidebar-content {gap: 0 !important;}.lecturer-nav-group {padding: 16px 20px !important;}.lecturer-nav-list {gap: 8px !important;}.lecturer-nav-button {@apply justify-start gap-2 rounded-[8px] text-xs font-semibold shadow-none;color: var(--lecturer-muted);height: 34px !important;padding: 0 10px !important;}.lecturer-nav-button:hover,.lecturer-nav-button[data-active='true'] {background-color: var(--lecturer-primary-soft);color: var(--lecturer-primary);}.lecturer-sidebar-footer {@apply mt-auto border-t;border-color: var(--lecturer-border);padding: 16px 20px !important;}.lecturer-user-button {@apply mb-3 w-fit gap-2 rounded-[6px] shadow-none;background-color: var(--lecturer-surface-soft);color: var(--lecturer-text);height: auto !important;padding: 6px 8px !important;}.lecturer-user-button:hover {background-color: var(--lecturer-surface-soft);color: var(--lecturer-text);}.lecturer-user-avatar {@apply size-6 text-[8px];background-color: var(--lecturer-surface);color: var(--lecturer-text);}.lecturer-user-copy {@apply min-w-0;}.lecturer-user-name {@apply block truncate text-[11px] font-semibold leading-tight;color: var(--lecturer-text);}.lecturer-user-role {@apply block truncate text-[10px] leading-tight;color: var(--lecturer-muted);}.lecturer-logout-button {@apply justify-start gap-1 rounded-none text-[11px] font-normal shadow-none;color: var(--lecturer-danger);height: auto !important;padding: 0 !important;}.lecturer-logout-button:hover {background-color: transparent;color: var(--lecturer-danger);}.group[data-collapsible='icon'] .lecturer-sidebar-header {justify-content: center !important;padding: 0 !important;}.group[data-collapsible='icon'] .lecturer-brand-copy,.group[data-collapsible='icon'] .lecturer-nav-button span,.group[data-collapsible='icon'] .lecturer-user-copy,.group[data-collapsible='icon'] .lecturer-logout-button span {@apply hidden;}.group[data-collapsible='icon'] .lecturer-brand {flex: 0 0 auto;justify-content: center;}.group[data-collapsible='icon'] .lecturer-sidebar-trigger {display: none !important;}.group[data-collapsible='icon'] .lecturer-nav-group {padding: 20px 12px !important;}.group[data-collapsible='icon'] .lecturer-nav-button,.group[data-collapsible='icon'] .lecturer-user-button,.group[data-collapsible='icon'] .lecturer-logout-button {@apply mx-auto flex items-center justify-center rounded-[9px];width: 32px !important;height: 32px !important;padding: 0 !important;}.group[data-collapsible='icon'] .lecturer-sidebar-footer {@apply px-3;}.lecturer-workspace {@apply flex min-w-0 flex-1 flex-col;background-color: var(--lecturer-bg);color: var(--lecturer-text);}.lecturer-page {@apply w-full px-5 py-8 sm:px-8 lg:px-10;}.lecturer-page-header {@apply flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between;}.lecturer-page-header h1 {@apply text-3xl font-bold leading-tight tracking-[-0.03em];color: var(--lecturer-text);}.lecturer-page-header p {@apply mt-1 text-sm leading-relaxed;color: var(--lecturer-muted);}.lecturer-header-actions {@apply flex items-center gap-3;}.lecturer-theme-toggle {@apply static size-9 rounded-[9px] shadow-none sm:static;background-color: var(--lecturer-surface) !important;border-color: var(--lecturer-border-strong) !important;color: var(--lecturer-primary) !important;}.lecturer-create-button {@apply h-9 rounded-[8px] px-4 text-xs font-semibold shadow-none;background-color: var(--lecturer-primary) !important;color: var(--lecturer-primary-foreground) !important;}.lecturer-cancel-button {@apply h-10 rounded-[8px] px-5 text-sm font-semibold shadow-none;background-color: var(--lecturer-surface) !important;border-color: var(--lecturer-border) !important;color: var(--lecturer-text) !important;}.lecturer-cancel-button:hover {background-color: var(--lecturer-surface-soft) !important;}.lecturer-course-dialog {@apply gap-6 rounded-[16px] border p-6 shadow-none sm:max-w-[460px];background-color: var(--lecturer-surface);border-color: var(--lecturer-border-strong);box-shadow: var(--lecturer-shadow);color: var(--lecturer-text);}.lecturer-course-form {@apply flex flex-col gap-5;}.lecturer-form-field {@apply flex flex-col gap-2;}.lecturer-form-label {color: var(--lecturer-text);}.lecturer-form-input,.lecturer-form-textarea {@apply w-full rounded-[8px] border px-4 text-sm shadow-none outline-none transition-[border-color,box-shadow];background-color: color-mix(in oklab,var(--lecturer-primary) 6%,var(--lecturer-surface));border-color: var(--lecturer-border);color: var(--lecturer-text);}.lecturer-form-input {@apply h-11;}.lecturer-form-textarea {@apply min-h-28 resize-none py-3;}.lecturer-form-input::placeholder,.lecturer-form-textarea::placeholder {color: var(--app-placeholder);}.lecturer-form-input:focus,.lecturer-form-textarea:focus {border-color: var(--lecturer-primary);box-shadow: 0 0 0 3pxcolor-mix(in oklab, var(--lecturer-primary) 18%, transparent);}.lecturer-course-form .lecturer-status {@apply mx-0 mt-0;}.lecturer-course-footer {@apply gap-3 pt-1;}.lecturer-metric-grid {@apply mt-8 grid grid-cols-1 gap-5 md:grid-cols-3;}.lecturer-metric-card {@apply gap-0 rounded-[14px] border py-0 shadow-none;background-color: var(--lecturer-surface);border-color: var(--lecturer-border-soft);box-shadow: var(--lecturer-shadow);}.lecturer-metric-content {@apply flex items-center gap-5 px-6 py-6;}.lecturer-metric-icon {@apply flex size-12 shrink-0 items-center justify-center rounded-[12px];background-color: var(--lecturer-primary-soft);color: var(--lecturer-primary);}.lecturer-metric-icon[data-tone='danger'] {background-color: color-mix(in oklab,var(--lecturer-danger) 12%,var(--lecturer-surface));color: var(--lecturer-danger);}.lecturer-metric-copy p {@apply text-sm;color: var(--lecturer-muted);}.lecturer-metric-value-row {@apply mt-1 flex items-end gap-2;}.lecturer-metric-value-row strong {@apply text-3xl font-bold leading-none;color: var(--lecturer-text);}.lecturer-metric-icon[data-tone='danger']+ .lecturer-metric-copy.lecturer-metric-value-rowstrong {color: var(--lecturer-danger);}.lecturer-metric-value-row span {@apply pb-1 text-xs;color: var(--lecturer-muted);}.lecturer-table-card {@apply mt-8 gap-0 overflow-hidden rounded-[14px] border py-0 shadow-none;background-color: var(--lecturer-surface);border-color: var(--lecturer-border);box-shadow: var(--lecturer-shadow);}.lecturer-table-content {@apply px-0;}.lecturer-table-heading {@apply flex flex-col gap-4 border-b px-6 py-5 sm:flex-row sm:items-center sm:justify-between;border-color: var(--lecturer-border);}.lecturer-table-heading h2 {@apply text-base font-semibold;color: var(--lecturer-text);}.lecturer-search-field {@apply relative w-full sm:max-w-[320px];}.lecturer-search-field svg {@apply pointer-events-none absolute left-3 top-1/2 -translate-y-1/2;color: var(--lecturer-muted);z-index: 1;}.lecturer-search-input {@apply h-10 rounded-[9px] border text-sm shadow-none outline-none transition-[border-color,box-shadow];background-color: color-mix(in oklab,var(--lecturer-primary) 5%,var(--lecturer-surface));border-color: var(--lecturer-border);color: var(--lecturer-text);padding-right: 0.75rem !important;padding-left: 2.5rem !important;}.lecturer-search-input::placeholder {color: var(--app-placeholder);}.lecturer-search-input:focus {border-color: var(--lecturer-primary);box-shadow: 0 0 0 3pxcolor-mix(in oklab, var(--lecturer-primary) 16%, transparent);}.lecturer-status {@apply mx-6 mt-4 rounded-[10px] border px-4 py-3 text-sm font-medium;background-color: color-mix(in oklab,var(--lecturer-danger) 8%,var(--lecturer-surface));border-color: color-mix(in oklab,var(--lecturer-danger) 24%,transparent);color: var(--lecturer-danger);}.lecturer-table-wrap {@apply w-full overflow-x-auto;}.lecturer-table {@apply w-full min-w-[620px] border-collapse text-left;}.lecturer-table th {@apply px-6 py-4 text-xs font-semibold;color: var(--lecturer-muted);}.lecturer-table td {@apply border-t px-6 py-4 text-sm;border-color: var(--lecturer-border);color: var(--lecturer-muted);}.lecturer-table tbody tr:hover {background-color: color-mix(in oklab,var(--lecturer-primary) 5%,transparent);}.lecturer-kb-name {@apply block max-w-[260px] font-semibold;color: var(--lecturer-text);}.lecturer-doc-pill {@apply inline-flex items-center gap-1.5 rounded-[7px] px-2.5 py-1 text-xs font-semibold;background-color: var(--lecturer-surface-soft);color: var(--lecturer-text);}.lecturer-doc-pill svg {color: var(--lecturer-primary);}.lecturer-doc-error {@apply size-1.5 rounded-full;background-color: var(--lecturer-danger);}.lecturer-table-empty {@apply py-10 text-center text-sm;color: var(--lecturer-muted) !important;}.lecturer-manage-button {@apply inline-flex items-center justify-center gap-1 rounded-[7px] px-3 py-1.5 text-sm font-semibold outline-none transition-colors focus-visible:ring-2;background-color: color-mix(in oklab,var(--lecturer-primary) 10%,var(--lecturer-surface));color: var(--lecturer-primary);--tw-ring-color: color-mix(in oklab,var(--lecturer-primary) 45%,transparent);}.lecturer-manage-button:hover {background-color: color-mix(in oklab,var(--lecturer-primary) 16%,var(--lecturer-surface));}.lecturer-detail-page {@apply min-h-svh w-full;background-color: var(--lecturer-bg);color: var(--lecturer-text);}.lecturer-detail-header {@apply flex flex-col gap-5 px-5 py-8 sm:flex-row sm:items-start sm:px-8 lg:px-10;background-color: var(--lecturer-surface-soft);border-bottom: 1px solid var(--lecturer-border-soft);}.lecturer-detail-back {@apply mt-1 inline-flex size-9 shrink-0 items-center justify-center rounded-full outline-none transition-colors focus-visible:ring-2;color: var(--lecturer-muted);--tw-ring-color: color-mix(in oklab,var(--lecturer-primary) 45%,transparent);}.lecturer-detail-back:hover {background-color: var(--lecturer-surface);color: var(--lecturer-text);}.lecturer-detail-heading {@apply min-w-0 flex-1;}.lecturer-detail-title-row {@apply flex flex-wrap items-center gap-4;}.lecturer-detail-title-row h1 {@apply text-3xl font-bold leading-tight tracking-[-0.03em];color: var(--lecturer-text);}.lecturer-detail-heading p {@apply mt-1 text-base italic leading-relaxed;color: var(--lecturer-muted);}.lecturer-detail-actions {@apply flex items-center gap-3 sm:ml-auto;}.lecturer-edit-button {@apply h-12 rounded-[8px] px-5 text-base font-semibold shadow-none;background-color: var(--lecturer-surface) !important;border-color: var(--lecturer-border) !important;color: var(--lecturer-text) !important;}.lecturer-edit-button:hover {background-color: color-mix(in oklab,var(--lecturer-primary) 8%,var(--lecturer-surface)) !important;}.lecturer-delete-button {@apply size-12 rounded-[8px] shadow-none;background-color: color-mix(in oklab,var(--lecturer-danger) 10%,var(--lecturer-surface)) !important;color: var(--lecturer-danger) !important;}.lecturer-delete-button:hover {background-color: color-mix(in oklab,var(--lecturer-danger) 16%,var(--lecturer-surface)) !important;}.lecturer-delete-copy {@apply text-sm leading-relaxed;color: var(--lecturer-muted);}.lecturer-delete-copy strong {color: var(--lecturer-text);}.lecturer-danger-action-button {@apply h-10 rounded-[8px] px-5 text-sm font-semibold shadow-none;background-color: var(--lecturer-danger) !important;color: var(--lecturer-primary-foreground) !important;}.lecturer-danger-action-button:hover {background-color: color-mix(in oklab,var(--lecturer-danger) 86%,#000) !important;}.lecturer-detail-content {@apply mx-auto flex w-full max-w-[920px] flex-col gap-6 px-5 py-10 sm:px-8;}.lecturer-upload-input {@apply sr-only;}.lecturer-upload-card {@apply flex min-h-[185px] w-full flex-col items-center justify-center gap-3 rounded-[14px] border border-dashed px-6 py-8 text-center outline-none transition-colors focus-visible:ring-2;background-color: color-mix(in oklab,var(--lecturer-primary) 6%,var(--lecturer-surface));border-color: color-mix(in oklab,var(--lecturer-primary) 28%,var(--lecturer-border));color: var(--lecturer-text);--tw-ring-color: color-mix(in oklab,var(--lecturer-primary) 45%,transparent);}.lecturer-upload-card:hover {background-color: color-mix(in oklab,var(--lecturer-primary) 10%,var(--lecturer-surface));border-color: var(--lecturer-primary);}.lecturer-upload-card[data-uploading='true'] {opacity: 0.78;}.lecturer-upload-icon {@apply flex size-12 items-center justify-center rounded-full;background-color: var(--lecturer-surface);color: var(--lecturer-primary);}.lecturer-upload-title {@apply text-base font-medium;color: var(--lecturer-text);}.lecturer-upload-description {@apply max-w-[560px] text-sm leading-relaxed;color: var(--lecturer-muted);}.lecturer-document-section {@apply mt-1;}.lecturer-document-heading {@apply flex items-center gap-2 text-sm font-bold;color: var(--lecturer-text);}.lecturer-document-list {@apply mt-5 flex flex-col gap-3;}.lecturer-document-card {@apply gap-0 rounded-[10px] border py-0 shadow-none;background-color: color-mix(in oklab,var(--lecturer-primary) 3%,var(--lecturer-surface));border-color: color-mix(in oklab,var(--lecturer-primary) 18%,var(--lecturer-border));}.lecturer-document-card[data-status='failed'] {background-color: color-mix(in oklab,var(--lecturer-danger) 5%,var(--lecturer-surface));border-color: color-mix(in oklab,var(--lecturer-danger) 25%,var(--lecturer-border));}.lecturer-document-content {@apply flex items-start gap-4 px-5 py-5;}.lecturer-document-icon {@apply flex size-10 shrink-0 items-center justify-center rounded-[8px];background-color: color-mix(in oklab,var(--lecturer-primary) 12%,var(--lecturer-surface));color: var(--lecturer-primary);}.lecturer-document-icon[data-status='failed'] {background-color: color-mix(in oklab,var(--lecturer-danger) 12%,var(--lecturer-surface));color: var(--lecturer-danger);}.lecturer-document-copy {@apply min-w-0 flex-1;}.lecturer-document-copy h3 {@apply truncate text-sm font-bold;color: var(--lecturer-text);}.lecturer-document-meta {@apply mt-2 flex flex-wrap items-center gap-3 text-xs;color: var(--lecturer-muted);}.lecturer-document-status {@apply mt-3 flex items-center gap-1.5 text-xs font-semibold;color: var(--lecturer-success);}.lecturer-document-status[data-status='failed'] {color: var(--lecturer-danger);}.lecturer-document-status[data-status='processing'] {color: var(--lecturer-primary);}.lecturer-document-actions {@apply ml-auto flex shrink-0 items-center gap-3;}.lecturer-document-delete {@apply inline-flex size-8 items-center justify-center rounded-[7px] outline-none transition-colors focus-visible:ring-2;color: var(--lecturer-muted);--tw-ring-color: color-mix(in oklab,var(--lecturer-primary) 45%,transparent);}.lecturer-document-delete:hover {background-color: color-mix(in oklab,var(--lecturer-danger) 10%,var(--lecturer-surface));color: var(--lecturer-danger);}.lecturer-detail-empty {@apply rounded-[10px] border px-5 py-8 text-center text-sm;background-color: var(--lecturer-surface);border-color: var(--lecturer-border);color: var(--lecturer-muted);}@media (max-width: 640px) {.student-chat-stage--session {@apply px-3;6 unmodified lines.student-chat-composer {@apply pb-4;}.lecturer-page {@apply px-4 py-6;}.lecturer-page-header h1 {@apply text-2xl;}.lecturer-header-actions {@apply w-full;}.lecturer-create-button {@apply flex-1;}.lecturer-detail-title-row h1 {@apply text-2xl;}.lecturer-detail-actions {@apply w-full;}.lecturer-edit-button {@apply flex-1;}.lecturer-detail-content {@apply px-4 py-6;}.lecturer-document-content {@apply flex-col;}.lecturer-document-actions {@apply ml-0 w-full justify-between;}}}
12345623 unmodified lines30313233343536373839404142434445464748495051525354556 unmodified lines62636465666768697071722 unmodified lines757677787980811 unmodified line838485868788899091929394959697989919 unmodified lines1191201211221231241252 unmodified lines1281291301311321331341351361371381391401411421 unmodified line1441451461471481491501511 unmodified line153154155156157158159160import { Head, Link } from '@inertiajs/react';import type { FormEvent } from 'react';import { useState } from 'react';import AppearanceToggle from '@/components/appearance-toggle';import { Button } from '@/components/ui/button';import { Card, CardContent } from '@/components/ui/card';23 unmodified linesrole: RegisterRole;};type RegisterFieldProps = {autoComplete?: string;autoFocus?: boolean;label: string;name: string;placeholder: string;required?: boolean;tabIndex: number;type?: string;};function RegisterField({autoComplete,autoFocus = false,label,name,placeholder,required = false,tabIndex,type = 'text',}: RegisterFieldProps) {return (<div className="register-field">6 unmodified linestype={type}autoComplete={autoComplete}autoFocus={autoFocus}placeholder={placeholder}required={required}tabIndex={tabIndex}className="register-input"/></div>);}2 unmodified linesconst content = roleContent[role];const [backendError, setBackendError] = useState<string>();const [backendStatus, setBackendStatus] = useState<string>();const [isProcessing, setIsProcessing] = useState(false);const handleSubmit = async (event: FormEvent<HTMLFormElement>,1 unmodified lineevent.preventDefault();setBackendError(undefined);setBackendStatus(undefined);setIsProcessing(true);const formData = new FormData(event.currentTarget);try {const response = await authApi.register({email: String(formData.get('email') ?? ''),password: String(formData.get('password') ?? ''),name: String(formData.get('name') ?? ''),role: content.apiRole,identity_number: String(formData.get('identity_number') ?? ''),});setBackendStatus(response.message);19 unmodified lines<h1 className="register-heading">{content.heading}</h1><form className="register-form" onSubmit={handleSubmit}><input type="hidden" name="role" value={role} /><RegisterField2 unmodified linesplaceholder="Masukkan nama lengkap"autoComplete="name"autoFocusrequiredtabIndex={1}/><RegisterFieldname="identity_number"label={content.identifierLabel}placeholder={content.identifierPlaceholder}requiredtabIndex={2}/><RegisterFieldname="email"1 unmodified linelabel="Email"placeholder="contoh@kampus.ac.id"autoComplete="email"requiredtabIndex={3}/><RegisterFieldname="password"1 unmodified linelabel="Password"placeholder="Minimal 6 karakter"autoComplete="new-password"requiredtabIndex={4}/><Button123456723 unmodified lines3132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421436 unmodified lines1501511521531541551561571581591601611621631641651661671681691701712 unmodified lines1741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272281 unmodified line23023123223323423523623723823924024124224324424524624724824925025125225325425525619 unmodified lines2762772782792802812822832842852862 unmodified lines2892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213221 unmodified line3243253263273283293303313323333343353363373381 unmodified line340341342343344345346347348349350351352353import { Head, Link } from '@inertiajs/react';import type { FormEvent } from 'react';import { useState } from 'react';import AppearanceToggle from '@/components/appearance-toggle';import { Button } from '@/components/ui/button';import { Card, CardContent } from '@/components/ui/card';23 unmodified linesrole: RegisterRole;};type RegisterFormValues = {email: string;identity_number: string;name: string;password: string;};type RegisterFormErrors = Partial<Record<keyof RegisterFormValues, string>>;type RegisterTouchedFields = Partial<Record<keyof RegisterFormValues, boolean>>;type RegisterFieldProps = {autoComplete?: string;autoFocus?: boolean;error?: string;inputMode?: 'email' | 'numeric' | 'text';label: string;name: string;onBlur?: () => void;onChange: (value: string) => void;pattern?: string;placeholder: string;required?: boolean;tabIndex: number;type?: string;value: string;};const emptyFormValues: RegisterFormValues = {email: '',identity_number: '',name: '',password: '',};const namePattern = /^[\p{L}\s.'-]+$/u;const identityNumberPattern = /^(?:\d{5,30}|[A-Z]{2,10}\d{3,30})$/;const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;function validateRegisterForm(values: RegisterFormValues,identifierLabel: string,): RegisterFormErrors {const errors: RegisterFormErrors = {};const normalizedName = values.name.trim().replace(/\s+/g, ' ');const normalizedEmail = values.email.trim();const normalizedIdentityNumber = values.identity_number.trim();if (!normalizedName) {errors.name = 'Nama lengkap wajib diisi.';} else if (normalizedName.length < 3) {errors.name = 'Nama lengkap minimal 3 karakter.';} else if (!namePattern.test(normalizedName)) {errors.name = 'Nama hanya boleh berisi huruf dan tanda nama.';}if (!normalizedIdentityNumber) {errors.identity_number = `${identifierLabel} wajib diisi.`;} else if (!identityNumberPattern.test(normalizedIdentityNumber)) {errors.identity_number = `${identifierLabel} hanya boleh angka, atau kode huruf besar diikuti angka.`;}if (!normalizedEmail) {errors.email = 'Email wajib diisi.';} else if (normalizedEmail.includes(' ') ||!emailPattern.test(normalizedEmail)) {errors.email = 'Format email tidak valid.';}if (!values.password) {errors.password = 'Password wajib diisi.';} else if (values.password.length < 6) {errors.password = 'Password minimal 6 karakter.';} else if (/\s/.test(values.password)) {errors.password = 'Password tidak boleh mengandung spasi.';}return errors;}function normalizeRegisterValues(values: RegisterFormValues,): RegisterFormValues {return {email: values.email.trim(),identity_number: values.identity_number.trim(),name: values.name.trim().replace(/\s+/g, ' '),password: values.password,};}function RegisterField({autoComplete,autoFocus = false,error,inputMode = 'text',label,name,onBlur,onChange,pattern,placeholder,required = false,tabIndex,type = 'text',value,}: RegisterFieldProps) {return (<div className="register-field">6 unmodified linestype={type}autoComplete={autoComplete}autoFocus={autoFocus}aria-invalid={Boolean(error)}placeholder={placeholder}inputMode={inputMode}onBlur={onBlur}onChange={(event) => onChange(event.target.value)}pattern={pattern}required={required}tabIndex={tabIndex}value={value}className="register-input"/>{error && (<p className="register-error" role="alert">{error}</p>)}</div>);}2 unmodified linesconst content = roleContent[role];const [backendError, setBackendError] = useState<string>();const [backendStatus, setBackendStatus] = useState<string>();const [fieldErrors, setFieldErrors] = useState<RegisterFormErrors>({});const [formValues, setFormValues] =useState<RegisterFormValues>(emptyFormValues);const [isProcessing, setIsProcessing] = useState(false);const [submittedOnce, setSubmittedOnce] = useState(false);const [touchedFields, setTouchedFields] = useState<RegisterTouchedFields>({},);function validateCurrentForm(values: RegisterFormValues = formValues,): RegisterFormErrors {return validateRegisterForm(values, content.identifierLabel);}function setSingleFieldError(field: keyof RegisterFormValues,errors: RegisterFormErrors,): void {setFieldErrors((currentErrors) => {const nextErrors = { ...currentErrors };const message = errors[field];if (message) {nextErrors[field] = message;} else {delete nextErrors[field];}return nextErrors;});}function updateField(field: keyof RegisterFormValues, value: string): void {const nextValues = { ...formValues, [field]: value };setFormValues(nextValues);if (submittedOnce || touchedFields[field]) {setSingleFieldError(field, validateCurrentForm(nextValues));}}function validateFieldOnBlur(field: keyof RegisterFormValues): void {setTouchedFields((currentFields) => ({...currentFields,[field]: true,}));setSingleFieldError(field, validateCurrentForm());}const handleSubmit = async (event: FormEvent<HTMLFormElement>,1 unmodified lineevent.preventDefault();setBackendError(undefined);setBackendStatus(undefined);setSubmittedOnce(true);const normalizedValues = normalizeRegisterValues(formValues);const nextFieldErrors = validateCurrentForm(normalizedValues);setFormValues(normalizedValues);setFieldErrors(nextFieldErrors);if (Object.keys(nextFieldErrors).length > 0) {return;}setIsProcessing(true);try {const response = await authApi.register({email: normalizedValues.email,password: normalizedValues.password,name: normalizedValues.name,role: content.apiRole,identity_number: normalizedValues.identity_number,});setBackendStatus(response.message);19 unmodified lines<h1 className="register-heading">{content.heading}</h1><formclassName="register-form"noValidateonSubmit={handleSubmit}><input type="hidden" name="role" value={role} /><RegisterField2 unmodified linesplaceholder="Masukkan nama lengkap"autoComplete="name"autoFocuserror={fieldErrors.name}onBlur={() => validateFieldOnBlur('name')}onChange={(value) => updateField('name', value)}pattern="[\p{L}\s.'-]+"requiredtabIndex={1}value={formValues.name}/><RegisterFieldname="identity_number"label={content.identifierLabel}placeholder={content.identifierPlaceholder}autoComplete="off"error={fieldErrors.identity_number}inputMode="text"onBlur={() =>validateFieldOnBlur('identity_number')}onChange={(value) =>updateField('identity_number',value.toUpperCase(),)}pattern="(?:\d{5,30}|[A-Z]{2,10}\d{3,30})"requiredtabIndex={2}value={formValues.identity_number}/><RegisterFieldname="email"1 unmodified linelabel="Email"placeholder="contoh@kampus.ac.id"autoComplete="email"error={fieldErrors.email}inputMode="email"onBlur={() => validateFieldOnBlur('email')}onChange={(value) =>updateField('email', value)}requiredtabIndex={3}value={formValues.email}/><RegisterFieldname="password"1 unmodified linelabel="Password"placeholder="Minimal 6 karakter"autoComplete="new-password"error={fieldErrors.password}onBlur={() => validateFieldOnBlur('password')}onChange={(value) =>updateField('password', value)}requiredtabIndex={4}value={formValues.password}/><Button
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200import { router } from '@inertiajs/react';import { LayoutDashboard, LogOut, MessageSquare, Settings } from 'lucide-react';import type { CSSProperties, ReactNode } from 'react';import { useSyncExternalStore } from 'react';
import { Avatar, AvatarFallback } from '@/components/ui/avatar';import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarHeader, SidebarInset, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarProvider, SidebarRail, SidebarTrigger, useSidebar,} from '@/components/ui/sidebar';import { clearAuthSession, getStoredAuthUser } from '@/lib/auth';import { dosen, login } from '@/routes';import { pengaturan as dosenPengaturan } from '@/routes/dosen';
type DosenMenu = 'dashboard' | 'settings';
const lecturerSidebarStyle = { '--sidebar-width': '212px', '--sidebar-width-icon': '64px',} as CSSProperties;
function getStoredLecturerName(): string { return getStoredAuthUser()?.name ?? 'Dosen';}
function subscribeToAuthStorage(onStoreChange: () => void): () => void { if (typeof window === 'undefined') { return () => {}; }
window.addEventListener('storage', onStoreChange);
return () => window.removeEventListener('storage', onStoreChange);}
function useStoredLecturerName(): string { return useSyncExternalStore( subscribeToAuthStorage, getStoredLecturerName, () => 'Dosen', );}
function getInitials(name: string): string { return name .split(' ') .filter(Boolean) .slice(0, 2) .map((part) => part[0]?.toUpperCase()) .join('');}
function handleLogout(): void { clearAuthSession(); router.visit(login());}
function DosenSidebarBrand() { const { state, toggleSidebar } = useSidebar();
const handleBrandClick = (): void => { if (state === 'collapsed') { toggleSidebar(); } };
return ( <button aria-label="Buka sidebar" className="lecturer-brand" onClick={handleBrandClick} type="button" > <span className="lecturer-brand-mark"> <MessageSquare className="size-4" /> </span> <span className="lecturer-brand-copy">RAG Hub</span> </button> );}
function DosenSidebar({ activeMenu }: { activeMenu: DosenMenu }) { const lecturerName = useStoredLecturerName();
return ( <Sidebar className="lecturer-sidebar" collapsible="icon"> <SidebarHeader className="lecturer-sidebar-header"> <DosenSidebarBrand />
<SidebarTrigger className="lecturer-sidebar-trigger" /> </SidebarHeader>
<SidebarContent className="lecturer-sidebar-content"> <SidebarGroup className="lecturer-nav-group"> <SidebarGroupContent> <SidebarMenu className="lecturer-nav-list"> <SidebarMenuItem> <SidebarMenuButton className="lecturer-nav-button" isActive={activeMenu === 'dashboard'} onClick={() => router.visit(dosen())} tooltip="Dashboard KB" > <LayoutDashboard className="size-4" /> <span>Dashboard KB</span> </SidebarMenuButton> </SidebarMenuItem>
<SidebarMenuItem> <SidebarMenuButton className="lecturer-nav-button" isActive={activeMenu === 'settings'} onClick={() => router.visit(dosenPengaturan()) } tooltip="Pengaturan" > <Settings className="size-4" /> <span>Pengaturan</span> </SidebarMenuButton> </SidebarMenuItem> </SidebarMenu> </SidebarGroupContent> </SidebarGroup> </SidebarContent>
<SidebarFooter className="lecturer-sidebar-footer"> <SidebarMenu> <SidebarMenuItem> <SidebarMenuButton className="lecturer-user-button" tooltip={lecturerName} > <Avatar className="lecturer-user-avatar"> <AvatarFallback> {getInitials(lecturerName) || 'DS'} </AvatarFallback> </Avatar> <span className="lecturer-user-copy"> <span className="lecturer-user-name"> {lecturerName} </span> <span className="lecturer-user-role"> Dosen </span> </span> </SidebarMenuButton> </SidebarMenuItem>
<SidebarMenuItem> <SidebarMenuButton className="lecturer-logout-button" onClick={handleLogout} tooltip="Logout" > <LogOut className="size-4" /> <span>Logout</span> </SidebarMenuButton> </SidebarMenuItem> </SidebarMenu> </SidebarFooter>
<SidebarRail /> </Sidebar> );}
export function DosenShell({ activeMenu = 'dashboard', children,}: { activeMenu?: DosenMenu; children: ReactNode;}) { return ( <SidebarProvider className="lecturer-dashboard-shell" defaultOpen style={lecturerSidebarStyle} > <DosenSidebar activeMenu={activeMenu} />
<SidebarInset className="lecturer-workspace"> {children} </SidebarInset> </SidebarProvider> );}123459 unmodified lines151617181920214 unmodified lines262728293031323 unmodified lines36373839404110 unmodified lines525354555657585960616223 unmodified lines8687888990914 unmodified lines96979899100101102103104105106import { BookOpen, Send, Sparkles } from 'lucide-react';import type { FormEvent } from 'react';import { Button } from '@/components/ui/button';import { Card, CardContent } from '@/components/ui/card';9 unmodified linesexport function QuestionComposer({courses,isCourseLocked = false,isLoadingCourses,isProcessing,onCourseChange,4 unmodified linesvariant = 'empty',}: {courses: CourseResponse[];isCourseLocked?: boolean;isLoadingCourses: boolean;isProcessing: boolean;onCourseChange: (courseId: string) => void;3 unmodified linesselectedCourseId: string;variant?: 'dock' | 'empty';}) {return (<CardclassName={cn(10 unmodified lines</span><Selectdisabled={isCourseLocked ||isLoadingCourses ||courses.length === 0}onValueChange={onCourseChange}value={selectedCourseId}>23 unmodified lines<textareaaria-label="Pertanyaan"className="text-base"onChange={(event) =>onQuestionChange(event.target.value)}4 unmodified lines<ButtonclassName="student-floating-send"disabled={isProcessing ||selectedCourseId.length === 0 ||question.trim().length === 0}size="icon"type="submit">123459 unmodified lines1516171819204 unmodified lines2526272829303 unmodified lines343536373839404142434445464748495051525354555657585960616210 unmodified lines7374757677787923 unmodified lines1031041051061071081094 unmodified lines114115116117118119120import { BookOpen, Send, Sparkles } from 'lucide-react';import type { FormEvent, KeyboardEvent } from 'react';import { Button } from '@/components/ui/button';import { Card, CardContent } from '@/components/ui/card';9 unmodified linesexport function QuestionComposer({courses,isLoadingCourses,isProcessing,onCourseChange,4 unmodified linesvariant = 'empty',}: {courses: CourseResponse[];isLoadingCourses: boolean;isProcessing: boolean;onCourseChange: (courseId: string) => void;3 unmodified linesselectedCourseId: string;variant?: 'dock' | 'empty';}) {const canSubmit =!isProcessing &&selectedCourseId.length > 0 &&question.trim().length > 0;function handleQuestionKeyDown(event: KeyboardEvent<HTMLTextAreaElement>,): void {if (event.key !== 'Enter' ||event.shiftKey ||event.nativeEvent.isComposing) {return;}event.preventDefault();if (canSubmit) {event.currentTarget.form?.requestSubmit();}}return (<CardclassName={cn(10 unmodified lines</span><Selectdisabled={isLoadingCourses || courses.length === 0}onValueChange={onCourseChange}value={selectedCourseId}>23 unmodified lines<textareaaria-label="Pertanyaan"className="text-base"onKeyDown={handleQuestionKeyDown}onChange={(event) =>onQuestionChange(event.target.value)}4 unmodified lines<ButtonclassName="student-floating-send"disabled={!canSubmit}size="icon"type="submit">
11 unmodified lines12131415161721 unmodified lines39404142434486 unmodified lines1311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173189 unmodified lines32832933033133233333411 unmodified linesimport AppearanceToggle from '@/components/appearance-toggle';import { Avatar, AvatarFallback } from '@/components/ui/avatar';import { Button } from '@/components/ui/button';import {Sidebar,SidebarContent,21 unmodified lines'--sidebar-width-icon': '64px',} as CSSProperties;export function getStoredStudentName(): string {return getStoredAuthUser()?.name ?? 'Mahasiswa';}86 unmodified linesactiveSessionId?: string;chatSessions: ChatSessionResponse[];isLoading: boolean;onDeleteSession?: (sessionId: string) => void;studentName: string;}) {const [isHistoryOpen, setIsHistoryOpen] = useState(true);const { state } = useSidebar();const isSidebarCollapsed = state === 'collapsed';return (<Sidebar className="student-sidebar" collapsible="icon"><SidebarHeader className="student-sidebar-top"><StudentSidebarLogo /><SidebarTrigger className="student-sidebar-trigger" /></SidebarHeader><SidebarContent className="student-sidebar-content"><SidebarGroup className="student-history-group">{isSidebarCollapsed ? (<SidebarGroupContent><SidebarMenu className="student-history-list"><SidebarMenuItem><SidebarMenuButtonclassName="student-history-menu-button"tooltip="Riwayat Chat"><Clock3 className="student-history-menu-icon size-4" /><span className="student-history-copy"><span className="student-history-title">Riwayat Chat</span></span></SidebarMenuButton></SidebarMenuItem></SidebarMenu></SidebarGroupContent>) : (<><SidebarGroupLabel asChild><buttonaria-expanded={isHistoryOpen}className="student-history-label"onClick={() =>setIsHistoryOpen((currentState) => !currentState,)}type="button"><Clock3 className="size-4" /><span>Riwayat Chat</span><ChevronDown className="student-history-chevron" /></button></SidebarGroupLabel>{isHistoryOpen && (<SidebarGroupContent><SidebarMenu className="student-history-list">{isLoading && (<SidebarMenuItem><SidebarMenuButtonclassName="student-history-menu-button"disabled><Clock3 className="student-history-menu-icon size-4" /><span className="student-history-copy"><span className="student-history-title">Memuat riwayat</span></span></SidebarMenuButton></SidebarMenuItem>)}{chatSessions.map((session) => {const sessionTime =formatSessionTime(session.last_message_at ??session.updated_at ??session.created_at,);return (<SidebarMenuItemclassName="student-history-menu-item"key={session.uuid_id}><SidebarMenuButtonclassName="student-history-menu-button"isActive={session.uuid_id ===activeSessionId}onClick={() =>router.visit(showMahasiswaSession(session.uuid_id,),)}tooltip={session.title}type="button"><Clock3 className="student-history-menu-icon size-4" /><span className="student-history-copy"><span className="student-history-title">{session.title}</span>{sessionTime && (<span className="student-history-meta">{sessionTime}</span>)}</span></SidebarMenuButton>{onDeleteSession && (<buttonaria-label={`Hapus sesi ${session.title}`}className="student-history-delete"onClick={(event,) => {event.stopPropagation();onDeleteSession(session.uuid_id,);}}type="button"><Trash2 className="size-3" /></button>)}</SidebarMenuItem>);})}</SidebarMenu></SidebarGroupContent>)}</>)}</SidebarGroup></SidebarContent><SidebarFooter className="student-sidebar-footer"><SidebarMenu><SidebarMenuItem><SidebarMenuButtonclassName="student-user-menu-button"tooltip={studentName}><Avatar className="student-user-avatar"><AvatarFallback>{getInitials(studentName) || 'AK'}</AvatarFallback></Avatar><span className="student-user-copy"><span className="student-user-name">{studentName}</span><span className="student-user-role">Mahasiswa</span></span></SidebarMenuButton></SidebarMenuItem><SidebarMenuItem><SidebarMenuButtonclassName="student-logout-button"onClick={handleLogout}tooltip="Logout"><LogOut className="size-4" /><span>Logout</span></SidebarMenuButton></SidebarMenuItem></SidebarMenu></SidebarFooter><SidebarRail /></Sidebar>);}9 unmodified lineschatSessions: ChatSessionResponse[];children: ReactNode;isLoadingSessions: boolean;onDeleteSession?: (sessionId: string) => void;studentName: string;}) {return (11 unmodified lines121314151617181920212223242521 unmodified lines474849505152535455565786 unmodified lines1441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314329 unmodified lines44244344444544644744844945011 unmodified linesimport AppearanceToggle from '@/components/appearance-toggle';import { Avatar, AvatarFallback } from '@/components/ui/avatar';import { Button } from '@/components/ui/button';import {Dialog,DialogContent,DialogDescription,DialogFooter,DialogHeader,DialogTitle,} from '@/components/ui/dialog';import {Sidebar,SidebarContent,21 unmodified lines'--sidebar-width-icon': '64px',} as CSSProperties;export type DeleteSessionResult = {ok: boolean;message?: string;};export function getStoredStudentName(): string {return getStoredAuthUser()?.name ?? 'Mahasiswa';}86 unmodified linesactiveSessionId?: string;chatSessions: ChatSessionResponse[];isLoading: boolean;onDeleteSession?: (sessionId: string,) => DeleteSessionResult | Promise<DeleteSessionResult>;studentName: string;}) {const [isHistoryOpen, setIsHistoryOpen] = useState(true);const [deleteDialogMessage, setDeleteDialogMessage] = useState<string>();const [isDeletingSession, setIsDeletingSession] = useState(false);const [sessionToDelete, setSessionToDelete] =useState<ChatSessionResponse>();const { state } = useSidebar();const isSidebarCollapsed = state === 'collapsed';function handleDeleteDialogOpenChange(open: boolean): void {if (isDeletingSession) {return;}if (!open) {setSessionToDelete(undefined);setDeleteDialogMessage(undefined);}}async function handleConfirmDeleteSession(): Promise<void> {if (!sessionToDelete || !onDeleteSession) {return;}setIsDeletingSession(true);setDeleteDialogMessage(undefined);try {const result = await onDeleteSession(sessionToDelete.uuid_id);if (result.ok) {setSessionToDelete(undefined);return;}setDeleteDialogMessage(result.message);} finally {setIsDeletingSession(false);}}return (<><Sidebar className="student-sidebar" collapsible="icon"><SidebarHeader className="student-sidebar-top"><StudentSidebarLogo /><SidebarTrigger className="student-sidebar-trigger" /></SidebarHeader><SidebarContent className="student-sidebar-content"><SidebarGroup className="student-history-group">{isSidebarCollapsed ? (<SidebarGroupContent><SidebarMenu className="student-history-list"><SidebarMenuItem><SidebarMenuButtonclassName="student-history-menu-button"tooltip="Riwayat Chat"><Clock3 className="student-history-menu-icon size-4" /><span className="student-history-copy"><span className="student-history-title">Riwayat Chat</span></span></SidebarMenuButton></SidebarMenuItem></SidebarMenu></SidebarGroupContent>) : (<><SidebarGroupLabel asChild><buttonaria-expanded={isHistoryOpen}className="student-history-label"onClick={() =>setIsHistoryOpen((currentState) => !currentState,)}type="button"><Clock3 className="size-4" /><span>Riwayat Chat</span><ChevronDown className="student-history-chevron" /></button></SidebarGroupLabel>{isHistoryOpen && (<SidebarGroupContent><SidebarMenu className="student-history-list">{isLoading && (<SidebarMenuItem><SidebarMenuButtonclassName="student-history-menu-button"disabled><Clock3 className="student-history-menu-icon size-4" /><span className="student-history-copy"><span className="student-history-title">Memuat riwayat</span></span></SidebarMenuButton></SidebarMenuItem>)}{chatSessions.map((session) => {const sessionTime =formatSessionTime(session.last_message_at ??session.updated_at ??session.created_at,);return (<SidebarMenuItemclassName="student-history-menu-item"key={session.uuid_id}><SidebarMenuButtonclassName="student-history-menu-button"isActive={session.uuid_id ===activeSessionId}onClick={() =>router.visit(showMahasiswaSession(session.uuid_id,),)}tooltip={session.title}type="button"><Clock3 className="student-history-menu-icon size-4" /><span className="student-history-copy"><span className="student-history-title">{session.title}</span>{sessionTime && (<span className="student-history-meta">{sessionTime}</span>)}</span></SidebarMenuButton>{onDeleteSession && (<buttonaria-label={`Hapus sesi ${session.title}`}className="student-history-delete"onClick={(event,) => {event.stopPropagation();setSessionToDelete(session,);setDeleteDialogMessage(undefined,);}}type="button"><Trash2 className="size-3" /></button>)}</SidebarMenuItem>);})}</SidebarMenu></SidebarGroupContent>)}</>)}</SidebarGroup></SidebarContent><SidebarFooter className="student-sidebar-footer"><SidebarMenu><SidebarMenuItem><SidebarMenuButtonclassName="student-user-menu-button"tooltip={studentName}><Avatar className="student-user-avatar"><AvatarFallback>{getInitials(studentName) || 'AK'}</AvatarFallback></Avatar><span className="student-user-copy"><span className="student-user-name">{studentName}</span><span className="student-user-role">Mahasiswa</span></span></SidebarMenuButton></SidebarMenuItem><SidebarMenuItem><SidebarMenuButtonclassName="student-logout-button"onClick={handleLogout}tooltip="Logout"><LogOut className="size-4" /><span>Logout</span></SidebarMenuButton></SidebarMenuItem></SidebarMenu></SidebarFooter><SidebarRail /></Sidebar><DialogonOpenChange={handleDeleteDialogOpenChange}open={Boolean(sessionToDelete)}><DialogContent className="student-delete-dialog"><DialogHeader><DialogTitle>Hapus Riwayat Chat</DialogTitle><DialogDescription>Sesi chat ini akan dihapus dari riwayat.</DialogDescription></DialogHeader><div className="student-delete-dialog-body"><p className="student-delete-copy">Hapus sesi{' '}<strong>{sessionToDelete?.title ?? 'chat ini'}</strong>?</p>{deleteDialogMessage && (<p className="student-delete-error" role="alert">{deleteDialogMessage}</p>)}</div><DialogFooter className="student-delete-dialog-footer"><ButtonclassName="student-delete-cancel"disabled={isDeletingSession}onClick={() => handleDeleteDialogOpenChange(false)}type="button"variant="outline">Batal</Button><ButtonclassName="student-delete-confirm"disabled={isDeletingSession}onClick={() => {void handleConfirmDeleteSession();}}type="button">{isDeletingSession ? 'Menghapus...' : 'Hapus'}</Button></DialogFooter></DialogContent></Dialog></>);}9 unmodified lineschatSessions: ChatSessionResponse[];children: ReactNode;isLoadingSessions: boolean;onDeleteSession?: (sessionId: string,) => DeleteSessionResult | Promise<DeleteSessionResult>;studentName: string;}) {return (
23 unmodified lines24252627282944 unmodified lines74757677787926 unmodified lines10610710810911011111211311411511680 unmodified lines1971981992002012022 unmodified lines20520620720820921014 unmodified lines22522622722822923023 unmodified lineslimit: number;};export type ChatSessionResponse = {uuid_id: string;user_id: string;44 unmodified linescreated_at: string;};export type ChatQueryResponse = {message_id: string;role?: string;26 unmodified lines};const DIRECT_CHAT_STORAGE_PREFIX = 'sevima_raghub_direct_messages';function getDirectChatStorageKey(sessionId: string): string {return `${DIRECT_CHAT_STORAGE_PREFIX}:${sessionId}`;}function getBrowserSessionStorage(): Storage | null {if (typeof window === 'undefined') {return null;80 unmodified linesgetBrowserSessionStorage()?.removeItem(getDirectChatStorageKey(sessionId));}export const ragApi = {listCourses({ page = 1, limit = 100, signal }: ListCoursesOptions = {}) {return api.get<CourseListResponse>('/courses', {2 unmodified lines});},listChatSessions({page = 1,limit = 20,14 unmodified lines});},getChatSession(sessionId: string,{ signal, token }: AuthenticatedRequestOptions = {},23 unmodified lines2425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686944 unmodified lines11411511611711811912012112212312412526 unmodified lines15215315415515615715815916016116216316416516616716880 unmodified lines2492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982 unmodified lines30130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733814 unmodified lines35335435535635735835936036136236336436536636736836937037137237337437537637737823 unmodified lineslimit: number;};export type CreateCourseRequest = {title: string;description?: string;};export type UpdateCourseRequest = {title?: string;description?: string;};export type DocumentStatus = 'processing' | 'ready' | 'failed';export type DocumentResponse = {id: string;filename: string;file_type: string;file_size: number;status: DocumentStatus;course_id: string;course_name?: string;uploaded_by: string;uploader_name?: string;summary?: string;chunk_count?: number;error?: string;created_at: string;updated_at: string;};export type DocumentListResponse = {data: DocumentResponse[];};export type UploadDocumentResponse = {document_id: string;filename: string;status: DocumentStatus;message: string;};export type ChatSessionResponse = {uuid_id: string;user_id: string;44 unmodified linescreated_at: string;};export type PendingInitialChat = {content: string;courseId: string;userMessage: ChatMessageResponse;};export type ChatQueryResponse = {message_id: string;role?: string;26 unmodified lines};const DIRECT_CHAT_STORAGE_PREFIX = 'sevima_raghub_direct_messages';const PENDING_INITIAL_CHAT_STORAGE_PREFIX ='sevima_raghub_pending_initial_chat';function getDirectChatStorageKey(sessionId: string): string {return `${DIRECT_CHAT_STORAGE_PREFIX}:${sessionId}`;}function getPendingInitialChatStorageKey(sessionId: string): string {return `${PENDING_INITIAL_CHAT_STORAGE_PREFIX}:${sessionId}`;}function getBrowserSessionStorage(): Storage | null {if (typeof window === 'undefined') {return null;80 unmodified linesgetBrowserSessionStorage()?.removeItem(getDirectChatStorageKey(sessionId));}export function getPendingInitialChat(sessionId: string,): PendingInitialChat | undefined {const rawPendingChat = getBrowserSessionStorage()?.getItem(getPendingInitialChatStorageKey(sessionId),);if (!rawPendingChat) {return undefined;}try {const pendingChat = JSON.parse(rawPendingChat) as PendingInitialChat;if (typeof pendingChat.content === 'string' &&typeof pendingChat.courseId === 'string' &&typeof pendingChat.userMessage?.uuid_id === 'string') {return pendingChat;}} catch {return undefined;}return undefined;}export function savePendingInitialChat(sessionId: string,pendingChat: PendingInitialChat,): void {getBrowserSessionStorage()?.setItem(getPendingInitialChatStorageKey(sessionId),JSON.stringify(pendingChat),);}export function clearPendingInitialChat(sessionId: string): void {getBrowserSessionStorage()?.removeItem(getPendingInitialChatStorageKey(sessionId),);}export const ragApi = {listCourses({ page = 1, limit = 100, signal }: ListCoursesOptions = {}) {return api.get<CourseListResponse>('/courses', {2 unmodified lines});},getCourse(courseId: string,{ signal, token }: AuthenticatedRequestOptions = {},) {return api.get<CourseResponse>(`/courses/${courseId}`, {signal,token,});},createCourse(payload: CreateCourseRequest, token?: string) {return api.post<CourseResponse>('/courses', payload, {token,});},updateCourse(courseId: string,payload: UpdateCourseRequest,token?: string,) {return api.put<CourseResponse>(`/courses/${courseId}`, payload, {token,});},deleteCourse(courseId: string, token?: string) {return api.delete<unknown>(`/courses/${courseId}`, {token,});},listChatSessions({page = 1,limit = 20,14 unmodified lines});},listCourseDocuments(courseId: string,{ signal, token }: AuthenticatedRequestOptions = {},) {return api.get<DocumentListResponse>(`/courses/${courseId}/documents`, {signal,token,});},uploadDocument(courseId: string, file: File, token?: string) {const formData = new FormData();formData.append('file', file);formData.append('course_id', courseId);return api.post<UploadDocumentResponse>('/documents/upload', formData, {token,});},getChatSession(sessionId: string,{ signal, token }: AuthenticatedRequestOptions = {},
7 unmodified lines89101112131422 unmodified lines3738394041424344457 unmodified linesimport { Input } from '@/components/ui/input';import { Label } from '@/components/ui/label';import { authApi, getAuthErrorMessage, saveAuthSession } from '@/lib/auth';import { dashboard, home, mahasiswa, register } from '@/routes';type LoginProps = {canRegister?: boolean;22 unmodified linessaveAuthSession(response, remember);router.visit(response.user.role === 'student' ? mahasiswa() : dashboard(),);} catch (error) {setBackendError(getAuthErrorMessage(error));} finally {7 unmodified lines89101112131422 unmodified lines373839404142434445464748495051525354557 unmodified linesimport { Input } from '@/components/ui/input';import { Label } from '@/components/ui/label';import { authApi, getAuthErrorMessage, saveAuthSession } from '@/lib/auth';import { dashboard, dosen, home, mahasiswa, register } from '@/routes';type LoginProps = {canRegister?: boolean;22 unmodified linessaveAuthSession(response, remember);if (response.user.role === 'student') {router.visit(mahasiswa());return;}if (response.user.role === 'lecturer') {router.visit(dosen());return;}router.visit(dashboard());} catch (error) {setBackendError(getAuthErrorMessage(error));} finally {
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618import { Head, router } from '@inertiajs/react';import { AlertCircle, ArrowLeft, CheckCircle2, FileText, LoaderCircle, Pencil, Trash2, Upload,} from 'lucide-react';import type { ChangeEvent, DragEvent, FormEvent } from 'react';import { useCallback, useEffect, useRef, useState } from 'react';
import { DosenShell } from '@/components/dosen/dosen-shell';import { Button } from '@/components/ui/button';import { Card, CardContent } from '@/components/ui/card';import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle,} from '@/components/ui/dialog';import { Input } from '@/components/ui/input';import { Label } from '@/components/ui/label';import { getStoredAuthToken } from '@/lib/auth';import type { CourseResponse, DocumentResponse, DocumentStatus,} from '@/lib/rag';import { getRagErrorMessage, ragApi } from '@/lib/rag';import { dosen } from '@/routes';
type DosenDetailProps = { courseId: string;};
type CourseForm = { title: string; description: string;};
const emptyCourseForm: CourseForm = { description: '', title: '',};
const acceptedDocumentTypes = [ '.pdf', '.ppt', '.pptx', '.txt', 'application/pdf', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'text/plain',].join(',');
function formatDate(value?: string): string { if (!value) { return '-'; }
const datePart = value.split('T')[0];
return datePart || value;}
function formatFileSize(bytes: number): string { if (!Number.isFinite(bytes) || bytes <= 0) { return '-'; }
const units = ['B', 'KB', 'MB', 'GB']; let size = bytes; let unitIndex = 0;
while (size >= 1024 && unitIndex < units.length - 1) { size /= 1024; unitIndex += 1; }
return `${size.toFixed(unitIndex === 0 ? 0 : 1)} ${units[unitIndex]}`;}
function getStatusLabel(status: DocumentStatus): string { if (status === 'failed') { return 'Gagal diproses'; }
if (status === 'processing') { return 'Sedang diproses'; }
return 'Tersedia untuk Q&A';}
function DocumentStatusIcon({ status }: { status: DocumentStatus }) { if (status === 'failed') { return <AlertCircle className="size-4" />; }
if (status === 'processing') { return <LoaderCircle className="size-4 animate-spin" />; }
return <CheckCircle2 className="size-4" />;}
function DocumentCard({ document }: { document: DocumentResponse }) { const statusTone = document.status;
return ( <Card className="lecturer-document-card" data-status={statusTone}> <CardContent className="lecturer-document-content"> <span className="lecturer-document-icon" data-status={statusTone} > <FileText className="size-5" /> </span>
<div className="lecturer-document-copy"> <h3>{document.filename}</h3> <p className="lecturer-document-meta"> <span>{formatFileSize(document.file_size)}</span> <span aria-hidden="true">·</span> <span>{formatDate(document.created_at)}</span> {document.chunk_count !== undefined && ( <> <span aria-hidden="true">·</span> <span>{document.chunk_count} chunks</span> </> )} </p>
<p className="lecturer-document-status" data-status={statusTone} > <DocumentStatusIcon status={document.status} /> {getStatusLabel(document.status)} </p> </div>
<div className="lecturer-document-actions"> <button aria-label={`Hapus ${document.filename}`} className="lecturer-document-delete" type="button" > <Trash2 className="size-4" /> </button> </div> </CardContent> </Card> );}
export default function DosenDetail({ courseId }: DosenDetailProps) { const [course, setCourse] = useState<CourseResponse>(); const [documents, setDocuments] = useState<DocumentResponse[]>([]); const [deleteCourseMessage, setDeleteCourseMessage] = useState<string>(); const [editCourseMessage, setEditCourseMessage] = useState<string>(); const [editForm, setEditForm] = useState<CourseForm>(emptyCourseForm); const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false); const [isDeletingCourse, setIsDeletingCourse] = useState(false); const [isEditDialogOpen, setIsEditDialogOpen] = useState(false); const [isLoading, setIsLoading] = useState(true); const [isUpdatingCourse, setIsUpdatingCourse] = useState(false); const [isUploading, setIsUploading] = useState(false); const fileInputRef = useRef<HTMLInputElement>(null);
const loadCourseDetail = useCallback( async (signal?: AbortSignal): Promise<void> => { setIsLoading(true);
const token = getStoredAuthToken() ?? undefined;
const [courseResult, documentsResult] = await Promise.allSettled([ ragApi.getCourse(courseId, { signal, token, }), ragApi.listCourseDocuments(courseId, { signal, token, }), ]);
if (signal?.aborted) { return; }
if (courseResult.status === 'fulfilled') { setCourse(courseResult.value); }
if (documentsResult.status === 'fulfilled') { setDocuments(documentsResult.value.data); } else { setDocuments([]); }
setIsLoading(false); }, [courseId], );
useEffect(() => { const controller = new AbortController();
void Promise.resolve().then(() => loadCourseDetail(controller.signal));
return () => { controller.abort(); }; }, [loadCourseDetail]);
async function handleUploadDocument(file: File): Promise<void> { setIsUploading(true);
try { await ragApi.uploadDocument( courseId, file, getStoredAuthToken() ?? undefined, );
await loadCourseDetail(); } catch { // Backend upload messages are intentionally hidden in this view. } finally { setIsUploading(false); } }
function handleEditDialogOpenChange(open: boolean): void { if (isUpdatingCourse) { return; }
setIsEditDialogOpen(open); setEditCourseMessage(undefined);
if (open) { setEditForm({ description: course?.description ?? '', title: course?.title ?? '', }); } }
async function handleUpdateCourseSubmit( event: FormEvent<HTMLFormElement>, ): Promise<void> { event.preventDefault(); setEditCourseMessage(undefined); setIsUpdatingCourse(true);
try { const updatedCourse = await ragApi.updateCourse( courseId, { description: editForm.description.trim(), title: editForm.title.trim(), }, getStoredAuthToken() ?? undefined, );
setCourse(updatedCourse); setIsEditDialogOpen(false); } catch (error) { setEditCourseMessage(getRagErrorMessage(error)); } finally { setIsUpdatingCourse(false); } }
function handleDeleteDialogOpenChange(open: boolean): void { if (isDeletingCourse) { return; }
setIsDeleteDialogOpen(open); setDeleteCourseMessage(undefined); }
async function handleDeleteCourse(): Promise<void> { setDeleteCourseMessage(undefined); setIsDeletingCourse(true);
try { await ragApi.deleteCourse( courseId, getStoredAuthToken() ?? undefined, ); router.visit(dosen()); } catch (error) { setDeleteCourseMessage(getRagErrorMessage(error)); } finally { setIsDeletingCourse(false); } }
function handleFileInputChange(event: ChangeEvent<HTMLInputElement>): void { const file = event.target.files?.[0]; event.target.value = '';
if (file) { void handleUploadDocument(file); } }
function handleUploadCardClick(): void { if (!isUploading) { fileInputRef.current?.click(); } }
function handleUploadCardDrop(event: DragEvent<HTMLButtonElement>): void { event.preventDefault();
if (isUploading) { return; }
const file = event.dataTransfer.files[0];
if (file) { void handleUploadDocument(file); } }
const title = course?.title ?? (isLoading ? 'Memuat mata kuliah...' : 'Detail mata kuliah'); const description = course?.description ?? (isLoading ? 'Mengambil detail mata kuliah dari backend.' : 'Tidak ada deskripsi mata kuliah.');
return ( <> <Head title={course ? course.title : 'Detail Mata Kuliah'} />
<DosenShell> <main className="lecturer-detail-page"> <section className="lecturer-detail-header"> <button aria-label="Kembali ke dashboard dosen" className="lecturer-detail-back" onClick={() => router.visit(dosen())} type="button" > <ArrowLeft className="size-6" /> </button>
<div className="lecturer-detail-heading"> <div className="lecturer-detail-title-row"> <h1>{title}</h1> </div> <p>{description}</p> </div>
<div className="lecturer-detail-actions"> <Button className="lecturer-edit-button" disabled={!course || isLoading} onClick={() => handleEditDialogOpenChange(true)} variant="outline" > <Pencil className="size-5" /> Edit </Button> <Button className="lecturer-delete-button" disabled={!course || isLoading} onClick={() => handleDeleteDialogOpenChange(true) } variant="ghost" > <Trash2 className="size-5" /> </Button> </div> </section>
<section className="lecturer-detail-content"> <input accept={acceptedDocumentTypes} className="lecturer-upload-input" disabled={isUploading} onChange={handleFileInputChange} ref={fileInputRef} type="file" />
<button className="lecturer-upload-card" data-uploading={isUploading} disabled={isUploading} onClick={handleUploadCardClick} onDragOver={(event) => event.preventDefault()} onDrop={handleUploadCardDrop} type="button" > <span className="lecturer-upload-icon"> {isUploading ? ( <LoaderCircle className="size-7 animate-spin" /> ) : ( <Upload className="size-7" /> )} </span> <span className="lecturer-upload-title"> {isUploading ? 'Mengupload dokumen...' : 'Upload Dokumen Baru'} </span> <span className="lecturer-upload-description"> Drag & drop file PDF, PPT, atau TXT di sini. Maks 100MB per file. Sistem otomatis mengekstrak teks dan membuat embedding. </span> </button>
<section className="lecturer-document-section"> <h2 className="lecturer-document-heading"> <FileText className="size-5" /> <span> Dokumen dalam Knowledge Base ( {documents.length}) </span> </h2>
<div className="lecturer-document-list"> {isLoading && ( <p className="lecturer-detail-empty"> Memuat dokumen... </p> )}
{!isLoading && documents.length === 0 && ( <p className="lecturer-detail-empty"> Belum ada dokumen pada knowledge base ini. </p> )}
{!isLoading && documents.map((document) => ( <DocumentCard document={document} key={document.id} /> ))} </div> </section> </section> </main>
<Dialog onOpenChange={handleEditDialogOpenChange} open={isEditDialogOpen} > <DialogContent className="lecturer-course-dialog"> <DialogHeader> <DialogTitle>Edit Mata Kuliah</DialogTitle> <DialogDescription> Perbarui nama dan deskripsi knowledge base. </DialogDescription> </DialogHeader>
<form className="lecturer-course-form" onSubmit={(event) => { void handleUpdateCourseSubmit(event); }} > <div className="lecturer-form-field"> <Label className="lecturer-form-label" htmlFor="edit-course-title" > Nama Mata Kuliah </Label> <Input className="lecturer-form-input" disabled={isUpdatingCourse} id="edit-course-title" onChange={(event) => setEditForm((current) => ({ ...current, title: event.target.value, })) } placeholder="Masukkan nama mata kuliah" value={editForm.title} /> </div>
<div className="lecturer-form-field"> <Label className="lecturer-form-label" htmlFor="edit-course-description" > Deskripsi </Label> <textarea className="lecturer-form-textarea" disabled={isUpdatingCourse} id="edit-course-description" onChange={(event) => setEditForm((current) => ({ ...current, description: event.target.value, })) } placeholder="Masukkan deskripsi mata kuliah" value={editForm.description} /> </div>
{editCourseMessage && ( <p className="lecturer-status" role="alert"> {editCourseMessage} </p> )}
<DialogFooter className="lecturer-course-footer"> <Button className="lecturer-cancel-button" disabled={isUpdatingCourse} onClick={() => handleEditDialogOpenChange(false) } type="button" variant="outline" > Batal </Button> <Button className="lecturer-create-button" disabled={isUpdatingCourse} type="submit" > {isUpdatingCourse ? 'Menyimpan...' : 'Simpan'} </Button> </DialogFooter> </form> </DialogContent> </Dialog>
<Dialog onOpenChange={handleDeleteDialogOpenChange} open={isDeleteDialogOpen} > <DialogContent className="lecturer-course-dialog"> <DialogHeader> <DialogTitle>Hapus Mata Kuliah</DialogTitle> <DialogDescription> Tindakan ini akan menghapus knowledge base dari backend. </DialogDescription> </DialogHeader>
<div className="lecturer-course-form"> <p className="lecturer-delete-copy"> Mata kuliah{' '} <strong>{course?.title ?? title}</strong> akan dihapus. Pastikan data ini memang sudah tidak dipakai. </p>
{deleteCourseMessage && ( <p className="lecturer-status" role="alert"> {deleteCourseMessage} </p> )}
<DialogFooter className="lecturer-course-footer"> <Button className="lecturer-cancel-button" disabled={isDeletingCourse} onClick={() => handleDeleteDialogOpenChange(false) } type="button" variant="outline" > Batal </Button> <Button className="lecturer-danger-action-button" disabled={isDeletingCourse} onClick={() => { void handleDeleteCourse(); }} type="button" > {isDeletingCourse ? 'Menghapus...' : 'Hapus'} </Button> </DialogFooter> </div> </DialogContent> </Dialog> </DosenShell> </> );}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541import { Head, router } from '@inertiajs/react';import type { LucideIcon } from 'lucide-react';import { AlertTriangle, Database, FileText, Plus, Search } from 'lucide-react';import type { FormEvent } from 'react';import { useCallback, useEffect, useMemo, useState } from 'react';
import AppearanceToggle from '@/components/appearance-toggle';import { DosenShell } from '@/components/dosen/dosen-shell';import { Button } from '@/components/ui/button';import { Card, CardContent } from '@/components/ui/card';import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle,} from '@/components/ui/dialog';import { Input } from '@/components/ui/input';import { Label } from '@/components/ui/label';import { getStoredAuthToken } from '@/lib/auth';import type { CourseResponse, DocumentResponse } from '@/lib/rag';import { getRagErrorMessage, ragApi } from '@/lib/rag';import { show as showDosenCourse } from '@/routes/dosen';
type KnowledgeBaseRow = { id: string; name: string; documentCount: number; failedDocumentCount: number; hasError?: boolean; updatedAt: string;};
type Metric = { label: string; value: string; description?: string; icon: LucideIcon; tone: 'primary' | 'danger';};
type CourseForm = { title: string; description: string;};
const emptyCourseForm: CourseForm = { description: '', title: '',};
function isAbortError(error: unknown): boolean { return error instanceof DOMException && error.name === 'AbortError';}
function formatUpdatedAt(value?: string): string { if (!value) { return '-'; }
const datePart = value.split('T')[0];
return datePart || value;}
function getLatestUpdatedAt(documents: DocumentResponse[]): string | undefined { return documents .map((document) => document.updated_at) .filter(Boolean) .sort() .at(-1);}
function buildKnowledgeBaseRow( course: CourseResponse, documents: DocumentResponse[],): KnowledgeBaseRow { const failedDocumentCount = documents.filter( (document) => document.status === 'failed' || Boolean(document.error), ).length;
return { documentCount: documents.length, failedDocumentCount, hasError: failedDocumentCount > 0, id: String(course.id), name: course.title, updatedAt: formatUpdatedAt(getLatestUpdatedAt(documents)), };}
function MetricCard({ metric }: { metric: Metric }) { const Icon = metric.icon;
return ( <Card className="lecturer-metric-card"> <CardContent className="lecturer-metric-content"> <span className="lecturer-metric-icon" data-tone={metric.tone}> <Icon className="size-6" /> </span>
<div className="lecturer-metric-copy"> <p>{metric.label}</p> <div className="lecturer-metric-value-row"> <strong>{metric.value}</strong> {metric.description && ( <span>{metric.description}</span> )} </div> </div> </CardContent> </Card> );}
export default function Dosen() { const [backendMessage, setBackendMessage] = useState<string>(); const [courseForm, setCourseForm] = useState<CourseForm>(emptyCourseForm); const [createCourseMessage, setCreateCourseMessage] = useState<string>(); const [isCourseDialogOpen, setIsCourseDialogOpen] = useState(false); const [isCreatingCourse, setIsCreatingCourse] = useState(false); const [isLoading, setIsLoading] = useState(true); const [knowledgeBases, setKnowledgeBases] = useState<KnowledgeBaseRow[]>( [], ); const [searchQuery, setSearchQuery] = useState('');
const loadKnowledgeBases = useCallback(async (signal?: AbortSignal) => { setIsLoading(true); setBackendMessage(undefined);
try { const token = getStoredAuthToken() ?? undefined; const coursesResponse = await ragApi.listCourses({ limit: 100, signal, });
if (signal?.aborted) { return; }
const documentResults = await Promise.allSettled( coursesResponse.data.map((course) => ragApi.listCourseDocuments(String(course.id), { signal, token, }), ), );
if (signal?.aborted) { return; }
let documentErrorMessage: string | undefined;
const rows = coursesResponse.data.map((course, index) => { const documentResult = documentResults[index];
if (documentResult?.status === 'fulfilled') { return buildKnowledgeBaseRow( course, documentResult.value.data, ); }
if (documentResult && !isAbortError(documentResult.reason)) { documentErrorMessage ??= getRagErrorMessage( documentResult.reason, ); }
return buildKnowledgeBaseRow(course, []); });
setKnowledgeBases(rows); setBackendMessage(documentErrorMessage); } catch (error) { if (!isAbortError(error)) { setKnowledgeBases([]); setBackendMessage(getRagErrorMessage(error)); } } finally { if (!signal?.aborted) { setIsLoading(false); } } }, []);
useEffect(() => { const controller = new AbortController();
void Promise.resolve().then(() => loadKnowledgeBases(controller.signal), );
return () => { controller.abort(); }; }, [loadKnowledgeBases]);
function handleCourseDialogOpenChange(open: boolean): void { setIsCourseDialogOpen(open);
if (!open) { setCourseForm(emptyCourseForm); setCreateCourseMessage(undefined); } }
async function handleCreateCourseSubmit( event: FormEvent<HTMLFormElement>, ): Promise<void> { event.preventDefault(); setCreateCourseMessage(undefined); setIsCreatingCourse(true);
try { const token = getStoredAuthToken() ?? undefined;
await ragApi.createCourse( { description: courseForm.description || undefined, title: courseForm.title, }, token, );
handleCourseDialogOpenChange(false); await loadKnowledgeBases(); } catch (error) { setCreateCourseMessage(getRagErrorMessage(error)); } finally { setIsCreatingCourse(false); } }
const metrics = useMemo<Metric[]>(() => { const failedDocumentCount = knowledgeBases.reduce( (total, item) => total + item.failedDocumentCount, 0, ); const documentCount = knowledgeBases.reduce( (total, item) => total + item.documentCount, 0, );
return [ { icon: Database, label: 'Total Knowledge Base', tone: 'primary', value: isLoading ? '...' : String(knowledgeBases.length), }, { icon: FileText, label: 'Total Dokumen', description: 'Chunked', tone: 'primary', value: isLoading ? '...' : String(documentCount), }, { icon: AlertTriangle, label: 'Processing Error', description: 'dokumen', tone: 'danger', value: isLoading ? '...' : String(failedDocumentCount), }, ]; }, [isLoading, knowledgeBases]);
const filteredKnowledgeBases = useMemo(() => { const normalizedQuery = searchQuery.trim().toLowerCase();
if (!normalizedQuery) { return knowledgeBases; }
return knowledgeBases.filter((item) => item.name.toLowerCase().includes(normalizedQuery), ); }, [knowledgeBases, searchQuery]);
return ( <> <Head title="Dashboard Knowledge Base" />
<DosenShell> <main className="lecturer-page"> <section className="lecturer-page-header"> <div> <h1>Dashboard Knowledge Base</h1> <p> Kelola sumber dokumen RAG untuk berbagai mata kuliah Anda. </p> </div>
<div className="lecturer-header-actions"> <AppearanceToggle className="lecturer-theme-toggle" /> <Button className="lecturer-create-button" onClick={() => handleCourseDialogOpenChange(true) } > <Plus className="size-4" /> Buat KB Baru </Button> </div> </section>
<section className="lecturer-metric-grid"> {metrics.map((metric) => ( <MetricCard key={metric.label} metric={metric} /> ))} </section>
<Card className="lecturer-table-card"> <CardContent className="lecturer-table-content"> <div className="lecturer-table-heading"> <h2>Daftar Mata Kuliah / Topik</h2> <div className="lecturer-search-field"> <Search aria-hidden className="size-4" /> <Input aria-label="Cari mata kuliah" className="lecturer-search-input" onChange={(event) => setSearchQuery(event.target.value) } placeholder="Cari mata kuliah..." type="search" value={searchQuery} /> </div> </div>
{backendMessage && ( <p className="lecturer-status" role="alert"> {backendMessage} </p> )}
<div className="lecturer-table-wrap"> <table className="lecturer-table"> <thead> <tr> <th>Nama Knowledge Base</th> <th>Dokumen</th> <th>Update Terakhir</th> <th>Aksi</th> </tr> </thead> <tbody> {isLoading && ( <tr> <td className="lecturer-table-empty" colSpan={4} > Memuat knowledge base... </td> </tr> )}
{!isLoading && knowledgeBases.length === 0 && ( <tr> <td className="lecturer-table-empty" colSpan={4} > Belum ada knowledge base. </td> </tr> )}
{!isLoading && knowledgeBases.length > 0 && filteredKnowledgeBases.length === 0 && ( <tr> <td className="lecturer-table-empty" colSpan={4} > Mata kuliah tidak ditemukan. </td> </tr> )}
{!isLoading && filteredKnowledgeBases.map( (item) => ( <tr key={item.id}> <td> <span className="lecturer-kb-name"> {item.name} </span> </td> <td> <span className="lecturer-doc-pill"> <FileText className="size-3.5" /> { item.documentCount } {item.hasError && ( <span className="lecturer-doc-error" /> )} </span> </td> <td> {item.updatedAt} </td> <td> <button className="lecturer-manage-button" onClick={() => router.visit( showDosenCourse( item.id, ), ) } type="button" > Kelola </button> </td> </tr> ), )} </tbody> </table> </div> </CardContent> </Card> </main>
<Dialog onOpenChange={handleCourseDialogOpenChange} open={isCourseDialogOpen} > <DialogContent className="lecturer-course-dialog"> <DialogHeader> <DialogTitle>Tambah Mata Kuliah</DialogTitle> <DialogDescription> Buat knowledge base baru untuk dokumen RAG mata kuliah. </DialogDescription> </DialogHeader>
<form className="lecturer-course-form" onSubmit={(event) => { void handleCreateCourseSubmit(event); }} > <div className="lecturer-form-field"> <Label className="lecturer-form-label" htmlFor="course-title" > Nama Mata Kuliah </Label> <Input className="lecturer-form-input" disabled={isCreatingCourse} id="course-title" onChange={(event) => setCourseForm((current) => ({ ...current, title: event.target.value, })) } placeholder="Masukkan nama mata kuliah" value={courseForm.title} /> </div>
<div className="lecturer-form-field"> <Label className="lecturer-form-label" htmlFor="course-description" > Deskripsi </Label> <textarea className="lecturer-form-textarea" disabled={isCreatingCourse} id="course-description" onChange={(event) => setCourseForm((current) => ({ ...current, description: event.target.value, })) } placeholder="Masukkan deskripsi mata kuliah" value={courseForm.description} /> </div>
{createCourseMessage && ( <p className="lecturer-status" role="alert"> {createCourseMessage} </p> )}
<DialogFooter className="lecturer-course-footer"> <Button className="lecturer-cancel-button" disabled={isCreatingCourse} onClick={() => handleCourseDialogOpenChange(false) } type="button" variant="outline" > Batal </Button> <Button className="lecturer-create-button" disabled={isCreatingCourse} type="submit" > {isCreatingCourse ? 'Menyimpan...' : 'Simpan'} </Button> </DialogFooter> </form> </DialogContent> </Dialog> </DosenShell> </> );}12345678910111213141516171819202122import { Head } from '@inertiajs/react';
import { DosenShell } from '@/components/dosen/dosen-shell';
export default function PengaturanDosen() { return ( <> <Head title="Pengaturan" />
<DosenShell activeMenu="settings"> <main className="lecturer-page"> <section className="lecturer-page-header"> <div> <h1>Pengaturan</h1> <p>Halaman ini masih kosong.</p> </div> </section> </main> </DosenShell> </> );}3 unmodified lines45678910 unmodified lines2021222324252668 unmodified lines959697989910010110210310410510610710810911019 unmodified lines13013113213313413513613713813914014114214314414514614714814915015144 unmodified lines1961971981992002012026 unmodified lines2092102112122132142152162178 unmodified lines22622722822923023123223366 unmodified lines3003013023033043053063073084 unmodified lines31331431531631731831912 unmodified lines3323333343353363373386 unmodified lines3453463473483493503513 unmodified linesimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';import { QuestionComposer } from '@/components/student/question-composer';import {formatSessionTime,isAbortError,10 unmodified linesimport {appendDirectChatMessages,clearDirectChatMessages,createLocalUserMessage,getRagErrorMessage,getStoredDirectChatMessages,isDirectChatMode,68 unmodified lines);}export default function MahasiswaChat({ sessionId }: MahasiswaChatProps) {const [backendMessage, setBackendMessage] = useState<string>();const [chatSessions, setChatSessions] = useState<ChatSessionResponse[]>([]);const [courses, setCourses] = useState<CourseResponse[]>([]);const [currentSession, setCurrentSession] = useState<ChatSessionResponse>();const [isLoading, setIsLoading] = useState(true);const [isProcessing, setIsProcessing] = useState(false);const [messages, setMessages] = useState<ChatMessageResponse[]>([]);const [question, setQuestion] = useState('');const [selectedCourseId, setSelectedCourseId] = useState('');const studentName = useStoredStudentName();const messagesEndRef = useRef<HTMLDivElement>(null);19 unmodified linesmessagesEndRef.current?.scrollIntoView({ block: 'end' });}, [messages, isProcessing]);const applyHistoryResponse = useCallback((response: ChatHistoryResponse): void => {if (isDirectChatMode()) {setMessages([...response.data,...getStoredDirectChatMessages(sessionId),]);return;}setMessages(response.data);},[sessionId],);useEffect(() => {const controller = new AbortController();44 unmodified lines}if (historyResult.status === 'fulfilled') {applyHistoryResponse(historyResult.value);} else if (!isAbortError(historyResult.reason)) {setBackendMessage(getRagErrorMessage(historyResult.reason));}6 unmodified linesreturn () => {controller.abort();};}, [applyHistoryResponse, sessionId]);const handleDeleteSession = async (targetSessionId: string) => {try {const token = getStoredAuthToken() ?? undefined;await ragApi.deleteChatSession(targetSessionId, token);8 unmodified linesif (targetSessionId === sessionId) {router.visit(mahasiswa());}} catch (error) {setBackendMessage(getRagErrorMessage(error));}};66 unmodified linesactiveSessionId={sessionId}chatSessions={chatSessions}isLoadingSessions={isLoading}onDeleteSession={(targetSessionId) => {void handleDeleteSession(targetSessionId);}}studentName={studentName}><div className="student-chat-stage student-chat-stage--session">4 unmodified lines</p>)}{isLoading ? (<p className="student-chat-loading">Memuat percakapan...</p>12 unmodified lines<Bot className="size-4" /></span><div className="student-message-bubble student-message-bubble--typing">Menyiapkan jawaban...</div></article>)}6 unmodified lines<div className="student-chat-composer"><QuestionComposercourses={composerCourses}isCourseLockedisLoadingCourses={isLoading}isProcessing={isProcessing}onCourseChange={setSelectedCourseId}3 unmodified lines4567891010 unmodified lines21222324252627282968 unmodified lines989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713819 unmodified lines15815916016116216316416516616716816917017117217317417517617717817918018118218318444 unmodified lines2292302312322332342352362372382392402412422432446 unmodified lines2512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473488 unmodified lines35735835936036136236336436536636736836966 unmodified lines4364374384394404414424 unmodified lines44744844945045145245312 unmodified lines4664674684694704714726 unmodified lines4794804814824834843 unmodified linesimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';import { QuestionComposer } from '@/components/student/question-composer';import type { DeleteSessionResult } from '@/components/student/student-shell';import {formatSessionTime,isAbortError,10 unmodified linesimport {appendDirectChatMessages,clearDirectChatMessages,clearPendingInitialChat,createLocalUserMessage,getPendingInitialChat,getRagErrorMessage,getStoredDirectChatMessages,isDirectChatMode,68 unmodified lines);}function appendUniqueMessages(currentMessages: ChatMessageResponse[],nextMessages: ChatMessageResponse[],): ChatMessageResponse[] {const existingIds = new Set(currentMessages.map((message) => message.uuid_id),);return [...currentMessages,...nextMessages.filter((message) => !existingIds.has(message.uuid_id)),];}export default function MahasiswaChat({ sessionId }: MahasiswaChatProps) {const [initialPendingChat] = useState(() =>getPendingInitialChat(sessionId),);const pendingInitialChatRef = useRef(initialPendingChat);const hasStartedPendingInitialChatRef = useRef(false);const [backendMessage, setBackendMessage] = useState<string>();const [chatSessions, setChatSessions] = useState<ChatSessionResponse[]>([]);const [courses, setCourses] = useState<CourseResponse[]>([]);const [currentSession, setCurrentSession] = useState<ChatSessionResponse>();const [isLoading, setIsLoading] = useState(true);const [isProcessing, setIsProcessing] = useState(Boolean(initialPendingChat),);const [messages, setMessages] = useState<ChatMessageResponse[]>(() =>initialPendingChat ? [initialPendingChat.userMessage] : [],);const [question, setQuestion] = useState('');const [selectedCourseId, setSelectedCourseId] = useState(initialPendingChat?.courseId ?? '',);const studentName = useStoredStudentName();const messagesEndRef = useRef<HTMLDivElement>(null);19 unmodified linesmessagesEndRef.current?.scrollIntoView({ block: 'end' });}, [messages, isProcessing]);const getHistoryMessages = useCallback((response: ChatHistoryResponse): ChatMessageResponse[] => {if (isDirectChatMode()) {return [...response.data,...getStoredDirectChatMessages(sessionId),];}return response.data;},[sessionId],);const applyHistoryResponse = useCallback((response: ChatHistoryResponse): void => {setMessages(getHistoryMessages(response));},[getHistoryMessages],);useEffect(() => {const controller = new AbortController();44 unmodified lines}if (historyResult.status === 'fulfilled') {const historyMessages = getHistoryMessages(historyResult.value);const pendingInitialChat = pendingInitialChatRef.current;setMessages(pendingInitialChat? appendUniqueMessages(historyMessages, [pendingInitialChat.userMessage,]): historyMessages,);} else if (!isAbortError(historyResult.reason)) {setBackendMessage(getRagErrorMessage(historyResult.reason));}6 unmodified linesreturn () => {controller.abort();};}, [getHistoryMessages, sessionId]);useEffect(() => {const pendingInitialChat = pendingInitialChatRef.current;if (!pendingInitialChat || hasStartedPendingInitialChatRef.current) {return;}const activePendingInitialChat = pendingInitialChat;let isCancelled = false;hasStartedPendingInitialChatRef.current = true;setIsProcessing(true);setQuestion('');setSelectedCourseId(activePendingInitialChat.courseId);setMessages((currentMessages) =>appendUniqueMessages(currentMessages, [activePendingInitialChat.userMessage,]),);async function sendPendingInitialChat(): Promise<void> {try {const token = getStoredAuthToken() ?? undefined;const assistantMessage = await ragApi.sendConfiguredChatMessage({content: activePendingInitialChat.content,courseId: activePendingInitialChat.courseId,sessionId,token,},);if (isCancelled) {return;}clearPendingInitialChat(sessionId);pendingInitialChatRef.current = undefined;if (isDirectChatMode()) {appendDirectChatMessages(sessionId, [activePendingInitialChat.userMessage,assistantMessage,]);setMessages((currentMessages) =>appendUniqueMessages(currentMessages, [assistantMessage,]),);return;}const history = await ragApi.getChatHistory(sessionId, {token,});if (!isCancelled) {applyHistoryResponse(history);}} catch (error) {if (!isCancelled) {clearPendingInitialChat(sessionId);pendingInitialChatRef.current = undefined;setMessages((currentMessages) =>currentMessages.filter((message) =>message.uuid_id !==activePendingInitialChat.userMessage.uuid_id,),);setQuestion(activePendingInitialChat.content);setBackendMessage(getRagErrorMessage(error));}} finally {if (!isCancelled) {setIsProcessing(false);}}}void sendPendingInitialChat();return () => {isCancelled = true;};}, [applyHistoryResponse, sessionId]);const handleDeleteSession = async (targetSessionId: string,): Promise<DeleteSessionResult> => {try {const token = getStoredAuthToken() ?? undefined;await ragApi.deleteChatSession(targetSessionId, token);8 unmodified linesif (targetSessionId === sessionId) {router.visit(mahasiswa());}return { ok: true };} catch (error) {const message = getRagErrorMessage(error);setBackendMessage(message);return { message, ok: false };}};66 unmodified linesactiveSessionId={sessionId}chatSessions={chatSessions}isLoadingSessions={isLoading}onDeleteSession={handleDeleteSession}studentName={studentName}><div className="student-chat-stage student-chat-stage--session">4 unmodified lines</p>)}{isLoading && messages.length === 0 && !isProcessing ? (<p className="student-chat-loading">Memuat percakapan...</p>12 unmodified lines<Bot className="size-4" /></span><div className="student-message-bubble student-message-bubble--typing">Thinking...</div></article>)}6 unmodified lines<div className="student-chat-composer"><QuestionComposercourses={composerCourses}isLoadingCourses={isLoading}isProcessing={isProcessing}onCourseChange={setSelectedCourseId}
3 unmodified lines4567892 unmodified lines121314151617181920212252 unmodified lines75767778798019 unmodified lines1001011021031041051061071081091101111121131141151161171181199 unmodified lines1291301311321331343 unmodified linesimport { useEffect, useState } from 'react';import { QuestionComposer } from '@/components/student/question-composer';import {isAbortError,StudentShell,2 unmodified linesimport { getStoredAuthToken } from '@/lib/auth';import type { ChatSessionResponse, CourseResponse } from '@/lib/rag';import {appendDirectChatMessages,createLocalUserMessage,getRagErrorMessage,isDirectChatMode,ragApi,} from '@/lib/rag';import { show as showMahasiswaSession } from '@/routes/mahasiswa';52 unmodified lines};}, []);const handleQuestionSubmit = async (event: FormEvent<HTMLFormElement>,): Promise<void> => {19 unmodified lines);const userMessage = createLocalUserMessage(trimmedQuestion);const assistantMessage = await ragApi.sendConfiguredChatMessage({content: trimmedQuestion,courseId: selectedCourseId,sessionId: session.uuid_id,token,});if (isDirectChatMode()) {appendDirectChatMessages(session.uuid_id, [userMessage,assistantMessage,]);}router.visit(showMahasiswaSession(session.uuid_id));} catch (error) {setBackendMessage(getRagErrorMessage(error));9 unmodified lines<StudentShellchatSessions={chatSessions}isLoadingSessions={isLoading}studentName={studentName}><div className="student-chat-stage">3 unmodified lines456789102 unmodified lines131415161718192021222352 unmodified lines76777879808182838485868788899091929394959697989910010110210310419 unmodified lines1241251261271281291301311321331341359 unmodified lines1451461471481491501513 unmodified linesimport { useEffect, useState } from 'react';import { QuestionComposer } from '@/components/student/question-composer';import type { DeleteSessionResult } from '@/components/student/student-shell';import {isAbortError,StudentShell,2 unmodified linesimport { getStoredAuthToken } from '@/lib/auth';import type { ChatSessionResponse, CourseResponse } from '@/lib/rag';import {clearDirectChatMessages,createLocalUserMessage,getRagErrorMessage,ragApi,savePendingInitialChat,} from '@/lib/rag';import { show as showMahasiswaSession } from '@/routes/mahasiswa';52 unmodified lines};}, []);const handleDeleteSession = async (targetSessionId: string,): Promise<DeleteSessionResult> => {try {const token = getStoredAuthToken() ?? undefined;await ragApi.deleteChatSession(targetSessionId, token);clearDirectChatMessages(targetSessionId);setChatSessions((currentSessions) =>currentSessions.filter((session) => session.uuid_id !== targetSessionId,),);return { ok: true };} catch (error) {const message = getRagErrorMessage(error);setBackendMessage(message);return { message, ok: false };}};const handleQuestionSubmit = async (event: FormEvent<HTMLFormElement>,): Promise<void> => {19 unmodified lines);const userMessage = createLocalUserMessage(trimmedQuestion);savePendingInitialChat(session.uuid_id, {content: trimmedQuestion,courseId: selectedCourseId,userMessage,});router.visit(showMahasiswaSession(session.uuid_id));} catch (error) {setBackendMessage(getRagErrorMessage(error));9 unmodified lines<StudentShellchatSessions={chatSessions}isLoadingSessions={isLoading}onDeleteSession={handleDeleteSession}studentName={studentName}><div className="student-chat-stage">
19 unmodified lines2021222319 unmodified lines'sessionId' => $uuid,]))->name('mahasiswa.show');require __DIR__.'/settings.php';19 unmodified lines20212223242526272829303119 unmodified lines'sessionId' => $uuid,]))->name('mahasiswa.show');Route::inertia('dosen', 'dosen')->name('dosen');Route::inertia('dosen/pengaturan', 'dosen/pengaturan')->name('dosen.pengaturan');Route::get('dosen/{courseId}', fn (string $courseId) => Inertia::render('dosen-detail', ['courseId' => $courseId,]))->name('dosen.show');require __DIR__.'/settings.php';
1234567891011121314151617181920212223<?php
use Inertia\Testing\AssertableInertia as Assert;
test('dosen dashboard page can be rendered', function () { $this->get(route('dosen')) ->assertOk() ->assertInertia(fn (Assert $page) => $page->component('dosen'));});
test('dosen settings page can be rendered', function () { $this->get(route('dosen.pengaturan')) ->assertOk() ->assertInertia(fn (Assert $page) => $page->component('dosen/pengaturan'));});
test('dosen course detail page can be rendered', function () { $this->get(route('dosen.show', ['courseId' => '101'])) ->assertOk() ->assertInertia(fn (Assert $page) => $page ->component('dosen-detail') ->where('courseId', '101'));});resources/css/app.css+959-22
resources/js/components/auth/register-role-form.tsx+200-7
resources/js/components/dosen/dosen-shell.tsxAdded+200
resources/js/components/student/question-composer.tsx+27-13
resources/js/components/student/student-shell.tsx+276-160
resources/js/lib/rag.ts+148
resources/js/pages/auth/login.tsx+14-4
resources/js/pages/dosen-detail.tsxAdded+618
resources/js/pages/dosen.tsxAdded+541
resources/js/pages/dosen/pengaturan.tsxAdded+22
resources/js/pages/mahasiswa-chat.tsx+152-19
resources/js/pages/mahasiswa.tsx+29-12
routes/web.php+8
tests/Feature/DosenDashboardTest.phpAdded+23