1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[812],{812:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{Z:function(){return Account_UserQuestions}});var jsx_runtime=__webpack_require__(5893),react=__webpack_require__(7294),Inputs=__webpack_require__(3537),UserInterests=__webpack_require__(7836),fetchContext=__webpack_require__(5828),authContext=__webpack_require__(188),react_datepicker_min=__webpack_require__(9198),react_datepicker_min_default=__webpack_require__.n(react_datepicker_min),CityInput=__webpack_require__(8375),Text=__webpack_require__(6058),Image=__webpack_require__(4249),ClickOutsideListener=__webpack_require__(7699);let UserQuestionTooltip=param=>{let{tooltip}=param;return(0,jsx_runtime.jsx)(ClickOutsideListener.Z,{className:"",children:(showElement,setShowElement)=>(0,jsx_runtime.jsxs)("div",{className:"tooltip",onClick:()=>setShowElement(show=>!show),children:[(0,jsx_runtime.jsx)(TooltipIcon,{}),(0,jsx_runtime.jsxs)("div",{className:"tooltip-text ".concat(showElement?"show":""),children:[tooltip,(0,jsx_runtime.jsx)("div",{className:"tooltip-text-shape",children:(0,jsx_runtime.jsx)(TooltipBoxShape,{})})]})]})})},TooltipIcon=()=>(0,jsx_runtime.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,jsx_runtime.jsx)("mask",{id:"mask0_436_2321",maskUnits:"userSpaceOnUse",x:"0",y:"0",width:"16",height:"16",children:(0,jsx_runtime.jsx)("rect",{width:"16",height:"16",fill:"#D9D9D9"})}),(0,jsx_runtime.jsx)("g",{mask:"url(#mask0_436_2321)",children:(0,jsx_runtime.jsx)("path",{d:"M8.00065 11.3333C8.18954 11.3333 8.34787 11.2694 8.47565 11.1416C8.60343 11.0138 8.66732 10.8555 8.66732 10.6666V7.99992C8.66732 7.81103 8.60343 7.6527 8.47565 7.52492C8.34787 7.39714 8.18954 7.33325 8.00065 7.33325C7.81176 7.33325 7.65343 7.39714 7.52565 7.52492C7.39787 7.6527 7.33398 7.81103 7.33398 7.99992V10.6666C7.33398 10.8555 7.39787 11.0138 7.52565 11.1416C7.65343 11.2694 7.81176 11.3333 8.00065 11.3333ZM8.00065 5.99992C8.18954 5.99992 8.34787 5.93603 8.47565 5.80825C8.60343 5.68047 8.66732 5.52214 8.66732 5.33325C8.66732 5.14436 8.60343 4.98603 8.47565 4.85825C8.34787 4.73047 8.18954 4.66658 8.00065 4.66658C7.81176 4.66658 7.65343 4.73047 7.52565 4.85825C7.39787 4.98603 7.33398 5.14436 7.33398 5.33325C7.33398 5.52214 7.39787 5.68047 7.52565 5.80825C7.65343 5.93603 7.81176 5.99992 8.00065 5.99992ZM8.00065 14.6666C7.07843 14.6666 6.21176 14.4916 5.40065 14.1416C4.58954 13.7916 3.88398 13.3166 3.28398 12.7166C2.68398 12.1166 2.20898 11.411 1.85898 10.5999C1.50898 9.78881 1.33398 8.92214 1.33398 7.99992C1.33398 7.0777 1.50898 6.21103 1.85898 5.39992C2.20898 4.58881 2.68398 3.88325 3.28398 3.28325C3.88398 2.68325 4.58954 2.20825 5.40065 1.85825C6.21176 1.50825 7.07843 1.33325 8.00065 1.33325C8.92287 1.33325 9.78954 1.50825 10.6007 1.85825C11.4118 2.20825 12.1173 2.68325 12.7173 3.28325C13.3173 3.88325 13.7923 4.58881 14.1423 5.39992C14.4923 6.21103 14.6673 7.0777 14.6673 7.99992C14.6673 8.92214 14.4923 9.78881 14.1423 10.5999C13.7923 11.411 13.3173 12.1166 12.7173 12.7166C12.1173 13.3166 11.4118 13.7916 10.6007 14.1416C9.78954 14.4916 8.92287 14.6666 8.00065 14.6666ZM8.00065 13.3333C9.48954 13.3333 10.7507 12.8166 11.784 11.7833C12.8173 10.7499 13.334 9.48881 13.334 7.99992C13.334 6.51103 12.8173 5.24992 11.784 4.21659C10.7507 3.18325 9.48954 2.66659 8.00065 2.66659C6.51176 2.66659 5.25065 3.18325 4.21732 4.21659C3.18398 5.24992 2.66732 6.51103 2.66732 7.99992C2.66732 9.48881 3.18398 10.7499 4.21732 11.7833C5.25065 12.8166 6.51176 13.3333 8.00065 13.3333Z",fill:"#353CC5"})})]}),TooltipBoxShape=()=>(0,jsx_runtime.jsx)("svg",{width:"32",height:"16",viewBox:"0 0 32 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,jsx_runtime.jsx)("path",{d:"M17.4142 14.5858C16.6332 15.3668 15.3668 15.3668 14.5858 14.5858L1.39876e-06 -8.9018e-07L32 1.90735e-06L17.4142 14.5858Z",fill:"rgba(10, 11, 35, 0.95)"})}),UserQuestions=param=>{let{type,quiz,setQuiz,buttonTitle,buttonExtraText,buttonDisabled,minQuestionsToAnswer=0,extraText,submitCb,showMoreAvailable=!0,showSubmitBtn=!0,editable=!0,updateQuestionsCalc,isProfilePage}=param,CITY_POSITION=isProfilePage?4:11,DATE_POSITION=isProfilePage?3:10,{user,setUser,isLoggedIn,setAuthModalHeader,openAuthModal,updateSignUpLocation,updateUserInfo}=(0,authContext.aC)(),{fetchAPI}=(0,fetchContext.ib)(),[birthday,setBirthday]=(0,react.useState)(null),[city,setCity]=(0,react.useState)(""),[state,setState]=(0,react.useState)(""),[questionsAnswers,setQuestionsAnswers]=(0,react.useState)([]);(0,react.useEffect)(()=>{(null==user?void 0:user.profileData)&&(setBirthday(user.profileData.birthday?new Date(user.profileData.birthday):null),setCity(user.profileData.city||""),setState(user.profileData.state||""))},[user]);let updateDateHandler=async date=>{setBirthday(date)},[categories,setCategories]=(0,react.useState)([]);(0,react.useEffect)(()=>{let getCategories=async()=>{let json=await fetchAPI("/categories",{method:"GET"});json.success&&setCategories(json.response.data.data)};getCategories()},[fetchAPI]);let[showTotal,setShowTotal]=(0,react.useState)(showMoreAvailable?5:500),[fetching,setFetching]=(0,react.useState)(!1),[selectItemQuestions,setSelectItemQuestions]=(0,react.useState)([]),[selectedInterests,setSelectedInterests]=(0,react.useState)([]),[answersSaved,setAnswersSaved]=(0,react.useState)(!1);(0,react.useEffect)(()=>{setSelectItemQuestions(()=>{let mapQuestions=[...quiz.questions].map(question=>{let mapAnswers=question.answers.map(answer=>{var ref;let isAnswered=(null===(ref=question.user_answer)||void 0===ref?void 0:ref.answer_id)===answer.id;return{selected:isAnswered,title:answer.answer,id:answer.id}});return{id:question.id,title:question.title,answers:mapAnswers,image:question.image,profile_title:question.profile_title,tooltip:question.tooltip}});return mapQuestions})},[quiz.questions]);let[totalQuestions,setTotalQuestions]=(0,react.useState)(quiz.questions.length+3);(0,react.useEffect)(()=>{updateQuestionsCalc&&updateQuestionsCalc(totalQuestions,questionsAnswers.length)},[updateQuestionsCalc,totalQuestions,questionsAnswers]),(0,react.useEffect)(()=>{setTotalQuestions(quiz.questions.length+3)},[quiz.questions.length]);let showMoreHandler=()=>{setShowTotal(total=>{let updated=total+5;return updated>totalQuestions?totalQuestions:updated})},showLessHandler=()=>{setShowTotal(total=>{let updated=total-5;return updated<=5?5:updated})},updateQuestionItemsHandler=(id,updatedItems)=>{setSelectItemQuestions(questions=>[...questions].map(question=>{let isCurrentQuestion=id===question.id;return isCurrentQuestion?{...question,answers:updatedItems}:question}))},allQuestionsShown=showTotal===totalQuestions,[fetchingSubmitAnswer,setFetchingSubmitAnswer]=(0,react.useState)(!1),customInterestsUpdate=interests=>{setSelectedInterests(interests)},submitInterestsToServer=(0,react.useCallback)(async()=>{0!==selectedInterests.length&&(await fetchAPI("/user/interests",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({category_ids:selectedInterests})}),setUser(user=>{if(!user)return null;let makeInterestsArray=[];
1return selectedInterests.forEach(interestId=>{let find=categories.find(cat=>cat.id===interestId);find&&makeInterestsArray.push(find)}),{...user,profileData:user.profileData?{...user.profileData,interests:{categories:makeInterestsArray}}:null}}))},[fetchAPI,selectedInterests,setUser,categories]),checkSavedData=(0,react.useCallback)(()=>{submitInterestsToServer(),(birthday||city||state)&&(updateUserInfo({birthday:birthday?new Date(birthday):null,city:city||void 0,state:state||void 0}),setBirthday(null),setCity(""),setState(""))},[submitInterestsToServer,updateUserInfo,birthday,city,state]),submitAnswersToServer=(0,react.useCallback)(async()=>{if(fetchingSubmitAnswer)return;setFetchingSubmitAnswer(!0),checkSavedData();let json=await fetchAPI("/quiz/".concat(quiz.id,"/question/{question_id}/answer/{answer_id}"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(questionsAnswers)});json.success&&setQuiz(json.response.data),setFetchingSubmitAnswer(!1),submitCb&&submitCb()},[fetchingSubmitAnswer,checkSavedData,fetchAPI,quiz,questionsAnswers,setQuiz,submitCb]),isBtnDisabled=(0,react.useMemo)(()=>{let total=questionsAnswers.length+selectedInterests.length;return city&&total++,birthday&&total++,total<minQuestionsToAnswer},[questionsAnswers,selectedInterests,city,birthday,minQuestionsToAnswer]),submitQuestionsHandler=async()=>{!isBtnDisabled&&(fetching||(setFetching(!0),await submitHandler(),setFetching(!1)))};(0,react.useEffect)(()=>{let questionAnswer=[];selectItemQuestions.forEach(question=>{question.answers.forEach(answer=>{answer.selected&&questionAnswer.push({quiz_question_id:question.id,quiz_answer_id:answer.id})})}),setQuestionsAnswers(questionAnswer)},[selectItemQuestions]);let submitHandler=async()=>{if(!user){saveAnswersHandler();return}await submitAnswersToServer()},saveAnswersHandler=()=>{setAnswersSaved(!0),openAuthModal(1),updateSignUpLocation("money_quiz"),setAuthModalHeader("register-money-quiz")};(0,react.useEffect)(()=>{isLoggedIn&&answersSaved&&submitAnswersToServer()},[isLoggedIn,answersSaved,submitAnswersToServer]);let saveCityAndState=(city,state)=>{setCity(city),setState(state)},getSelectedInterests=()=>{var ref;let str="",interests=null==user?void 0:null===(ref=user.profileData)||void 0===ref?void 0:ref.interests.categories;return interests&&interests.forEach((category,index)=>{str+="".concat(category.name),interests.length>index+1&&(str+=", ")}),str},generateInputTitle=(title,src,tooltip)=>isProfilePage?(0,jsx_runtime.jsxs)("div",{className:"question-container",children:[(0,jsx_runtime.jsx)(Image.Z,{src:"interests"===src?"/svg/money-quiz/most-interested.svg":"city"===src?"/svg/money-quiz/state.svg":"date"===src?"/svg/money-quiz/birthday.svg":src,alt:"icon",width:24,height:24}),(0,jsx_runtime.jsx)(Text.X,{variation:"p",type:"small",className:"input__title",children:title}),tooltip&&(0,jsx_runtime.jsx)(UserQuestionTooltip,{tooltip:tooltip})]}):(0,jsx_runtime.jsx)(Text.X,{variation:"p",type:"small",className:"input__title",children:title}),interestsTitle=generateInputTitle(isProfilePage?"Iâm most interested in":"What Are You Most Interested In?","interests");return(0,jsx_runtime.jsxs)("div",{className:"userquestions",children:[(function(){if(0===selectItemQuestions.length)return[];let questionNodes=[],dynamicCount=0,totalIteration=selectItemQuestions.length+3,questionCount=0;for(;totalIteration>0;){var ref,ref1,ref2,ref3,ref4,ref5;if(0===dynamicCount)questionNodes.push((0,jsx_runtime.jsx)(jsx_runtime.Fragment,{children:editable?(0,jsx_runtime.jsx)(UserInterests.Z,{categories:categories,title:interestsTitle,container:"money-quiz-page"===type?"column":"row",withPreview:!1,customUpdate:customInterestsUpdate}):(0,jsx_runtime.jsx)(Inputs.fv,{container:"money-quiz-page"===type?"column":"row",title:interestsTitle,children:(0,jsx_runtime.jsx)("p",{className:"userquestions__answer ".concat((null==user?void 0:null===(ref=user.profileData)||void 0===ref?void 0:ref.interests.categories.length)===0?"userquestions__answer--noanswer":""),children:""!==getSelectedInterests()?getSelectedInterests():"Not complete"})},"userInterestsInput")}));else if(dynamicCount===CITY_POSITION)questionNodes.push((0,jsx_runtime.jsx)(Inputs.fv,{container:"money-quiz-page"===type?"column":"row",title:generateInputTitle(isProfilePage?"I live in the city":"What City Do You Live In?","city"),children:editable?(0,jsx_runtime.jsx)(CityInput.Z,{customUpdate:saveCityAndState}):(0,jsx_runtime.jsx)("p",{className:"userquestions__answer ".concat((null==user?void 0:null===(ref1=user.profileData)||void 0===ref1?void 0:ref1.city)?"":"userquestions__answer--noanswer"),children:(null==user?void 0:null===(ref2=user.profileData)||void 0===ref2?void 0:ref2.city)?"".concat(user.profileData.city||"").concat((null==user?void 0:null===(ref3=user.profileData)||void 0===ref3?void 0:ref3.state)?", ".concat(user.profileData.state):""):"Not complete"})},"cityInput"));else if(dynamicCount===DATE_POSITION)questionNodes.push((0,jsx_runtime.jsx)("div",{className:"userquestions__date",children:(0,jsx_runtime.jsx)(Inputs.fv,{container:"money-quiz-page"===type?"column":"row",title:generateInputTitle(isProfilePage?"My birthday is":"What's Your Birthday?","date"),children:editable?(0,jsx_runtime.jsx)(react_datepicker_min_default(),{selected:birthday||void 0,onChange:updateDateHandler,isClearable:!0,maxDate:new Date,peekNextMonth:!0,showMonthDropdown:!0,showYearDropdown:!0,dropdownMode:"select",placeholderText:"- Select -",dateFormat:"yyyy-MM-dd"}):(0,jsx_runtime.jsx)("p",{className:"userquestions__answer ".concat((null==user?void 0:null===(ref4=user.profileData)||void 0===ref4?void 0:ref4.birthday)?"":"userquestions__answer--noanswer"),children:(null==user?void 0:null===(ref5=user.profileData)||void 0===ref5?void 0:ref5.birthday)||"Not complete"})},"reactDatePicker")}));else{let{id,title,answers,image,profile_title,tooltip}=selectItemQuestions[questionCount],answeredQuestion=answers.find(answer=>answer.selected);questionNodes.push((0,jsx_runtime.jsx)(Inputs.fv,{container:"money-quiz-page"===type?"column":"row",title:generateInputTitle(isProfilePage?profile_title:title,image,tooltip),children:editable?(0,jsx_runtime.jsx)(Inputs.Ph,{items:answers,updateItems:updatedItems=>updateQuestionItemsHandler(id,updatedItems)}):(0,jsx_runtime.jsx)("p",{className:"userquestions__answer ".concat(answeredQuestion?"":"userquestions__answer--noanswer"),children:answeredQuestion?answeredQuestion.title:"Not complete"})},id)),questionCount++}dynamicCount++,totalIteration--}return questionNodes})().map((question,index)=>showTotal>index?question:null),(0,jsx_runtime.jsxs)("div",{className:"userquestions__action",children:[showMoreAvailable&&(0,jsx_runtime.jsx)("button",{className:"userquestions__action--btn",type:"button",onClick:()=>allQuestionsShown?showLessHandler():showMoreHandler(),children:allQuestionsShown?"- Show Less Questions":"+ Show More Questions"}),extraText&&(0,jsx_runtime.jsx)("p",{children:extraText}),showSubmitBtn&&(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[(0,jsx_runtime.jsx)(Inputs.zx,{variation:"primary",onClick:submitQuestionsHandler,disabled:isBtnDisabled,children:fetching?"Loading...":buttonTitle}),(0,jsx_runtime.jsx)("p",{className:"userquestions__action--extra",children:buttonExtraText})]})]})]})};var Account_UserQuestions=UserQuestions}}]);
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.