blob: aa1b032d13b235579856c97c9f28c8a14810741b [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);
pineafanf97734b2021-11-23 21:11:00 +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={[]}
20 />
pineafana0e4b9b2021-11-02 21:10:49 +000021 <div className={Styles.form}>
22 <div className={Styles.header}>
pineafanf97734b2021-11-23 21:11:00 +000023 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"}
pineafana0e4b9b2021-11-02 21:10:49 +000025 </div>
26 <div className={Styles.body}>
27 {
pineafanf97734b2021-11-23 21:11:00 +000028 this.props.questions.map((question, index) => {
pineafana0e4b9b2021-11-02 21:10:49 +000029 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>
pineafanaa9c4fd2022-06-10 19:58:10 +010046 </>
47 )
48 }
pineafana0e4b9b2021-11-02 21:10:49 +000049}
pineafanf97734b2021-11-23 21:11:00 +000050
51export async function getServerSideProps(ctx) {
pineafanf97734b2021-11-23 21:11:00 +000052 if(!ctx.query.code) {
53 return {
54 redirect: {
55 destination: '/clicksforms/error/nocode',
56 permanent: true
57 }
58 }
59 }
pineafanff3d4522022-05-06 19:51:02 +010060 const code = fetch(`https://cf.bots.clicks.codes/code/${ctx.query.code}/token/BkjTUmNPk8S1aPVIYBt8rAUGQF692C8BEscJS9jGDwEtDJcy78uCVsHgRI1dspseGFoatakhWPHTAmYH42zhPpOjoaN1N9eLU7hB`, {
pineafanf97734b2021-11-23 21:11:00 +000061 method: "GET",
62 mode: "cors"
63 })
pineafan9babd752022-10-21 21:47:52 +010064 if ( (await code).status === 404 ) {
pineafanf97734b2021-11-23 21:11:00 +000065 return {
66 redirect: {
67 destination: '/clicksforms/error/deleted',
68 permanent: true
69 }
70 }
pineafan9babd752022-10-21 21:47:52 +010071 } else if ( code.status !== 200 ) {
pineafanf97734b2021-11-23 21:11:00 +000072 return {
73 redirect: {
74 destination: '/clicksforms/error/unknown',
75 permanent: true
76 }
77 }
78 }
79
pineafanf97734b2021-11-23 21:11:00 +000080 return {
81 props: {
82 data: code.data
83 }
84 }
85}