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 | a465f35 | 2023-02-05 16:45:01 +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={[]} |
PineaFan | a465f35 | 2023-02-05 16:45:01 +0000 | [diff] [blame] | 20 | season={this.props.season} |
pineafan | a0e4b9b | 2021-11-02 21:10:49 +0000 | [diff] [blame] | 21 | /> |
pineafan | a0e4b9b | 2021-11-02 21:10:49 +0000 | [diff] [blame] | 22 | <div className={Styles.form}> |
| 23 | <div className={Styles.header}> |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 24 | Once completing this.props, your response will be recorded |
| 25 | {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] | 26 | </div> |
| 27 | <div className={Styles.body}> |
| 28 | { |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 29 | this.props.questions.map((question, index) => { |
pineafan | a0e4b9b | 2021-11-02 21:10:49 +0000 | [diff] [blame] | 30 | return ( |
| 31 | <> |
| 32 | <Question |
| 33 | key={index} |
| 34 | title={question.title} |
| 35 | description={question.description} |
| 36 | colour={question.colour} |
| 37 | type={question.type} |
| 38 | options={question.options} |
| 39 | required={question.required} |
| 40 | /> |
| 41 | </> |
| 42 | ) |
| 43 | }) |
| 44 | } |
| 45 | </div> |
| 46 | </div> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 47 | </> |
| 48 | ) |
| 49 | } |
pineafan | a0e4b9b | 2021-11-02 21:10:49 +0000 | [diff] [blame] | 50 | } |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 51 | |
| 52 | export async function getServerSideProps(ctx) { |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 53 | if(!ctx.query.code) { |
| 54 | return { |
| 55 | redirect: { |
| 56 | destination: '/clicksforms/error/nocode', |
| 57 | permanent: true |
| 58 | } |
| 59 | } |
| 60 | } |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 61 | 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] | 62 | method: "GET", |
| 63 | mode: "cors" |
| 64 | }) |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 65 | if ( (await code).status === 404 ) { |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 66 | return { |
| 67 | redirect: { |
| 68 | destination: '/clicksforms/error/deleted', |
| 69 | permanent: true |
| 70 | } |
| 71 | } |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 72 | } else if ( code.status !== 200 ) { |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 73 | return { |
| 74 | redirect: { |
| 75 | destination: '/clicksforms/error/unknown', |
| 76 | permanent: true |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame] | 81 | return { |
| 82 | props: { |
| 83 | data: code.data |
| 84 | } |
| 85 | } |
| 86 | } |