Skip to content

Commit

Permalink
feat(tt): record individual survey answers
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtaholik committed Oct 24, 2024
1 parent 224e6cd commit 209b79f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions apps/total-typescript/src/pages/survey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const SurveyPageWrapper: React.FC = () => {
machineState,
} = useSurveyPageOfferMachine(TYPESCRIPT_2024_SURVEY_ID)

const answerSurveyMutation =
const answerSurveyMutation = trpc.convertkit.answerSurvey.useMutation()
const answerSurveyMultipleMutation =
trpc.convertkit.answerSurveyMultiple.useMutation()
const [email, setEmail] = React.useState<string | null>(null)

Expand All @@ -35,7 +36,7 @@ const SurveyPageWrapper: React.FC = () => {

React.useEffect(() => {
if (isComplete && machineState.matches('offerComplete')) {
answerSurveyMutation.mutate({
answerSurveyMultipleMutation.mutate({
email: email || subscriber?.email_address,
answers,
surveyId: TYPESCRIPT_2024_SURVEY_ID,
Expand All @@ -60,7 +61,15 @@ const SurveyPageWrapper: React.FC = () => {
<SurveyPage
currentQuestionId={currentQuestionId}
currentQuestion={currentQuestion as QuestionResource}
handleSubmitAnswer={handleSubmitAnswer}
handleSubmitAnswer={async (context) => {
if (email || subscriber?.email_address) {
answerSurveyMutation.mutate({
answer: context.answer,
question: context.currentQuestionId,
})
}
await handleSubmitAnswer(context)
}}
surveyConfig={typescript2024SurveyConfig}
sendToMachine={sendToMachine}
isComplete={isComplete}
Expand Down

0 comments on commit 209b79f

Please sign in to comment.