From ab18c0b5caf882ebdd1ac1c60f29a78e8612b9c3 Mon Sep 17 00:00:00 2001 From: harshithpabbati Date: Fri, 11 Oct 2019 00:45:00 +0530 Subject: [PATCH] Add RSVP Form in MLH --- .../mlh-hack-day/components/registration.js | 73 +----------- .../mlh-hack-day/components/rsvpForm.js | 109 ++++++++++++++++++ src/events/mlh-hack-day/index.js | 28 ++++- src/pages/index.js | 2 +- 4 files changed, 134 insertions(+), 78 deletions(-) create mode 100644 src/events/mlh-hack-day/components/rsvpForm.js diff --git a/src/events/mlh-hack-day/components/registration.js b/src/events/mlh-hack-day/components/registration.js index 7e09476..26a5f16 100644 --- a/src/events/mlh-hack-day/components/registration.js +++ b/src/events/mlh-hack-day/components/registration.js @@ -112,78 +112,7 @@ class Registration extends React.Component {

{this.state.count} Already Registered.
{this.state.count < 60 ? <>{this.state.slotsLeft>=0 ? this.state.slotsLeft: 0} Slots Left.
: <> Join the WaitList
} - Register Now

-

- Sign up for the MLH Local Hack Day: Learn for free by filling up the form below, - and make sure you do that fast as we have very limited seats to fit you - all in! Also, don't forget to bring in your friends as well :) -

-

* Meetup only open for students of Amritapuri Campus

-
{ - this.setState({loading: true}); - this.register(); - e.preventDefault(); - }}> -
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
- -
-
- { - this.state.errorText !== '' ? -
- {this.state.errorText} -
: null - } -
-
- -
-
-
- + RSVP Now
) : this.state.successText !== '' ? this.state.status === "U" ? (
diff --git a/src/events/mlh-hack-day/components/rsvpForm.js b/src/events/mlh-hack-day/components/rsvpForm.js new file mode 100644 index 0000000..9b69927 --- /dev/null +++ b/src/events/mlh-hack-day/components/rsvpForm.js @@ -0,0 +1,109 @@ +import React from 'react'; +import dataFetch from "../../../utils/dataFetch"; + +const query = ` +mutation($formID: Int!, $hash: String!,$phone: String!, $response: Boolean!) +{ + submitRSVP(formID:$formID, hash: $hash, phone: $phone, response: $response) + { + status + } +} +` + +class RSVPForm extends React.Component { + constructor(props) { + super(props) + this.state = { + phone: '', + response: true, + loading: false, + successText: '', + errorText: '' + } + } + submit = async() => + { + const variables = { + 'formID': 2, + 'hash': this.props.hash, + 'phone': this.state.phone, + 'response': this.state.response + }; + const response = await dataFetch({ query, variables }); + if (Object.prototype.hasOwnProperty.call(response, 'errors')) { + this.setState({ loading: false, errorText: response.errors[0].message}); + } else { + this.setState({ + successText: response.data.submitRSVP.status, + errorText: '' + }) + } + } + + render() { + return( +
+
+

RSVP for MLH Local Hack Day 2019, Amritapuri

+

+ Thank you so much for showing interest in Local Hack Day, + organized by amFOSS, in association with MLH. +

+
+ If you are facing any technical issues, or if your friend didn't recieve + a confirmation email yet, please ping +91 8139056887 on Telegram/WhatsApp. + We are sorry for any inconvenience caused. +
+ {!this.state.loading ? +
{ + this.setState({ loading: true }); + this.submit(); + }} + className="form-group"> +
+
+ + +
+
+ + this.setState({ phone: e.currentTarget.value })} + /> +
+
+ +
+
+
: this.state.successText !== '' ? +
Thank you! Please inform your friends too about submitting their RSVP.
+ :
Submitting. Please Wait
+ } + { + this.state.errorText !== '' ? +
+ {this.state.errorText} +
: null + } +
+
+ ) + } +} + +export default RSVPForm; \ No newline at end of file diff --git a/src/events/mlh-hack-day/index.js b/src/events/mlh-hack-day/index.js index aa1b8b8..d1266bf 100644 --- a/src/events/mlh-hack-day/index.js +++ b/src/events/mlh-hack-day/index.js @@ -1,19 +1,37 @@ -import React from "react" +import React, { useState, useEffect } from "react" import SEO from "../../components/seo" import Header from "./components/header" import Registration from "./components/registration" import "../mlh-hack-day/styles/style.sass" import Countdown from "./components/countdown" +import RSVPForm from "./components/rsvpForm" import Footer from "./components/footer" const MLH = () => { + const [hash, setHash] = useState(''); + const [queryLoaded, setQueryLoaded] = useState(false); + + useEffect(() => { + if(!queryLoaded) + { + const query = window.location.search.substring(1); + const queryHash = query.split("=") + setHash(queryHash[1]) + setQueryLoaded(true) + } + }) + return(
-
- - -
) } diff --git a/src/pages/index.js b/src/pages/index.js index 12a4fbb..78cb52d 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -3,7 +3,7 @@ import { navigate } from "gatsby" const IndexPage = () => { useEffect(() => { - navigate('/hacktoberfest/') + navigate('/mlh/') }, []) return null; }