{"version":3,"file":"survey_page--VM1n3v6.js","sources":["../../app/javascript/components/surveys/shared/use_survey_question.ts","../../app/javascript/components/surveys/shared/validation/question_error_item.tsx","../../app/javascript/components/surveys/shared/validation/notification_for_question_errors.tsx","../../app/javascript/components/surveys/shared/validation/use_survey_validation.tsx","../../app/javascript/components/surveys/survey_page.tsx"],"sourcesContent":["import { useQuery } from \"urql\";\nimport {\n PostSessionSurveyCareerQuestionDocument,\n Survey,\n SurveyQuestionTemplateId,\n} from \"../../generated/graphql\";\nimport useRotatingQuestionIndex from \"../questions/hooks/useRotatingQuestion\";\nimport { SurveyAudienceContext } from \"../survey_page\";\nimport { getRotatingCareerOpenResponseQuestions } from \"../questions/rotating_career_open_response\";\n\nexport function useSurveyQuestion(\n question: Survey[\"questions\"][0],\n surveyAudienceContext?: SurveyAudienceContext\n) {\n const rotatingTemplatesIds = [\n SurveyQuestionTemplateId.RotatingOpenResponse,\n SurveyQuestionTemplateId.RotatingLikert,\n SurveyQuestionTemplateId.RotatingCareerOpenResponse,\n ];\n\n // Rotating career open response nonsense starts here //\n // This is necessary because unlike all other question types in the DB, the rotating career open response\n // question has hard-coded options in the FE.\n const questionIsCareerOpenResponse =\n question.template.templateId === SurveyQuestionTemplateId.RotatingCareerOpenResponse;\n\n const [{ fetching: fetchingSurveyAudienceEntities, data: surveyAudienceEntities }] = useQuery({\n query: PostSessionSurveyCareerQuestionDocument,\n variables: {\n participantId: surveyAudienceContext?.participantId ?? \"\",\n mentorshipId: surveyAudienceContext?.mentorshipId ?? \"\",\n },\n pause: !questionIsCareerOpenResponse || !surveyAudienceContext,\n });\n const careerRotatingQuestions =\n questionIsCareerOpenResponse && surveyAudienceEntities\n ? getRotatingCareerOpenResponseQuestions(\n surveyAudienceEntities?.participant,\n surveyAudienceEntities?.mentorship\n )\n : [];\n // Rotating career open response nonsense ends here /\n\n const numberOfRotatingQuestions =\n questionIsCareerOpenResponse && surveyAudienceEntities\n ? careerRotatingQuestions.length\n : question.customizations?.rotatingQuestions?.length;\n\n const { fetching: fetchingRotatingIndex, questionIndex } = useRotatingQuestionIndex({\n numberOfQuestions: numberOfRotatingQuestions,\n pause: !rotatingTemplatesIds.includes(question.template.templateId),\n surveyAudienceContext,\n });\n\n const getQuestionLabel = () => {\n switch (question.template.templateId) {\n case SurveyQuestionTemplateId.CounterpartsInfo:\n case SurveyQuestionTemplateId.DatePicker:\n case SurveyQuestionTemplateId.Flags:\n case SurveyQuestionTemplateId.Likert:\n case SurveyQuestionTemplateId.MentorshipChatGroupStudentSelect:\n case SurveyQuestionTemplateId.MultiSelect:\n case SurveyQuestionTemplateId.MultiSelectDropdown:\n case SurveyQuestionTemplateId.Nps:\n case SurveyQuestionTemplateId.NumberInput:\n case SurveyQuestionTemplateId.OpenResponse:\n case SurveyQuestionTemplateId.Select:\n case SurveyQuestionTemplateId.SelectWithSelectFollowUp: {\n return question.customizations.prompt;\n }\n case SurveyQuestionTemplateId.Generic: {\n return question.customizations.text;\n }\n case SurveyQuestionTemplateId.RotatingCareerOpenResponse: {\n return questionIndex !== undefined &&\n careerRotatingQuestions[questionIndex] !== undefined &&\n !fetchingRotatingIndex &&\n !fetchingSurveyAudienceEntities\n ? careerRotatingQuestions[questionIndex].prompt\n : \"Question\";\n }\n case SurveyQuestionTemplateId.RotatingLikert:\n case SurveyQuestionTemplateId.RotatingOpenResponse: {\n return fetchingRotatingIndex || questionIndex === undefined\n ? \"Question\"\n : question.customizations.rotatingQuestions[questionIndex].prompt;\n }\n case SurveyQuestionTemplateId.Conversation: {\n return (\n question.customizations.modeOfCommunicationPrompt ?? question.customizations.topicsPrompt\n );\n }\n case SurveyQuestionTemplateId.MentorshipChatGroupOptionalStudentInfo: {\n return question.customizations.yesNoPrompt;\n }\n default: {\n return question.customizations.prompt;\n }\n }\n };\n\n return {\n getQuestionLabel,\n };\n}\n","import React from \"react\";\nimport { useSurveyQuestion } from \"../use_survey_question\";\nimport { Survey } from \"../../../generated/graphql\";\nimport { SurveyAudienceContext } from \"../../survey_page\";\n\nconst TRUNCATE_LIMIT = 150;\n\nconst trailingEllipsis = (str: string) => {\n return str.length > TRUNCATE_LIMIT ? \"...\" : \"\";\n};\n\nexport default function QuestionErrorItem({\n question,\n surveyAudienceContext,\n}: {\n question: Survey[\"questions\"][\"0\"];\n // This is only needed because of the rotatingCareerOpenResponse question, which\n // hard codes the list of question in the FE and uses this object to determine which questions are\n // available to the user. All other questions have this information stored in the metadata of the\n // customizations column. A plague on the house of rotatingCareerOpenResponse.\n surveyAudienceContext?: SurveyAudienceContext;\n}) {\n const { getQuestionLabel } = useSurveyQuestion(question, surveyAudienceContext);\n\n // TODO: enable click to scroll\n // const handleScrollToQuestion = () => {\n // const element = document.getElementById(question.id);\n // element?.scrollIntoView({ behavior: \"smooth\", block: \"center\", inline: \"nearest\" });\n // };\n\n return (\n