11import React from 'react' ;
22import Link from 'next/link' ;
3- import { Card , Button , Divider , Form , Message } from 'semantic-ui-react' ;
3+ import { Card , Button , Divider } from 'semantic-ui-react' ;
44
5- import { baseEventsURL , indexPageEventURL , subscribeURL } from '../utils/urls' ;
5+ import { baseEventsURL , indexPageEventURL } from '../utils/urls' ;
66import RowEvent from '../components/row-events' ;
77import publicPage from '../hocs/public-page' ;
8+ import Subscribe from '../components/subscribe' ;
89
910const indexPageLearns = [
1011 {
@@ -53,10 +54,6 @@ const indexPageLearns = [
5354class Home extends React . Component {
5455 state = {
5556 indexPageEvent : '' ,
56- subscribersEmail : '' ,
57- submittingEmail : false ,
58- emailSubmittingError : '' ,
59- subscriberEmailPosted : false ,
6057 } ;
6158
6259 async componentDidMount ( ) {
@@ -71,56 +68,6 @@ class Home extends React.Component {
7168 }
7269 }
7370
74- handleChange = event => {
75- this . setState ( {
76- subscribersEmail : event . target . value ,
77- emailSubmittingError : '' ,
78- } ) ;
79- } ;
80-
81- handleSubmit = ( ) => {
82- this . setState ( { emailSubmittingError : '' } ) ;
83- const emailRegx = / ^ ( ( [ ^ < > ( ) [ \] \\ . , ; : \s @ " ] + ( \. [ ^ < > ( ) [ \] \\ . , ; : \s @ " ] + ) * ) | ( " .+ " ) ) @ ( ( \[ [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } ] ) | ( ( [ a - z A - Z \- 0 - 9 ] + \. ) + [ a - z A - Z ] { 2 , } ) ) $ / ;
84- const email = this . state . subscribersEmail ;
85- if ( ! email ) {
86- this . setState ( {
87- emailSubmittingError : 'Please enter a email' ,
88- } ) ;
89- return ;
90- }
91- if ( ! emailRegx . test ( email ) ) {
92- this . setState ( {
93- emailSubmittingError : 'Please enter a valid email' ,
94- } ) ;
95- return ;
96- }
97- this . postSubscriberEmail ( email ) ;
98- } ;
99-
100- async postSubscriberEmail ( subscribersEmail ) {
101- await this . setState ( { submittingEmail : true } ) ;
102- const postSubscriberEmailRequest = await fetch (
103- `${ baseEventsURL } ${ subscribeURL } ` ,
104- {
105- method : 'post' ,
106- headers : { 'Content-Type' : 'application/json' } ,
107- body : JSON . stringify ( { email : subscribersEmail } ) ,
108- } ,
109- ) ;
110- if ( postSubscriberEmailRequest . status === 200 ) {
111- this . setState ( {
112- subscriberEmailPosted : true ,
113- submittingEmail : false ,
114- emailSubmittingError : '' ,
115- } ) ;
116- } else {
117- this . setState ( {
118- submittingEmail : false ,
119- emailSubmittingError : 'Submission Failed Try Again.' ,
120- } ) ;
121- }
122- }
123-
12471 render ( ) {
12572 return (
12673 < div >
@@ -238,46 +185,7 @@ class Home extends React.Component {
238185 </ Button . Group >
239186 </ div >
240187 </ section >
241- < section className = "update" >
242- < div className = "container update_container" >
243- < h3 className = "taglines" >
244- We are constanly updating our platform.< br /> If you would like
245- to stay informed about our updates, drop you email.
246- </ h3 >
247- < div className = "update_content" >
248- { this . state . subscriberEmailPosted ? (
249- < h2 > Thank you, we will keep you posted</ h2 >
250- ) : (
251- < Form
252- onSubmit = { this . handleSubmit }
253- error = { this . state . emailSubmittingError }
254- >
255- < Form . Group >
256- < Form . Input
257- placeholder = "Enter email address"
258- name = "email"
259- value = { this . state . subscribersEmail }
260- onChange = { this . handleChange }
261- disabled = { this . state . submittingEmail }
262- />
263- < Form . Button
264- loading = { this . state . submittingEmail }
265- color = "pink"
266- content = "Subscribe"
267- />
268- </ Form . Group >
269- { this . state . emailSubmittingError && (
270- < Message
271- error
272- header = "Action Forbidden"
273- content = { this . state . emailSubmittingError }
274- />
275- ) }
276- </ Form >
277- ) }
278- </ div >
279- </ div >
280- </ section >
188+ < Subscribe />
281189 </ main >
282190 < style jsx > { `
283191 main {
@@ -333,17 +241,7 @@ class Home extends React.Component {
333241 .discord .container {
334242 background: #FAFAFA;
335243 }
336- .update_container{
337- background-color: #f6f6f6;
338- }
339- .update_content {
340- display: flex;
341- flex-direction: row;
342- flex-wrap: wrap;
343- justify-content: center;
344- align-content: center;
345- align-items: center;
346- }
244+
347245 ` } </ style >
348246 </ div >
349247 ) ;
0 commit comments