"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3954],{92559:function(e,t,i){i.r(t),i.d(t,{ApplicationBuilder:function(){return q}});var s=i(91674),n=i(9316),a=i(71586),l=i(26027),o=i(22267),r=i(13813),c=i(71095),d=i(60066),u=i(65735),p=i(2063),h=i(68007),m=i(14306),x=i(13110),g=i(7644),v=i(42751),j=i(29296),f=i(60041),y=i(54603),b=i(86655),N=i(89650),w=i(37398),A=i(72816),C=i(66533);let I=w.Ry().shape({publish:w.O7().default(!1),isPublic:w.O7().default(!0),isPrivate:w.O7().default(!1),title:w.Z_().required("Please enter the title of the application"),isFinancialAidApplication:w.O7().default(!1),description:w.Z_().required("Please enter a description for this application."),type:w.Z_().oneOf(["RADIO","INPUT","DATE","CHECKBOX"],"Invalid field type").required("Field type is required"),question:w.Z_().required("Please enter the question"),options:w.IX().of(w.Ry().shape({value:w.Z_().required("Please enter an option.")})).when("type",{is:e=>"RADIO"===e||"CHECKBOX"===e,then:e=>e.min(1,"At least one option is required."),otherwise:e=>e.notRequired()}).default(void 0),required:w.O7().default(!0),id:w.Z_()}),S={RADIO:{title:"Radio group",description:"Add options to choose from. Only one option can be chosen.",type:"RADIO"},INPUT:{title:"Text input",description:"Allow your students to enter text.",type:"INPUT"},DATE:{title:"Date input",description:"Make your students input a date.",type:"DATE"},CHECKBOX:{title:"Multiple selections",description:"Add options to choose from. Multiple choices can be selected.",type:"CHECKBOX"},FILE:{title:"File upload",description:"Add a single file upload.",type:"FILE"}};function q(){var e,t,i;let w=(0,y.usePathname)().split("/");w.pop(),w.pop();let q=w.join("/"),[k,T]=(0,b.useState)(),[R,P]=(0,b.useState)(!1),[B,D]=(0,b.useState)(!1),O=(0,y.useRouter)(),F=(0,y.useParams)(),{data:E,refetch:M,isLoading:V}=r.trpc.application.getApplicationById.useQuery({id:F.applicationId,include:{fields:{orderBy:{createdAt:"asc"}}}}),{mutateAsync:Q}=r.trpc.application.getApplicationDataForExport.useMutation(),{mutateAsync:Z}=r.trpc.site.getBySchoolId.useMutation(),{register:K,control:X,getValues:_,setValue:G,trigger:H,reset:L,watch:U,formState:{errors:z}}=(0,A.cI)({resolver:(0,N.X)(I)}),{mutate:W}=r.trpc.application.deleteApplication.useMutation({onSuccess(){c.A.success("Successfully deleted the application."),O.push(q)}}),{mutate:Y}=r.trpc.application.deleteField.useMutation({onSuccess(){c.A.success("Successfully deleted question!"),M()}}),{mutate:J}=r.trpc.application.addFieldToApplication.useMutation({onSuccess(e,t,i){c.A.success("Successfully saved application!"),M(),L(),T(void 0)}}),{mutate:$}=r.trpc.application.saveApplication.useMutation({onSuccess(){c.A.success("Successfully saved application!")}});(0,b.useEffect)(()=>{E&&(G("title",E.title),G("description",E.description||""),G("isFinancialAidApplication",E.isFinancialAid),G("publish",E.isPublic),G("isPrivate",E.isPrivate),G("isPublic",!E.isPrivate))},[E,G]);let{fields:ee,append:et,remove:ei,update:es}=(0,A.Dq)({control:X,name:"options"}),en=async e=>{await L(),T(e),G("type",e),("CHECKBOX"===e||"RADIO"===e)&&G("options",[{value:""}]),P(!1)},ea=()=>{let e=_();c.A.loading("Adding question to application...");let t="RADIO"===e.type||"CHECKBOX"===e.type?null==e?void 0:e.options.map(e=>null==e?void 0:e.value):void 0;J({id:e.id,title:e.title,description:e.description,applicationId:F.applicationId,field:{question:e.question,options:t,type:e.type,required:!!U("required")&&U("required")}})},el=async()=>{await H("title")&&await H("description")?$({id:F.applicationId,title:_("title"),isFinancialAid:_("isFinancialAidApplication"),description:_("description"),isPublic:_("publish"),isPrivate:_("isPrivate")}):c.A.error("Please fill out the necessary fields.")},eo=async()=>{let e=await Q({id:F.applicationId});e.StudentApplication,e.fields};return V?(0,s.jsxs)("div",{children:[(0,s.jsxs)(d.Button,{plain:!0,href:q,className:"hover:bg-gray-200 mb-5",children:[(0,s.jsx)(n.Z,{className:"w-4 h-4"}),"Back"]}),(0,s.jsxs)("div",{className:"flex justify-between sm:flex-row flex-col space-y-5 sm:space-y-0 mb-5",children:[(0,s.jsx)(u.Text,{variant:"h4",font:"poppins",className:"font-semibold",children:"School application"}),(0,s.jsx)(p.Q,{height:"h-10",width:"w-32"})]}),(0,s.jsxs)("div",{className:"space-y-5",children:[(0,s.jsx)(p.Q,{height:"h-64"}),(0,s.jsx)(p.Q,{height:"h-64"}),(0,s.jsx)(p.Q,{height:"h-64"}),(0,s.jsx)(p.Q,{height:"h-64"}),(0,s.jsx)(p.Q,{height:"h-64"}),(0,s.jsx)(p.Q,{height:"h-64"})]})]}):(0,s.jsxs)("div",{className:"space-y-5",children:[(0,s.jsx)(h.DeleteModal,{text:"Are you sure you want to delete this application?",description:"Deleting this application will permanently remove all associated student applications. Additionally, if it was required before signing up, you must go into each course product and remove it as a dependency. Please note that this action is irreversible.",isDelete:B,setDelete:()=>D(!1),deleteAction:()=>{c.A.loading("Deleting the application"),W({id:F.applicationId})}}),(0,s.jsx)(m.Dialog,{size:"4xl",open:!!k,onClose:()=>T(void 0),children:(0,s.jsxs)("div",{children:[k&&(0,s.jsxs)("div",{children:[(0,s.jsx)(u.Text,{variant:"h4",className:"font-semibold",children:S[k].title}),(0,s.jsx)(u.Text,{className:"text-gray-500",children:S[k].description})]}),(0,s.jsxs)("div",{className:"my-5 space-y-3",children:[(0,s.jsxs)(x.RadioGroup,{defaultValue:U("required")?"required":"not-required",onValueChange:e=>{G("required","required"===e)},children:[(0,s.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,s.jsx)(x.RadioGroupItem,{value:"required",id:"required"}),(0,s.jsx)("label",{htmlFor:"required",className:"w-full cursor-pointer",children:"Required"})]}),(0,s.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,s.jsx)(x.RadioGroupItem,{value:"not-required",id:"not-required"}),(0,s.jsx)("label",{htmlFor:"not-required",className:"w-full cursor-pointer",children:"Not required"})]})]}),(0,s.jsx)(g.Input,{register:K("question"),label:"Question",placeholder:"Question",className:"mt-1 block w-full rounded-md border-slate-300 shadow-sm focus:border-sky-500 focus:ring-sky-500 sm:text-sm",error:null==z?void 0:null===(e=z.question)||void 0===e?void 0:e.message}),("RADIO"===k||"CHECKBOX"===k)&&(null==ee?void 0:ee.map((e,t)=>{var i,n,l;return(0,s.jsxs)("div",{className:"flex space-x-3 items-start",children:[(0,s.jsx)(g.Input,{label:"Option ".concat(t+1),placeholder:"Option ".concat(t+1),register:K("options.".concat(t,".value")),error:null==z?void 0:null===(l=z.options)||void 0===l?void 0:null===(n=l[t])||void 0===n?void 0:null===(i=n.value)||void 0===i?void 0:i.message}),(0,s.jsx)(d.Button,{outline:!0,className:"mt-7",onClick:()=>{ee.length>1&&ei(t)},children:(0,s.jsx)(a.Z,{})})]},t)}))]}),("RADIO"===k||"CHECKBOX"===k)&&(0,s.jsx)(d.Button,{outline:!0,onClick:()=>et({value:""}),className:"w-full",children:"Add option"}),(0,s.jsxs)("div",{className:"mt-5 flex w-full items-end justify-end space-x-3",children:[(0,s.jsx)(d.Button,{onClick:()=>{T(void 0),L()},outline:!0,children:"Cancel"}),(0,s.jsx)(d.Button,{onClick:async()=>{await H()&&ea()},children:"Submit"})]})]})}),(0,s.jsxs)(m.Dialog,{size:"3xl",open:R,onClose:()=>P(!1),children:[(0,s.jsx)(u.Text,{variant:"h4",className:"font-semibold",children:"Add a question"}),(0,s.jsx)(u.Text,{className:"text-gray-500 mb-5",children:"Add a new question to your application."}),(0,s.jsx)("div",{className:"space-y-3",children:Object.keys(S).map(e=>{if("FILE"===e&&"1"===F.schoolId);else if("FILE"===e)return null;return(0,s.jsxs)("div",{onClick:()=>en(S[e].type),className:"border rounded-lg px-5 hover:bg-gray-100 cursor-pointer bg-gray-50 py-2",children:[(0,s.jsx)(u.Text,{children:S[e].title}),(0,s.jsx)(u.Text,{variant:"sp",children:S[e].description})]},S[e].type)})}),(0,s.jsx)("div",{className:"mt-5 flex w-full items-end justify-end",children:(0,s.jsx)(d.Button,{onClick:()=>{P(!1)},outline:!0,children:"Cancel"})})]}),(0,s.jsxs)(d.Button,{plain:!0,href:q,className:"hover:bg-gray-200 mb-5",children:[(0,s.jsx)(n.Z,{className:"w-4 h-4"}),"Back"]}),(0,s.jsxs)("div",{className:"flex justify-between sm:flex-row flex-col space-y-5 sm:space-y-0",children:[(0,s.jsx)(u.Text,{variant:"h4",font:"poppins",className:"font-semibold",children:"School application"}),(0,s.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,s.jsx)(d.Button,{onClick:()=>P(!0),className:"w-full sm:w-max",children:"Add question"}),(0,s.jsxs)(v.Dropdown,{children:[(0,s.jsx)(v.DropdownButton,{children:(0,s.jsx)(l.Z,{})}),(0,s.jsxs)(v.DropdownMenu,{children:[(0,s.jsx)(v.DropdownItem,{onClick:eo,children:"Export application data to csv (coming soon)"}),(0,s.jsx)(v.DropdownItem,{onClick:async()=>{c.A.loading("Generating url...");let e=await Z({schoolId:F.schoolId}),t="https://".concat(e.customDomain?e.customDomain:"".concat(e.subdomain,".nabda.app"),"/applications/").concat(F.applicationId);navigator.clipboard.writeText(t).then(async()=>{c.A.success("Successfully copied application url!")})},children:"Copy application url"}),(0,s.jsx)(v.DropdownItem,{onClick:()=>D(!0),children:"Delete application"})]})]})]})]}),(0,s.jsxs)("div",{className:"flex flex-col border space-y-3 bg-white p-8 rounded-2xl",children:[(0,s.jsx)(u.Text,{className:"text-gray-500",children:"By default, we collect the student’s name, email, phone number, address, and gender for your convenience."}),(0,s.jsx)(j.Checkbox,{label:"Publish application",message:"Check this box when you are ready to start accepting applications from students.",register:K("publish")}),U("publish")&&(0,s.jsxs)("div",{className:"bg-gray-50 rounded-xl p-5 space-y-3",children:[(0,s.jsx)(j.Checkbox,{label:"Mark as public",message:"Check this box if you want to make this application public to everyone.",register:K("isPublic"),onClick:()=>{U("isPrivate")&&G("isPrivate",!1)}}),(0,s.jsx)(j.Checkbox,{label:"Mark as private",message:"Check this box if you want to make this application private but still accessible by certain people.",register:K("isPrivate"),onClick:()=>{U("isPublic")&&G("isPublic",!1)}})]}),(0,s.jsx)(j.Checkbox,{label:"Mark as a financial aid application.",message:"Please check this box if you would like to collect financial aid information for students.",register:K("isFinancialAidApplication")}),(0,s.jsx)(g.Input,{register:K("title"),label:"Application title",placeholder:"Title",error:null==z?void 0:null===(t=z.title)||void 0===t?void 0:t.message}),(0,s.jsx)(g.Input,{register:K("description"),label:"Application description",placeholder:"Description",isTextArea:!0,error:null==z?void 0:null===(i=z.description)||void 0===i?void 0:i.message}),(0,s.jsx)(d.Button,{className:"mt-5",onClick:el,children:"Save application details"})]}),V?null:(0,s.jsx)(s.Fragment,{children:(0,s.jsx)(C.ApplicationRenderer,{questions:E.fields,edit:e=>{let t=E.fields.find(t=>e===t.id);if(t){var i;let e=null==t?void 0:null===(i=t.options)||void 0===i?void 0:i.map(e=>({value:e}));T(t.type),G("question",t.question),G("type",t.type),G("options",e),G("required",t.required),G("id",t.id)}},deleteField:e=>{c.A.loading("Deleting question..."),Y({id:e})},isEditMode:!0})}),(0,s.jsxs)(f.Tooltip,{children:[(0,s.jsx)(f.TooltipTrigger,{onClick:()=>P(!0),className:"w-full mt-10",children:(0,s.jsx)("div",{className:"bg-gray-100 w-full py-5 px-5 rounded-xl flex items-center justify-center hover:bg-gray-200",children:(0,s.jsx)(o.Z,{className:"h-6 w-6"})})}),(0,s.jsx)(f.TooltipContent,{children:"Add field"})]})]})}},66533:function(e,t,i){i.r(t),i.d(t,{ApplicationRenderer:function(){return A}});var s=i(91674),n=i(37398),a=i(89650),l=i(72816),o=i(71095),r=i(65735),c=i(83154),d=i(68007),u=i(60066),p=i(14306),h=i(29296),m=i(26125),x=i(13110),g=i(53026),v=i(86655),j=i(82428),f=i(13813),y=i(54603),b=i(49793);let N=(e,t,i)=>{switch(e.type){case"RADIO":return(0,s.jsx)(I,{question:e,setValue:t,answer:i});case"CHECKBOX":return(0,s.jsx)(C,{question:e,setValue:t,answer:i});case"INPUT":return(0,s.jsx)(S,{question:e,setValue:t,answer:i});case"DATE":return(0,s.jsx)(q,{question:e,setValue:t,answer:i})}},w=e=>{let t=e.reduce((e,t)=>("TEXT"===t.type?e[t.id]=t.required?n.Z_().trim().required("This question is required"):n.Z_().trim():e[t.id]=t.required?n.nK().required("This question is required"):n.nK(),e),{});return n.Ry().shape({questions:n.Ry().shape(t)})};function A(e){let{applicationId:t,questions:i,studentId:n,edit:h,deleteField:m,isSchoolReviewing:x=!1,isEditMode:g=!1}=e,A=(0,y.useRouter)(),{data:C}=(0,b.useSession)(),I=null==C?void 0:C.user.schoolId,[S,q]=(0,v.useState)(!1),[k,T]=(0,v.useState)(!1),[R,P]=(0,v.useState)(!1),[B,D]=(0,v.useState)(),{data:O,isLoading:F}=f.trpc.application.getStudentApplicationByApplicationIdAndStudentId.useQuery({applicationId:t,studentId:n||(null==C?void 0:C.user.studentId)},{enabled:!!C&&!g}),E=null==O?void 0:O.answers,{mutate:M}=f.trpc.application.submitStudentApplication.useMutation({onSuccess(e){e.submittedAt?(A.push("/applications"),A.refresh(),o.A.success("Successfully submitted application. You will receive an update via email or you can check back here.")):(o.A.success("Successfully saved application"),V(e))},onError(e){o.A.error(e.message)}}),V=async e=>{},{register:Q,handleSubmit:Z,setValue:K,getValues:X,watch:_,trigger:G,formState:{errors:H},reset:L}=(0,l.cI)({resolver:(0,a.X)(w(i)),mode:"onChange",defaultValues:{questions:{}}});(0,v.useEffect)(()=>{E?(q(!0),K("questions",E)):K("questions",{})},[E]);let U=async()=>{o.A.loading("Saving student application...");let e=X("questions"),i=e?Object.keys(e).reduce((t,i)=>(t[i]=e[i],t),{}):{};M({studentId:null==C?void 0:C.user.studentId,applicationId:t,schoolId:I,answers:i,status:"in progress",studentApplicationId:null==O?void 0:O.id})};return O&&O.submittedAt&&!x?(0,s.jsxs)("div",{className:"p-8 rounded-2xl border bg-white",children:[(0,s.jsx)(r.Text,{variant:"h4",className:"font-semibold",children:"You have already submitted this application"}),(0,s.jsxs)(r.Text,{className:"text-gray-500",children:["Submitted on ",(0,j.p6)(O.submittedAt)]}),(0,s.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,s.jsx)(r.Text,{className:"text-gray-500",children:"Status"}),(0,s.jsx)(c.Badge,{color:"accepted"===O.status?"green":"pending"===O.status?"yellow":"in progress"===O.status?"blue":"red",children:"accepted"===O.status?"Accepted":"pending"===O.status?"Review pending":"in progress"===O.status?"In progress":"Rejected"})]})]}):(0,s.jsxs)("div",{className:"space-y-10",children:[!!O&&!x&&(0,s.jsxs)("div",{className:"p-8 bg-white border rounded-2xl",children:[(0,s.jsx)(r.Text,{children:"Application Status"}),(0,s.jsx)(c.Badge,{color:"accepted"===O.status?"green":"pending"===O.status?"yellow":"in progress"===O.status?"blue":"red",children:"accepted"===O.status?"Accepted":"pending"===O.status?"Pending":"in progress"===O.status?"In progress":"Rejected"})]}),(0,s.jsx)(d.DeleteModal,{isDelete:R,setDelete:()=>P(!1),deleteAction:()=>{m(B),P(!1)},withInputConfirmation:!1}),null==i?void 0:i.map(e=>{var t,i,n,a,l,o;return(0,s.jsxs)("div",{className:(0,j.cn)("p-8 bg-white border rounded-2xl",(null==H?void 0:null===(i=H.questions)||void 0===i?void 0:null===(t=i[e.id])||void 0===t?void 0:t.message)&&"border border-red-500"),children:[(0,s.jsx)(r.Text,{variant:"xs",className:"text-gray-500",children:e.required?"*Required":""}),(0,s.jsx)(r.Text,{variant:"lg",className:"font-medium mb-5",children:e.question}),N(e,K,_("questions.".concat(e.id))),g&&(0,s.jsxs)("div",{className:"w-full flex justify-end mt-5 space-x-3",children:[(0,s.jsx)(u.Button,{outline:!0,onClick:()=>{h(e.id)},children:"Edit question"}),(0,s.jsx)(u.Button,{onClick:()=>{D(e.id),P(!0)},color:"red",children:"Delete"})]}),(null==H?void 0:null===(a=H.questions)||void 0===a?void 0:null===(n=a[e.id])||void 0===n?void 0:n.message)&&(0,s.jsx)(r.Text,{className:"text-red-500 mt-5",children:null==H?void 0:null===(o=H.questions)||void 0===o?void 0:null===(l=o[e.id])||void 0===l?void 0:l.message})]},e.id)}),!g&&!x&&(0,s.jsxs)("div",{className:"p-8 rounded-2xl border bg-white flex items-center justify-between",children:[(0,s.jsx)(r.Text,{className:"text-red-500",children:(null==H?void 0:H.questions)?"Please answer all of the questions":""}),(0,s.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,s.jsx)(u.Button,{outline:!0,onClick:()=>U(),children:"Save progress"}),(0,s.jsx)(u.Button,{onClick:Z(()=>T(!0)),children:"Submit application"})]}),(0,s.jsxs)(p.Dialog,{open:k,onClose:()=>T(!1),children:[(0,s.jsxs)("div",{children:[(0,s.jsx)(r.Text,{variant:"h4",className:"font-semibold",children:"Are you sure you want to submit this application?"}),(0,s.jsx)(r.Text,{className:"mt-3 text-gray-500",children:"After submitting this application, you will not be able to edit it."})]}),(0,s.jsxs)("div",{className:"flex items-center justify-end space-x-3 mt-5",children:[(0,s.jsx)(u.Button,{outline:!0,onClick:()=>T(!1),children:"Close"}),(0,s.jsx)(u.Button,{onClick:Z(e=>{o.A.loading("Submitting student application...");let{firstName:i,lastName:s,gender:n,contact:a,address:l}=e,r=e.questions?Object.keys(e.questions).reduce((t,i)=>(t[i]=e.questions[i],t),{}):{};M({studentId:null==C?void 0:C.user.studentId,applicationId:t,schoolId:I,answers:r,submittedAt:new Date().toISOString(),studentApplicationId:null==O?void 0:O.id})}),children:"Submit"})]})]})]})]})}function C(e){var t;let{question:i,setValue:n,answer:a}=e;return(0,s.jsx)(h.CheckboxGroup,{children:null===(t=i.options)||void 0===t?void 0:t.map((e,t)=>(0,s.jsxs)(h.CheckboxField,{className:"cursor-pointer",children:[(0,s.jsx)(h.CheckboxV2,{checked:!!a&&e in a&&!!a[e],onChange:t=>{n("questions.".concat(i.id),{...a,[e]:t})},name:e,value:e}),(0,s.jsx)(m.Label,{className:"cursor-pointer w-full",children:(0,s.jsx)(r.Text,{children:e})})]},"".concat(i.id,"-").concat(e)))})}function I(e){var t;let{question:i,setValue:n,answer:a}=e;return(0,s.jsx)(x.RadioGroup,{defaultValue:a,onValueChange:e=>n("questions.".concat(i.id),e),children:null===(t=i.options)||void 0===t?void 0:t.map((e,t)=>(0,s.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,s.jsx)(x.RadioGroupItem,{checked:a===e,value:e,id:"".concat(i.id,"-").concat(e)}),(0,s.jsx)("label",{htmlFor:"".concat(i.id,"-").concat(e),className:"w-full cursor-pointer",children:e})]},"".concat(i.id,"-").concat(e)))})}function S(e){let{question:t,setValue:i,answer:n}=e;return(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:t.id,className:"block text-sm font-medium text-gray-700",children:"Submission"}),(0,s.jsx)("textarea",{rows:5,value:n,onChange:e=>{let s=e.target.value;i("questions.".concat(t.id),s)},className:"p-2 pl-3 block rounded-md shadow-sm text-base border border-slate-300 w-full focus:border-sky-500 focus:ring-sky-500"})]})}function q(e){let{question:t,setValue:i,answer:n}=e;return(0,s.jsx)("div",{children:(0,s.jsx)(g.DatePicker,{date:n?new Date(n):"",setDate:e=>i("questions.".concat(t.id),e),message:"Select a date to answer this question."})})}},75085:function(e,t,i){i.r(t),i.d(t,{StudentApplication:function(){return N}});var s=i(91674),n=i(9316),a=i(13813),l=i(71095),o=i(14306),r=i(65735),c=i(7644),d=i(60066),u=i(2063),p=i(83154),h=i(82428),m=i(54603),x=i(66533),g=i(49793),v=i(86655),j=i(89650),f=i(37398),y=i(72816);let b=f.Ry().shape({amount:f.Rx().min(0,"Please enter a percent greater than or equal to 0%").max(100,"Please enter a percent less than or equal to 100%").required("Please enter in the financial aid amount.").typeError("Please enter a percent")});function N(){var e,t,i;let[f,N]=(0,v.useState)(),{data:w}=(0,g.useSession)(),A=(0,m.usePathname)().split("/");A.pop();let C=A.join("/"),I=(0,m.useParams)(),S=I.schoolId,q=I.studentApplicationId,{data:k}=a.trpc.faculty.getFacultyMember.useQuery({schoolId:S,teacherId:null==w?void 0:w.user.teacherId},{enabled:!!w}),{data:T,isLoading:R,refetch:P}=a.trpc.application.getStudentApplicationByIdAndApplication.useQuery({id:q}),B=null==T?void 0:null===(e=T.application)||void 0===e?void 0:e.isFinancialAid,D=null==T?void 0:null===(t=T.financialAid)||void 0===t?void 0:t.percentOff,{data:O}=a.trpc.stripe.getAccount.useQuery({schoolId:S},{enabled:B}),{register:F,handleSubmit:E,watch:M,getValues:V,trigger:Q,formState:{errors:Z},reset:K}=(0,y.cI)({resolver:(0,j.X)(b),mode:"onChange"}),{mutate:X}=a.trpc.application.updateApplicationStatus.useMutation({onSuccess(e){P(),l.A.success("Successfully updated status of application!"),W(e)}}),_=()=>{l.A.loading("Rejecting application..."),N(void 0),X({id:q,status:"reject"})},G=()=>{l.A.loading("Accepting application..."),N(void 0),X({id:q,status:"accepted"})},H=async()=>{if(O)return await fetch("/api/stripe/coupon/addCoupon",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountId:O.accountId,name:"Financial aid for ".concat(null==T?void 0:T.student.user.firstName," ").concat(null==T?void 0:T.student.user.lastName),percentOff:parseInt(V("amount").toString()),maxRedemptions:1,schoolId:S,duration:"forever"})}).then(e=>e.json()).then(e=>{let{coupon:t,error:i}=e;if(t)return t;if(i){l.A.error("We had some trouble accepting this financial aid application. Please try again later.");return}})},L=async()=>{if(await Q("amount")){l.A.loading("Accepting financial aid application..."),N(void 0);let e=await H();e&&X({id:q,status:"accepted",financialAidId:e.id})}else l.A.error("Please enter the financial aid amount.")},U=async()=>{l.A.loading("Rejecting financial aid application..."),N(void 0),X({id:q,status:"reject",financialAidId:void 0}),await z()},z=async()=>{if(O){var e;return await fetch("/api/stripe/coupon/deleteCoupon",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountId:O.accountId,stripeCouponId:null==T?void 0:null===(e=T.financialAid)||void 0===e?void 0:e.stripeCouponId,couponId:null==T?void 0:T.financialAid.id})}).then(e=>e.json()).then(e=>{let{isDeleted:t,error:i}=e;return!!t||(i&&l.A.error("We had some trouble rejecting this financial aid application. Please try again later."),!1)})}return!1},W=async e=>{let t=new Date,i=t.toLocaleString("default",{month:"long"}),s=t.toLocaleString("default",{day:"numeric"}),n=e.student.user.firstName,a=e.student.user.lastName,o=e.student.user.email,r=e.school,c=e.application,d="https://".concat((null==r?void 0:r.site.customDomain)?null==r?void 0:r.site.customDomain:"".concat(null==r?void 0:r.site.subdomain,".nabda.app"));try{await fetch("/api/sendEmail",{method:"POST",body:JSON.stringify({schoolName:null==r?void 0:r.name,subject:"".concat(null==r?void 0:r.name," | Application Update"),template:"sendApplicationUpdate",replyTo:"noreply@nabda.app",from:"".concat(null==r?void 0:r.name," <noreply@updates.nabda.app>"),emails:[o.toLowerCase()],props:{name:"".concat(n," ").concat(a),date:i+" "+s,schoolName:null==r?void 0:r.name,schoolLogo:null==r?void 0:r.logo,status:e.status,applicationName:c.title,route:d}})})}catch(e){l.A.error("We had some trouble sending an email to this applicant. Please inform them of their application status.")}};return R?null:(0,s.jsxs)("div",{children:[(0,s.jsxs)(o.Dialog,{open:!!f,onClose:()=>N(void 0),children:[(0,s.jsx)("div",{children:B?(0,s.jsxs)("div",{children:[(0,s.jsxs)(r.Text,{variant:"h4",className:"font-semibold",children:["accept"===f?"Accept":"Reject"," financial aid"]}),"reject"===f?(0,s.jsx)(r.Text,{className:"mt-3",children:"You are about to reject this student's financial aid request."}):(0,s.jsx)(c.Input,{css:"mt-3",label:"Percent of financial aid granted",register:F("amount"),error:null===(i=Z.amount)||void 0===i?void 0:i.message,placeholder:"Percent of financial aid granted"})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(r.Text,{variant:"h4",className:"font-semibold",children:["accept"===f?"Accept":"Reject"," application"]}),(0,s.jsx)(r.Text,{className:"mt-3",children:"You are about to update the status of this student's application. Doing so will also send an email to the student, informing them of the status change."})]})}),(0,s.jsxs)("div",{className:"flex items-center space-x-3 mt-5 justify-end",children:[(0,s.jsx)(d.Button,{onClick:()=>N(void 0),outline:!0,children:"Close"}),(0,s.jsx)(d.Button,{color:"accept"===f?"green":"red",onClick:()=>{B?"accept"===f?L():U():"accept"===f?G():_()},children:"accept"===f?"Accept":"Reject"})]})]}),(0,s.jsxs)(d.Button,{plain:!0,href:C,className:"hover:bg-gray-200 mb-5",children:[(0,s.jsx)(n.Z,{className:"w-4 h-4"}),"Back"]}),R?(0,s.jsxs)("div",{className:"space-y-5",children:[(0,s.jsx)(u.Q,{height:"h-44"}),(0,s.jsx)(u.Q,{height:"h-44"}),(0,s.jsx)(u.Q,{height:"h-44"}),(0,s.jsx)(u.Q,{height:"h-44"}),(0,s.jsx)(u.Q,{height:"h-44"}),(0,s.jsx)(u.Q,{height:"h-44"})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{children:"accepted"===T.status?(0,s.jsx)(p.Badge,{color:"green",children:D?"".concat(D,"% granted"):"Accepted"}):"pending"===T.status?(0,s.jsx)(p.Badge,{color:"yellow",children:"Review pending"}):"in progress"===T.status?(0,s.jsx)(p.Badge,{color:"blue",children:"In progress"}):(0,s.jsx)(p.Badge,{color:"red",children:"Rejected"})}),(0,s.jsxs)("div",{className:"",children:[(0,s.jsxs)(r.Text,{className:"text-gray-500",variant:"sp",children:["Applicant for ",null==T?void 0:T.application.title]}),(0,s.jsxs)(r.Text,{variant:"h4",className:"font-semibold",children:[null==T?void 0:T.student.user.firstName," ",null==T?void 0:T.student.user.lastName]})]}),(0,s.jsx)(r.Text,{className:"text-gray-500",children:"Submitted on"}),(0,s.jsx)(r.Text,{children:(null==T?void 0:T.submittedAt)?(0,h.p6)(null==T?void 0:T.submittedAt):"Not yet submitted"})]}),((null==k?void 0:k.permissions.includes("OWNER"))||(null==k?void 0:k.permissions.includes("ADMIN")))&&(0,s.jsxs)("div",{className:"w-full flex justify-end space-x-3 items-center",children:["reject"===T.status?null:(0,s.jsx)(d.Button,{onClick:()=>N("reject"),color:"red",children:"Reject"}),"accepted"===T.status?null:(0,s.jsx)(d.Button,{onClick:()=>N("accept"),color:"green",children:"Accept"})]}),(0,s.jsxs)("div",{className:"bg-white border p-8 rounded-2xl mt-5",children:[(0,s.jsxs)("div",{className:"flex sm:flex-row flex-col sm:items-center sm:justify-between",children:[(0,s.jsx)(r.Text,{className:"font-semibold",variant:"lg",children:"User information"}),(0,s.jsx)(d.Button,{href:"/schools/".concat(S,"/students/").concat(null==T?void 0:T.student.id),className:"sm:w-max w-full sm:mt-0 mt-3",outline:!0,children:"View student data"})]}),(0,s.jsxs)("div",{className:"w-full grid grid-cols-1 gap-x-3 gap-y-5 sm:grid-cols-6 mt-3",children:[(0,s.jsxs)("div",{className:"sm:col-span-3",children:[(0,s.jsx)(r.Text,{variant:"sp",className:"text-gray-500",children:"Email"}),(0,s.jsx)(r.Text,{children:null==T?void 0:T.student.user.email})]}),(0,s.jsxs)("div",{className:"sm:col-span-3",children:[(0,s.jsx)(r.Text,{variant:"sp",className:"text-gray-500",children:"Phone number"}),(0,s.jsx)(r.Text,{children:null==T?void 0:T.student.user.phoneNumber})]})]})]}),(0,s.jsxs)("div",{className:"mt-5 relative",children:[(0,s.jsx)(x.ApplicationRenderer,{questions:null==T?void 0:T.application.fields,applicationId:null==T?void 0:T.applicationId,studentId:null==T?void 0:T.studentId,isSchoolReviewing:!0}),(0,s.jsx)("div",{className:"absolute inset-0 z-10"})]})]})]})}},52258:function(e,t,i){i.r(t),i.d(t,{StudentApplications:function(){return f}});var s=i(91674),n=i(95257),a=i(13813),l=i(90393),o=i(54603),r=i(72763),c=i(12870),d=i(65735),u=i(44742),p=i(60066),h=i(86655);function m(e){var t,i,n;let{columns:a,data:l,filterBy:o}=e,[m,x]=(0,h.useState)([]),[g,v]=(0,h.useState)([]),[j,f]=(0,h.useState)({}),[y,b]=(0,h.useState)({}),[N,w]=(0,h.useState)(),A=(0,r.b7)({data:l,columns:a,getCoreRowModel:(0,c.sC)(),getPaginationRowModel:(0,c.G_)(),onSortingChange:x,getSortedRowModel:(0,c.tj)(),onColumnFiltersChange:v,getFilteredRowModel:(0,c.vL)(),onColumnVisibilityChange:f,onRowSelectionChange:b,state:{sorting:m,columnFilters:g,columnVisibility:j,rowSelection:y}});return(0,s.jsxs)("div",{children:[o&&(0,s.jsxs)("div",{className:"py-3",children:[(0,s.jsxs)("label",{className:"block text-sm font-medium text-gray-700",children:["Filter by ",o]}),(0,s.jsx)("input",{value:null!==(n=null===(t=A.getColumn(o))||void 0===t?void 0:t.getFilterValue())&&void 0!==n?n:"",placeholder:"Filter by ".concat(o),onChange:e=>{var t;return null===(t=A.getColumn(o))||void 0===t?void 0:t.setFilterValue(e.target.value)},className:"p-1 pl-3 block rounded-md border border-slate-300 focus:border-sky-500 focus:ring-sky-500 w-full"})]}),(0,s.jsxs)("div",{className:"mb-3",children:[(0,s.jsx)(d.Text,{variant:"sp",className:"mb-1",children:"Filter by status:"}),(0,s.jsxs)("div",{className:"flex space-x-2 items-center",children:[(0,s.jsx)("div",{onClick:()=>{var e,t;"accepted"===N?(null===(e=A.getColumn("status"))||void 0===e||e.setFilterValue(""),w(void 0)):(null===(t=A.getColumn("status"))||void 0===t||t.setFilterValue("accepted"),w("accepted"))},className:"px-2 py-1 w-max rounded-full cursor-pointer ".concat("accepted"===N?"bg-green-500 text-white":"bg-gray-200 hover:bg-gray-300"),children:(0,s.jsx)(d.Text,{variant:"xs",children:"Accepted"})}),(0,s.jsx)("div",{onClick:()=>{var e,t;"rejected"===N?(null===(e=A.getColumn("status"))||void 0===e||e.setFilterValue(""),w(void 0)):(null===(t=A.getColumn("status"))||void 0===t||t.setFilterValue("reject"),w("rejected"))},className:"bg-gray-200 px-2 py-1 w-max rounded-full cursor-pointer hover:bg-gray-300 ".concat("rejected"===N?"bg-green-500 text-white":"bg-gray-200 hover:bg-gray-300"),children:(0,s.jsx)(d.Text,{variant:"xs",children:"Rejected"})}),(0,s.jsx)("div",{onClick:()=>{var e,t;"pending"===N?(null===(e=A.getColumn("status"))||void 0===e||e.setFilterValue(""),w(void 0)):(null===(t=A.getColumn("status"))||void 0===t||t.setFilterValue("pending"),w("pending"))},className:"bg-gray-200 px-2 py-1 w-max rounded-full cursor-pointer hover:bg-gray-300 ".concat("pending"===N?"bg-green-500 text-white":"bg-gray-200 hover:bg-gray-300"),children:(0,s.jsx)(d.Text,{variant:"xs",children:"Pending"})}),(0,s.jsx)("div",{onClick:()=>{var e,t;"in progress"===N?(null===(e=A.getColumn("status"))||void 0===e||e.setFilterValue(""),w(void 0)):(null===(t=A.getColumn("status"))||void 0===t||t.setFilterValue("in progress"),w("in progress"))},className:"px-2 py-1 w-max rounded-full cursor-pointer ".concat("in progress"===N?"bg-green-500 text-white":"bg-gray-200 hover:bg-gray-300"),children:(0,s.jsx)(d.Text,{variant:"xs",children:"In progress"})})]})]}),(0,s.jsx)("div",{className:"rounded-md border bg-white",children:(0,s.jsxs)(u.iA,{children:[(0,s.jsx)(u.xD,{children:A.getHeaderGroups().map(e=>(0,s.jsx)(u.SC,{children:e.headers.map(e=>(0,s.jsx)(u.ss,{children:e.isPlaceholder?null:(0,r.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,s.jsx)(u.RM,{children:(null===(i=A.getRowModel().rows)||void 0===i?void 0:i.length)?A.getRowModel().rows.map(e=>(0,s.jsx)(u.SC,{"data-state":e.getIsSelected()&&"selected",children:e.getVisibleCells().map(e=>(0,s.jsx)(u.pj,{children:(0,r.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,s.jsx)(u.SC,{children:(0,s.jsx)(u.pj,{colSpan:a.length,className:"h-24 text-center",children:"No results."})})})]})}),(0,s.jsxs)("div",{className:"flex items-center justify-end space-x-2 py-4",children:[(0,s.jsx)(p.Button,{outline:!0,onClick:()=>A.previousPage(),disabled:!A.getCanPreviousPage(),children:"Previous"}),(0,s.jsx)(p.Button,{outline:!0,onClick:()=>A.nextPage(),disabled:!A.getCanNextPage(),children:"Next"})]})]})}var x=i(52077),g=i(83154),v=i(82428);let j=[{accessorKey:"application",header:"Application"},{accessorKey:"name",header:"Name"},{accessorKey:"email",header:e=>{let{column:t}=e;return(0,s.jsxs)(p.Button,{plain:!0,onClick:()=>t.toggleSorting("asc"===t.getIsSorted()),className:"font-normal",children:["Email",(0,s.jsx)(x.Z,{})]})}},{accessorKey:"submittedOn",header:e=>{let{column:t}=e;return(0,s.jsxs)(p.Button,{plain:!0,onClick:()=>t.toggleSorting("asc"===t.getIsSorted()),className:"font-normal",children:["Submitted on",(0,s.jsx)(x.Z,{})]})},cell:e=>{let{row:t}=e;return t.getValue("submittedOn")?(0,v.p6)(t.getValue("submittedOn")):"Not yet submitted"}},{accessorKey:"status",header:e=>{let{column:t}=e;return(0,s.jsxs)(p.Button,{plain:!0,onClick:()=>t.toggleSorting("asc"===t.getIsSorted()),className:"font-normal",children:["Status",(0,s.jsx)(x.Z,{})]})},cell:e=>{let{row:t}=e,i=t.getValue("status");return(0,s.jsx)(g.Badge,{color:"accepted"===i?"green":"pending"===i?"yellow":"in progress"===i?"blue":"red",children:"accepted"===i?"Accepted":"pending"===i?"Review pending":"in progress"===i?"In progress":"Rejected"})}},{id:"actions",cell:e=>{let{row:t}=e,i=t.original.id;return(0,s.jsx)(p.Button,{outline:!0,href:"applications/".concat(i),className:"text-center",children:"Review"})}}];function f(){let e=(0,o.useParams)(),{data:t,isLoading:i}=a.trpc.application.getStudentsApplications.useQuery({schoolId:e.schoolId}),r=null==t?void 0:t.map(e=>({id:e.id,application:e.application.title,name:"".concat(null==e?void 0:e.student.user.firstName," ").concat(null==e?void 0:e.student.user.lastName),email:null==e?void 0:e.student.user.email,submittedOn:e.submittedAt,status:e.status}));return(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)("div",{children:[!i&&(null==t?void 0:t.length)===0&&(0,s.jsx)(l.u,{className:"border-none",icon:n.Z,title:"No student applications.",description:"It looks like there are currently no application. Students who apply will show up here.",shouldRenderButton:!1}),r?(0,s.jsx)(m,{filterBy:"email",columns:j,data:r}):null]})})}},13110:function(e,t,i){i.r(t),i.d(t,{RadioGroup:function(){return r},RadioGroupItem:function(){return c}});var s=i(91674),n=i(86655),a=i(4168),l=i(78101),o=i(82428);let r=n.forwardRef((e,t)=>{let{className:i,...n}=e;return(0,s.jsx)(a.fC,{className:(0,o.cn)("grid gap-2",i),...n,ref:t})});r.displayName=a.fC.displayName;let c=n.forwardRef((e,t)=>{let{className:i,...n}=e;return(0,s.jsx)(a.ck,{ref:t,className:(0,o.cn)("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",i),...n,children:(0,s.jsx)(a.z$,{className:"flex items-center justify-center",children:(0,s.jsx)(l.Z,{className:"h-2.5 w-2.5 fill-current text-current"})})})});c.displayName=a.ck.displayName}}]);