pineafan | a0e4b9b | 2021-11-02 21:10:49 +0000 | [diff] [blame] | 1 | import Header from '../../Components/Header' |
| 2 | import { Component } from 'react' |
| 3 | import Styles from '../../styles/clicksforms/form.module.css'; |
pineafan | a0e4b9b | 2021-11-02 21:10:49 +0000 | [diff] [blame] | 4 | import Question from '../../Components/ClicksForms/Question'; |
| 5 | |
| 6 | export default class Form extends Component { |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 7 | constructor(props) { |
| 8 | super(props); |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 9 | } |
pineafan | a0e4b9b | 2021-11-02 21:10:49 +0000 | [diff] [blame] | 10 | |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 11 | render() { |
| 12 | return ( |
| 13 | <> |
pineafan | a0e4b9b | 2021-11-02 21:10:49 +0000 | [diff] [blame] | 14 | <Header |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 15 | name={this.props.name} |
| 16 | subtext={this.props.description + (this.props.active ? '' : <><br />this.props is not accepting responses. Please check back later</>)} |
pineafan | a0e4b9b | 2021-11-02 21:10:49 +0000 | [diff] [blame] | 17 | gradient={["71AFE5", "6576CC"]} |
pineafan | a841c76 | 2021-11-14 21:21:04 +0000 | [diff] [blame] | 18 | wave="web/waves/header/clicksforms" |
pineafan | a0e4b9b | 2021-11-02 21:10:49 +0000 | [diff] [blame] | 19 | buttons={[]} |
| 20 | /> |
pineafan | a0e4b9b | 2021-11-02 21:10:49 +0000 | [diff] [blame] | 21 | <div className={Styles.form}> |
| 22 | <div className={Styles.header}> |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 23 | Once completing this.props, your response will be recorded |
| 24 | {this.props.anonymous ? " and your name will not be shown" : " and your username will be visible"} |
pineafan | a0e4b9b | 2021-11-02 21:10:49 +0000 | [diff] [blame] | 25 | </div> |
| 26 | <div className={Styles.body}> |
| 27 | { |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 28 | this.props.questions.map((question, index) => { |
pineafan | a0e4b9b | 2021-11-02 21:10:49 +0000 | [diff] [blame] | 29 | return ( |
| 30 | <> |
| 31 | <Question |
| 32 | key={index} |
| 33 | title={question.title} |
| 34 | description={question.description} |
| 35 | colour={question.colour} |
| 36 | type={question.type} |
| 37 | options={question.options} |
| 38 | required={question.required} |
| 39 | /> |
| 40 | </> |
| 41 | ) |
| 42 | }) |
| 43 | } |
| 44 | </div> |
| 45 | </div> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 46 | </> |
| 47 | ) |
| 48 | } |
pineafan | a0e4b9b | 2021-11-02 21:10:49 +0000 | [diff] [blame] | 49 | } |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 50 | |
| 51 | export async function getServerSideProps(ctx) { |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 52 | if(!ctx.query.code) { |
| 53 | return { |
| 54 | redirect: { |
| 55 | destination: '/clicksforms/error/nocode', |
| 56 | permanent: true |
| 57 | } |
| 58 | } |
| 59 | } |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 60 | const code = fetch(`https://cf.bots.clicks.codes/code/${ctx.query.code}/token/BkjTUmNPk8S1aPVIYBt8rAUGQF692C8BEscJS9jGDwEtDJcy78uCVsHgRI1dspseGFoatakhWPHTAmYH42zhPpOjoaN1N9eLU7hB`, { |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 61 | method: "GET", |
| 62 | mode: "cors" |
| 63 | }) |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame^] | 64 | if ( (await code).status === 404 ) { |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 65 | return { |
| 66 | redirect: { |
| 67 | destination: '/clicksforms/error/deleted', |
| 68 | permanent: true |
| 69 | } |
| 70 | } |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame^] | 71 | } else if ( code.status !== 200 ) { |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 72 | return { |
| 73 | redirect: { |
| 74 | destination: '/clicksforms/error/unknown', |
| 75 | permanent: true |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 80 | return { |
| 81 | props: { |
| 82 | data: code.data |
| 83 | } |
| 84 | } |
| 85 | } |