aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/components/forms/subscribe_form.tsx
blob: 8bb0f4fc77e35160e0aed41fd9ac6be09730582c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { colors } from '@0xproject/react-shared';
import * as React from 'react';

import RaisedButton from 'material-ui/RaisedButton';
import { backendClient } from 'ts/utils/backend_client';

export interface SubscribeFormProps {}

export enum SubscribeFormStatus {
    None,
    Error,
    Success,
    Loading,
}

export interface SubscribeFormState {
    emailText: string;
    status: SubscribeFormStatus;
}

export class SubscribeForm extends React.Component<SubscribeFormProps, SubscribeFormState> {
    public state = {
        emailText: '',
        status: SubscribeFormStatus.None,
    };
    public render(): React.ReactNode {
        return (
            <div>
                Subscribe to our newsletter for 0x relayer and dApp updates
                <div>
                    <input value={this.state.emailText} onChange={this._handleEmailInputChange.bind(this)} />
                    <RaisedButton
                        labelStyle={{
                            textTransform: 'none',
                            fontSize: 15,
                            fontWeight: 400,
                        }}
                        buttonStyle={{
                            borderRadius: 6,
                        }}
                        style={{
                            boxShadow: '0px 0px 4px rgba(0, 0, 0, 0.25)',
                            borderRadius: 6,
                            height: 48,
                            width: 120,
                        }}
                        labelColor="white"
                        backgroundColor="#252525"
                        onClick={this._handleSubscribeClickAsync.bind(this)}
                        label="Subscribe"
                    />
                </div>
            </div>
        );
    }
    private _handleEmailInputChange(event: React.ChangeEvent<HTMLInputElement>): void {
        this.setState({ emailText: event.target.value });
    }
    private async _handleSubscribeClickAsync(): Promise<void> {
        this._setStatus(SubscribeFormStatus.Loading);
        const success = await backendClient.subscribeToNewsletterAsync(this.state.emailText);
        const status = success ? SubscribeFormStatus.Success : SubscribeFormStatus.Error;
        this._setStatus(status);
    }
    private _setStatus(status: SubscribeFormStatus): void {
        this.setState({ status });
    }
}