1 2!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f2b8e158-241a-5b95-94d1-fb34368e8e8a")}catch(e){}}(); 3import{j as s}from"./heroUI-B_ljU1QU.js";import{u as ie,a as o}from"./i18n-B1Tl-FS8.js";import{h as oe,i as re,b as ne,P as k}from"./App-NouI1Fy-.js";import{I as E}from"./Icon-Bn1Of1X8.js";import{B as P}from"./percentages-BXMCSKIN-CQaZ_nn0.js";import{I as le}from"./InputText-CPgxvznP.js";import{i as me,u as de,Q as ce,C as ue,F as pe,R as fe,a as he,T as xe,f as ge}from"./RandomizationSettings-byaKwVIo.js";import{u as be}from"./useForm-D_u_jxF8.js";import{S as _e}from"./StickyPageBar-BRhYpxrO.js";import{K as je}from"./KindTag-CPjEytEn.js";import{U as ve}from"./UpgradeModal-CaHJ5jMQ.js";import{c as ye}from"./useAccess-D5xE21lI.js";import"./excalidraw-ClE5B34E.js";import"./app-CNhMxvwe.js";import"./utils-Ck-GfcmJ.js";import"./file-text-D_rPaBmV.js";import"./check-CwC0fwRx.js";import"./arrow-up-right-DPds2Qak.js";import"./triangle-alert-yCytgbHH.js";import"./plus-BtuFysVt.js";import"./FeedVisibilityIcon-BCkAvGxF.js";import"./useMinWidth-BACQ5dLm.js";import"./plusBenefits-BoOenaCM.js";import"./ScaledModal-BhjXAmpD.js";import"./chatwoot-DTUnF2sG.js";const Q=291,B=(l,r=1)=>({id:r,question:"",custom_quiz_answer:l?2:0,custom_quiz_answer_json:[],image_path:null,image_url:null,description:"",max_selections:1}),Se={inputsSchema:me},we=l=>{const{t:r}=ie();l={...Se,...l};const O={...l.inputsSchema,question1:{name:"question1",label:r("forms.addForm.fields.questionBox.placeholder"),validate:{isRequired:!0,lengthMax:Q}}},u=new URLSearchParams(l.location?.search||"").get("kind")==="test",p=u?"test":"quiz",[A,S]=o.useState(O),[m,f]=o.useState(()=>[B(u)]),[w,z]=o.useState(!1),[h,M]=o.useState(null),[_,N]=o.useState(null),[R,j]=o.useState(!1),[g,D]=o.useState(!1),[b,U]=o.useState(!1),[L,q]=o.useState(!1),[V,H]=o.useState(!1),F=o.useRef(null),{planUsage:K}=oe(),{addNotification:$}=re(),{handleChange:v,values:d,errors:x,handleFetch:G,setValues:I}=be({inputsSchema:A,callBack:se}),{fetchApi:J,isLoading:c,responseApi:n}=ne({url:_?`/user/form/${_}/update`:"/user/form/create",method:"POST",data:{title:d.title,questions:m,gallery_kind:p,randomize_questions:g,randomize_answers:b,is_draft:!1,...ye(l.user)?{}:{visibility:"public"}},suppressCapabilityToast:!0}),y=o.useMemo(()=>({title:d?.title||"",gallery_kind:p,randomize_questions:g,randomize_answers:b,questions:m.map(e=>({id:e.id,question:d?.["question"+e.id]??e.question,custom_quiz_answer:e.custom_quiz_answer,custom_quiz_answer_json:e.custom_quiz_answer_json,image_path:e.image_path,description:e.description||"",max_selections:e.max_selections??1}))}),[d,m,p,g,b]),W=!!((y.title||"").trim()||y.questions.some(e=>String(e.question||"").trim()||(e.custom_quiz_answer_json||[]).some(a=>String(a?.label||"").trim()))),{isSaving:C=!1}=de({enabled:W&&!h&&!c&&!R,formId:_,payload:y,onCreated:e=>{N(e.form_id)}})||{};o.useEffect(()=>{if(n?.capability_required){n.draft_saved&&n.data?.form_id&&(N(n.data.form_id),H(!0)),q(!0),j(!1);return}n?.success&&n?.data?.form_id&&!n.data.is_draft&&M({...n.data,visibility:"public"}),n&&!n.success&&j(!1)},[n]),o.useEffect(()=>{w&&(z(!1),setTimeout(()=>{window.scrollTo({top:F.current.scrollHeight,behavior:"smooth"})},50))},[w]);function X(){l.navigate("/gallery")}function Y(){const e=new Date().getUTCMilliseconds()+Math.random(1,9999).toFixed(0),a=B(u,parseInt(e)),t="question"+e;f(i=>[...i,a]),S(i=>({...i,[t]:{name:t,label:r("forms.addForm.fields.questionBox.placeholder"),validate:{isRequired:!0,lengthMax:Q}}})),z(!0)}const T=o.useCallback((e,a)=>{f(t=>t.filter((i,ae)=>parseInt(ae)!==parseInt(e))),S(t=>{const i={...t};return delete i[a],i}),I(t=>{const i={...t};return delete i[a],i})},[I]);function Z(e){f(a=>a.map(t=>parseInt(t.id)===parseInt(e.id)?{...t,...e}:t))}function ee(e,a){f(t=>t.map(i=>parseInt(i.id)===parseInt(e)?{...i,custom_quiz_answer_json:a}:i))}function se(){const e=ge(m);
3if(e){$({title:r("globals.error"),description:r("forms.addForm.emptyOptionMessage"),settings:{type:"error",duration:4e3}}),requestAnimationFrame(()=>document.querySelector(`input[name="option-${e.questionId}-${e.optionId}"]`)?.focus());return}j(!0),J()}const te=o.useMemo(()=>m.map((e,a)=>{const t="question"+e.id,i={...e,number:a+1,value:d?.[t]};return s.jsx(ce,{question:i,value:e,onChange:v,deleteFunc:()=>T(a,t),errorMsg:x?.[t],isError:x?.hasOwnProperty(t),updateQuestion:Z,updateQuestionAnswerJson:ee,isTest:u},e.id)}),[m,x,v,d,T,u]);return l.user?s.jsxs(s.Fragment,{children:[s.jsxs(_e,{className:"form-builder-page-bar",children:[s.jsxs("button",{type:"button",className:"mr-auto flex cursor-pointer items-center",onClick:X,children:[s.jsx("span",{className:"mr-3 rotate-90",children:s.jsx(E,{name:"arrow"})}),s.jsx("span",{className:"flex text-sm font-medium leading-5 text-muted",children:r("globals.back")})]}),s.jsx(P,{text:r("globals.save"),theme:"primary",size:{width:"93px",height:"40px"},isLoading:c||C,isDisabled:c||C,onClick:G})]}),s.jsxs("div",{className:"form-builder relative mt-10",children:[c&&s.jsx("div",{className:"absolute top-[200px] right-0 left-0 z-[999] mx-auto max-w-[100px]",children:s.jsx(ue,{})}),s.jsx("div",{className:"mb-8",children:s.jsx(le,{label:r("forms.addForm.fields.name.label"),isError:x?.hasOwnProperty("title"),placeholder:r("forms.addForm.fields.name.placeholder"),errorMsg:x?.title,value:d?.title,name:"title",hasErrIcon:!0,isShakeOnErr:!0,onChange:v})}),s.jsx(pe,{content:s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:F,className:"form-builder-questions relative min-h-[328px] pt-2",style:{pointerEvents:c?"none":"auto",opacity:c?.4:1},children:s.jsx(he,{as:"div",axis:"y",values:m,onReorder:f,style:{padding:0,margin:0,width:"100%",overflow:"visible"},children:te})}),s.jsx("div",{className:"relative pb-4 pt-8",children:s.jsxs("div",{className:"flex items-center justify-center",children:[s.jsx("div",{className:"absolute mr-auto h-px w-screen bg-[#E4E7EC]"}),s.jsx("div",{className:"bottom-btn-cover",children:s.jsx(P,{icon:s.jsx(E,{name:"plus",stroke:"#344054"}),isDisabled:c,text:r("forms.addForm.addNewQuestion"),theme:"light",size:{width:"242px",height:"40px"},textStyle:{fontSize:"14px",lineHeight:"20px",fontWeight:"500"},onClick:Y})})]})})]}),details:s.jsxs("div",{className:"flex flex-col gap-6",children:[s.jsx("section",{className:"rounded-2xl border border-border bg-surface p-5",children:s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-base font-semibold text-foreground",children:r("forms.editor.details.typeTitle")}),s.jsx("p",{className:"mt-1 text-sm leading-5 text-muted",children:r("forms.editor.details.typeDescription")})]}),s.jsx(je,{kind:p})]})}),s.jsx(fe,{randomizeQuestions:g,randomizeAnswers:b,onChange:(e,a)=>{e==="randomizeQuestions"&&D(a),e==="randomizeAnswers"&&U(a)}})]})})]}),s.jsx(xe,{isOpen:!!h?.form_id,formId:h?.form_id,kind:p,canShareSchool:!!h?.can_share_school,schoolMemberCount:h?.school_member_count||0,initialVisibility:"public",onComplete:()=>l.navigate("/gallery")}),s.jsx(ve,{isOpen:L,onClose:()=>q(!1),action:"forms",draftSaved:V,planUsage:K})]}):null};
3we.propTypes={inputsSchema:k.object,navigate:k.func};export{we as default}; 4 5//# debugId=f2b8e158-241a-5b95-94d1-fb34368e8e8a
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.