lms/public/build/assets/assignment-submission-CzDof3An.js
2025-12-15 12:26:23 +01:00

2 lines
7.7 KiB
JavaScript

import{r as G,b as H,j as e,C as I,F as v,k as _,l as n,U as X,m as E,n as O}from"./vendor-BKmmeuxg.js";import{I as w}from"./input-error-LaPr_4wd.js";import{L as Y}from"./loading-button-BnTVAMJ7.js";import{A as C,a as k,b as S}from"./alert-D9uBQ7fu.js";import{B as D}from"./button-BpNwv2aE.js";import{C as o,a as x,c as h,d as u,b as p}from"./card-D9_SJYq6.js";import{L as A}from"./label-HmIcv5Yx.js";import{S as z}from"./separator-_3LZ_wAA.js";import{k as R}from"./richtor-CRcM6Du2.js";import"./utils-DxSsnXxD.js";import"./index-WW_1X1qx.js";const te=({assignment:s,submissions:r=[]})=>{const[j,d]=G.useState(null),a=r.length>0?r[0]:null,{data:i,setData:c,post:L,reset:f,errors:g,processing:F}=H({course_assignment_id:s.id,submission_text:"",attachment:null}),T=t=>{var y;const l=((y=t.target.files)==null?void 0:y[0])||null;d(l),c("attachment",l)},P=t=>{t.preventDefault(),L("/dashboard/assignment/submission",{onSuccess:()=>{f(),d(null)}})},N=s.deadline?new Date(s.deadline)<new Date:!1,M=s.late_deadline?new Date(s.late_deadline)<new Date:!1,B=!N||s.late_submission&&!M,m=s.retake-r.length,b=t=>{switch(t){case"graded":return e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-green-100 px-2 py-1 text-xs font-medium text-green-700",children:[e.jsx(O,{className:"h-3 w-3"}),"Graded"]});case"pending":return e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-yellow-100 px-2 py-1 text-xs font-medium text-yellow-700",children:[e.jsx(_,{className:"h-3 w-3"}),"Pending"]});case"late":return e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-orange-100 px-2 py-1 text-xs font-medium text-orange-700",children:[e.jsx(n,{className:"h-3 w-3"}),"Late Submission"]});default:return e.jsx("span",{className:"inline-flex items-center gap-1 rounded-full bg-gray-100 px-2 py-1 text-xs font-medium text-gray-700",children:t})}};return e.jsxs("div",{className:"mx-auto max-w-4xl space-y-6 p-6",children:[e.jsxs(o,{children:[e.jsxs(x,{children:[e.jsx(h,{children:s.title}),e.jsx(u,{children:s.summary&&e.jsx("div",{className:"prose prose-sm mt-2 max-w-none",dangerouslySetInnerHTML:{__html:s.summary}})})]}),e.jsx(p,{children:e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{className:"text-muted-foreground h-4 w-4"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Deadline"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s.deadline?new Date(s.deadline).toLocaleString():"No deadline"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"text-muted-foreground h-4 w-4"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Total Marks"}),e.jsxs("p",{className:"text-muted-foreground text-sm",children:[s.total_mark," (Pass: ",s.pass_mark,")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{className:"text-muted-foreground h-4 w-4"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Attempts"}),e.jsxs("p",{className:"text-muted-foreground text-sm",children:[r.length," / ",s.retake]})]})]}),s.late_submission&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(n,{className:"text-muted-foreground h-4 w-4"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Late Deadline"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s.late_deadline?new Date(s.late_deadline).toLocaleString():"N/A"})]})]})]})})]}),a&&e.jsxs(C,{children:[e.jsx(n,{className:"h-4 w-4"}),e.jsx(k,{children:"Latest Submission"}),e.jsx(S,{children:e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{children:["Status: ",b(a.status)]}),e.jsxs("span",{className:"text-muted-foreground text-sm",children:["Attempt ",a.attempt_number," of ",s.retake]})]}),a.marks_obtained!==null&&e.jsxs("p",{className:"text-sm",children:[e.jsx("strong",{children:"Grade:"})," ",a.marks_obtained," / ",s.total_mark]}),a.instructor_feedback&&e.jsxs("div",{className:"bg-muted rounded-md p-3",children:[e.jsx("p",{className:"text-sm font-medium",children:"Instructor Feedback:"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:a.instructor_feedback})]})]})})]}),B&&m>0?e.jsxs(o,{children:[e.jsxs(x,{children:[e.jsx(h,{children:"Submit Assignment"}),e.jsx(u,{children:N&&s.late_submission?`Late submission allowed until ${new Date(s.late_deadline).toLocaleString()}`:`You have ${m} attempt(s) remaining`})]}),e.jsx(p,{children:e.jsxs("form",{onSubmit:P,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(A,{htmlFor:"submission_text",children:"Your Answer"}),e.jsx(R,{ssr:!0,output:"html",placeholder:{paragraph:"Type your assignment answer here...",imageCaption:"Add caption (optional)"},contentMinHeight:200,contentMaxHeight:500,initialContent:i.submission_text,onContentChange:t=>c(l=>({...l,submission_text:t}))}),e.jsx(w,{message:g.submission_text})]}),e.jsxs("div",{children:[e.jsx(A,{htmlFor:"attachment",children:"Attach File (Optional)"}),e.jsxs("div",{className:"mt-2",children:[e.jsxs("label",{htmlFor:"attachment",className:"flex cursor-pointer items-center justify-center rounded-lg border-2 border-dashed border-gray-300 bg-gray-50 px-6 py-8 hover:border-gray-400 hover:bg-gray-100",children:[e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx(X,{className:"mx-auto h-12 w-12 text-gray-400"}),e.jsxs("div",{className:"text-sm text-gray-600",children:[e.jsx("span",{className:"font-semibold",children:"Click to upload"})," or drag and drop"]}),e.jsx("p",{className:"text-xs text-gray-500",children:"PDF, DOC, DOCX, TXT, ZIP, JPG, PNG (MAX 10MB)"})]}),e.jsx("input",{id:"attachment",type:"file",className:"hidden",onChange:T,accept:".pdf,.doc,.docx,.txt,.zip,.jpg,.jpeg,.png"})]}),j&&e.jsxs("div",{className:"bg-muted mt-2 flex items-center justify-between rounded-md p-3",children:[e.jsx("span",{className:"text-sm",children:j.name}),e.jsx(D,{type:"button",variant:"ghost",size:"sm",onClick:()=>{d(null),c("attachment",null)},children:e.jsx(E,{className:"h-4 w-4"})})]})]}),e.jsx(w,{message:g.attachment})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>f(),children:"Reset"}),e.jsx(Y,{loading:F,disabled:!i.submission_text&&!i.attachment,children:"Submit Assignment"})]})]})})]}):e.jsxs(C,{variant:"destructive",children:[e.jsx(n,{className:"h-4 w-4"}),e.jsx(k,{children:"Cannot Submit"}),e.jsx(S,{children:m<=0?"You have used all your attempts for this assignment.":"The deadline for this assignment has passed."})]}),r.length>0&&e.jsxs(o,{children:[e.jsxs(x,{children:[e.jsx(h,{children:"Submission History"}),e.jsx(u,{children:"View all your previous submissions"})]}),e.jsx(p,{children:e.jsx("div",{className:"space-y-4",children:r.map((t,l)=>e.jsxs("div",{children:[l>0&&e.jsx(z,{className:"my-4"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium",children:["Attempt ",t.attempt_number]}),e.jsxs("p",{className:"text-muted-foreground text-sm",children:["Submitted: ",t.submitted_at?new Date(t.submitted_at).toLocaleString():"N/A"]})]}),b(t.status)]}),t.attachment_name&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(v,{className:"h-4 w-4"}),e.jsx("span",{children:t.attachment_name})]}),t.marks_obtained!==null&&e.jsxs("div",{className:"bg-muted rounded-md p-3",children:[e.jsxs("p",{className:"text-sm font-medium",children:["Grade: ",t.marks_obtained," / ",s.total_mark]}),t.instructor_feedback&&e.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:t.instructor_feedback})]})]})]},t.id))})})]})]})};export{te as default};