Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
swizec.com/src/components/TypeformResponse.js /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
50 lines (43 sloc)
1.38 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react" | |
| function getAnswer(question, answers) { | |
| return answers.find((answer) => answer.field.title === question) | |
| } | |
| const JobTitle = ({ answers }) => { | |
| const answer = getAnswer("What’s your job level?", answers) | |
| return answer?.choice ? <>from a {answer.choice.label}</> : null | |
| } | |
| const QuestionAnswer = ({ question, answers }) => { | |
| const answer = getAnswer(question, answers) | |
| return answer?.text ? ( | |
| <> | |
| <strong>{answer.field.title}</strong> | |
| <p>{answer.text}</p> | |
| </> | |
| ) : null | |
| } | |
| export const TypeformResponse = ({ answers }) => { | |
| const rating = getAnswer("Are you enjoying the Swizec’s Newsletter?", answers) | |
| const stars = rating?.number ? new Array(rating.number).fill(0) : [] | |
| const questions = [ | |
| "What hesitation did you have about subscribing?", | |
| "What did you learn from Swizec’s Newsletter?", | |
| "What do you like most about the Swizec’s Newsletter?", | |
| "What are some other benefits you got from Swizec’s Newsletter?", | |
| "Would you recommend Swizec’s Newsletter to a friend? Why?", | |
| ] | |
| return ( | |
| <> | |
| <h3> | |
| {stars.map((i) => ( | |
| <span role="img" key={i}> | |
| ⭐️ | |
| </span> | |
| ))}{" "} | |
| <JobTitle answers={answers} /> | |
| </h3> | |
| {questions.map((question, i) => ( | |
| <QuestionAnswer question={question} answers={answers} key={i} /> | |
| ))} | |
| </> | |
| ) | |
| } |