blob: 38cfcb537104addc6e402516a3c690fbef9eba43 [file] [log] [blame]
pineafana0e4b9b2021-11-02 21:10:49 +00001import Header from '../../Components/Header'
2import { Component } from 'react'
3import Styles from '../../styles/clicksforms/form.module.css';
pineafana0e4b9b2021-11-02 21:10:49 +00004import Question from '../../Components/ClicksForms/Question';
5
6export default class Form extends Component {
pineafanaa9c4fd2022-06-10 19:58:10 +01007 constructor(props) {
8 super(props);
PineaFana465f352023-02-05 16:45:01 +00009 }
pineafana0e4b9b2021-11-02 21:10:49 +000010
pineafanaa9c4fd2022-06-10 19:58:10 +010011 render() {
12 return (
13 <>
pineafana0e4b9b2021-11-02 21:10:49 +000014 <Header
pineafanf97734b2021-11-23 21:11:00 +000015 name={this.props.name}
16 subtext={this.props.description + (this.props.active ? '' : <><br />this.props is not accepting responses. Please check back later</>)}
pineafana0e4b9b2021-11-02 21:10:49 +000017 gradient={["71AFE5", "6576CC"]}
pineafana841c762021-11-14 21:21:04 +000018 wave="web/waves/header/clicksforms"
pineafana0e4b9b2021-11-02 21:10:49 +000019 buttons={[]}
PineaFana465f352023-02-05 16:45:01 +000020 season={this.props.season}
pineafana0e4b9b2021-11-02 21:10:49 +000021 />
pineafana0e4b9b2021-11-02 21:10:49 +000022 <div className={Styles.form}>
23 <div className={Styles.header}>
pineafanf97734b2021-11-23 21:11:00 +000024 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"}
pineafana0e4b9b2021-11-02 21:10:49 +000026 </div>
27 <div className={Styles.body}>
28 {
pineafanf97734b2021-11-23 21:11:00 +000029 this.props.questions.map((question, index) => {
pineafana0e4b9b2021-11-02 21:10:49 +000030 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>
pineafanaa9c4fd2022-06-10 19:58:10 +010047 </>
48 )
49 }
pineafana0e4b9b2021-11-02 21:10:49 +000050}
pineafanf97734b2021-11-23 21:11:00 +000051
52export async function getServerSideProps(ctx) {
pineafanf97734b2021-11-23 21:11:00 +000053 if(!ctx.query.code) {
54 return {
55 redirect: {
56 destination: '/clicksforms/error/nocode',
57 permanent: true
58 }
59 }
60 }
pineafanff3d4522022-05-06 19:51:02 +010061 const code = fetch(`https://cf.bots.clicks.codes/code/${ctx.query.code}/token/BkjTUmNPk8S1aPVIYBt8rAUGQF692C8BEscJS9jGDwEtDJcy78uCVsHgRI1dspseGFoatakhWPHTAmYH42zhPpOjoaN1N9eLU7hB`, {
pineafanf97734b2021-11-23 21:11:00 +000062 method: "GET",
63 mode: "cors"
64 })
pineafan9babd752022-10-21 21:47:52 +010065 if ( (await code).status === 404 ) {
pineafanf97734b2021-11-23 21:11:00 +000066 return {
67 redirect: {
68 destination: '/clicksforms/error/deleted',
69 permanent: true
70 }
71 }
pineafan9babd752022-10-21 21:47:52 +010072 } else if ( code.status !== 200 ) {
pineafanf97734b2021-11-23 21:11:00 +000073 return {
74 redirect: {
75 destination: '/clicksforms/error/unknown',
76 permanent: true
77 }
78 }
79 }
80
pineafanf97734b2021-11-23 21:11:00 +000081 return {
82 props: {
83 data: code.data
84 }
85 }
86}