11<template >
22 <div class =" py-5 px-8" >
33 <div v-if =" loading" class =" flex justify-center" >Loading...</div >
4- <form @submit.prevent =" submitSurvey" v-else >
5- <div class =" grid grid-cols-4 " >
4+ <form @submit.prevent =" submitSurvey" v-else class = " container mx-auto " >
5+ <div class =" grid grid-cols-6 items-center " >
66 <div class =" mr-4" >
77 <img :src =" survey.image_url" alt =" " />
88 </div >
9- <div class =" col-span-3" >
10- <h1 class =" text-3xl" >{{ survey.title }}</h1 >
9+ <div class =" col-span-5" >
10+ <h1 class =" text-3xl mb-3" >{{ survey.title }}</h1 >
11+ <p class =" text-gray-500 text-sm" v-html =" survey.description" ></p >
1112 </div >
1213 </div >
13- <div v-for =" (question, ind) of survey.questions" :key =" question.id" >
14- <QuestionViewer v-model =" questions[question.id]" :question =" question" :index =" ind" />
14+
15+ <div v-if =" surveyFinished" class =" py-8 px-6 bg-emerald-400 text-white w-[600px] mx-auto" >
16+ <div class =" text-xl mb-3 font-semibold " >Thank you for participating in this survey.</div >
17+ <button @click =" submitAnotherResponse" type =" button" class =" inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" >
18+ Submit another response
19+ </button >
1520 </div >
21+ <div v-else >
22+ <hr class =" my-3" >
23+ <div v-for =" (question, ind) of survey.questions" :key =" question.id" >
24+ <QuestionViewer
25+ v-model =" answers[question.id]"
26+ :question =" question"
27+ :index =" ind"
28+ />
29+ </div >
1630
17- <button
18- type =" submit"
19- class =" inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
20- >
21- Submit
22- </button >
31+ <button
32+ type =" submit"
33+ class =" inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
34+ >
35+ Submit
36+ </button >
37+ </div >
2338 </form >
2439 </div >
2540</template >
@@ -35,12 +50,29 @@ const store = useStore();
3550const loading = computed (() => store .state .currentSurvey .loading );
3651const survey = computed (() => store .state .currentSurvey .data );
3752
38- const questions = ref ({});
53+ const surveyFinished = ref (false );
54+
55+ const answers = ref ({});
3956
4057store .dispatch (" getSurveyBySlug" , route .params .slug );
4158
4259function submitSurvey () {
43- console .log (JSON .stringify (questions .value , undefined , 2 ));
60+ console .log (JSON .stringify (answers .value , undefined , 2 ));
61+ store
62+ .dispatch (" saveSurveyAnswer" , {
63+ surveyId: survey .value .id ,
64+ answers: answers .value ,
65+ })
66+ .then ((response ) => {
67+ if (response .status === 201 ) {
68+ surveyFinished .value = true ;
69+ }
70+ });
71+ }
72+
73+ function submitAnotherResponse () {
74+ answers .value = {};
75+ surveyFinished .value = false ;
4476}
4577 </script >
4678
0 commit comments