|
| 1 | +import React, { useState } from 'react'; |
| 2 | +// import '../../css/style.css'; |
| 3 | +import Swal from 'sweetalert2'; |
| 4 | +import { Box, Image, Button, TextInput, Text } from 'grommet'; |
| 5 | +import PropTypes from 'prop-types'; |
| 6 | +import { graphql } from 'gatsby'; |
| 7 | +import { Layout, SEO } from '../../components'; |
| 8 | + |
| 9 | +const { GATSBY_SLACK_TOKEN } = process.env; |
| 10 | +const { GATSBY_SLACK_INVITE_URL } = process.env; |
| 11 | +const image = '/images/hero-pic.png'; |
| 12 | +const buttonstyle = { |
| 13 | + backgroundColor: '#dcdcdc', |
| 14 | + borderRadius: '100px', |
| 15 | + align: 'center', |
| 16 | + height: '50px', |
| 17 | + fontSize: '15px', |
| 18 | + fontFamily: 'sans-serif', |
| 19 | +}; |
| 20 | +export default function Slacksignup() { |
| 21 | + const [email, setemail] = useState(''); |
| 22 | + const onsubmit = (evt) => { |
| 23 | + evt.preventDefault(); |
| 24 | + if (email) { |
| 25 | + const doInvite = () => { |
| 26 | + const formData = new FormData(); |
| 27 | + formData.append('email', email); |
| 28 | + formData.append('token', GATSBY_SLACK_TOKEN); |
| 29 | + formData.append('set_active', true); |
| 30 | + return fetch(GATSBY_SLACK_INVITE_URL, { |
| 31 | + method: 'POST', |
| 32 | + body: formData, |
| 33 | + json: true, |
| 34 | + }) |
| 35 | + .then((res) => res.json()) |
| 36 | + .then((res) => { |
| 37 | + if (res.ok) { |
| 38 | + const el = document.createElement('div'); |
| 39 | + el.innerHTML = `Please check <b> ${email}</b> |
| 40 | + for an invite from slack`; |
| 41 | + Swal.fire({ |
| 42 | + title: 'SUCCESS !', |
| 43 | + html: el, |
| 44 | + icon: 'success', |
| 45 | + }); |
| 46 | + } else { |
| 47 | + let { error } = res; |
| 48 | + if (error === 'already_invited' || error === 'already_in_team') { |
| 49 | + const el = document.createElement('div'); |
| 50 | + el.innerHTML = |
| 51 | + "It seems like you are already member of our slack.<br>Visit <a href=https://hpedev.slack.com target='_blank' > <b> HPE Developer Community</b></a> on slack"; |
| 52 | + Swal.fire({ |
| 53 | + title: 'Success', |
| 54 | + html: el, |
| 55 | + icon: 'success', |
| 56 | + }); |
| 57 | + } else if (error === 'already_in_team_invited_user') { |
| 58 | + const l = document.createElement('div'); |
| 59 | + l.innerHTML = `Please check again <b style="font-size:large;" > ${email} </b> for an invite from Slack.<br>Visit <a href=https://developer.hpe.com/ target="_blank"> HPE Developer Community</a>`; |
| 60 | + Swal.fire({ |
| 61 | + title: 'It seems like we already sent you our slack invite', |
| 62 | + html: l, |
| 63 | + icon: 'info', |
| 64 | + }); |
| 65 | + } else { |
| 66 | + if (error === 'invalid_email') { |
| 67 | + error = 'The email you entered is an invalid email.'; |
| 68 | + } else if (error === 'invalid_auth') { |
| 69 | + error = |
| 70 | + 'Something has gone wrong. Please' + |
| 71 | + ' contact a system administrator.'; |
| 72 | + } |
| 73 | + Swal.fire({ |
| 74 | + title: 'Error', |
| 75 | + html: error, |
| 76 | + icon: 'error', |
| 77 | + }); |
| 78 | + } |
| 79 | + } |
| 80 | + }) |
| 81 | + .catch((err) => { |
| 82 | + Swal.fire({ |
| 83 | + title: 'Error !', |
| 84 | + html: err, |
| 85 | + icon: 'error', |
| 86 | + }); |
| 87 | + }); |
| 88 | + }; // end of doInvite |
| 89 | + doInvite(); |
| 90 | + } // end of if statement |
| 91 | + else { |
| 92 | + const errMsg = []; |
| 93 | + if (!email) { |
| 94 | + errMsg.push('your email is required'); |
| 95 | + } |
| 96 | + Swal.fire({ |
| 97 | + html: `Failed! ${errMsg.join(' and ')}.`, |
| 98 | + icon: 'info', |
| 99 | + }); |
| 100 | + } |
| 101 | + setTimeout(() => { |
| 102 | + setemail(''); |
| 103 | + }, 2500); |
| 104 | + }; |
| 105 | + const handlechange = (event) => { |
| 106 | + setemail(event.target.value); |
| 107 | + }; |
| 108 | + return ( |
| 109 | + <Layout> |
| 110 | + <SEO title="Slack-signup" /> |
| 111 | + <Box direction="row-responsive" pad="xlarge" gap="xlarge" align="center"> |
| 112 | + <Box> |
| 113 | + <Box style={{ marginTop: '-30px' }}> |
| 114 | + <Text size="xlarge" style={{ margingTop: '-10px', color: 'grey' }}> |
| 115 | + Sign up for |
| 116 | + </Text> |
| 117 | + <h1 |
| 118 | + style={{ |
| 119 | + fontFamily: 'sans-serif', |
| 120 | + color: '#220', |
| 121 | + fontWeight: 550, |
| 122 | + letterSpacing: '0.5px', |
| 123 | + fontSize: '63px', |
| 124 | + lineHeight: '5rem', |
| 125 | + }} |
| 126 | + > |
| 127 | + HPE Developer Community <br /> Slack |
| 128 | + </h1> |
| 129 | + <Image |
| 130 | + style={{ |
| 131 | + height: '80px', |
| 132 | + width: '100px', |
| 133 | + float: 'right', |
| 134 | + marginTop: '-120px', |
| 135 | + marginLeft: '170px', |
| 136 | + }} |
| 137 | + src="/img/community/slack.svg" |
| 138 | + alt="slack logo" |
| 139 | + /> |
| 140 | + <p style={{ fontWeight: 400, fontSize: '22px' }}> |
| 141 | + Where you’ll find all things software at HPE. Join us to |
| 142 | + collaborate and build applications and integrations with HPE |
| 143 | + products using the latest software and open source technologies |
| 144 | + </p> |
| 145 | + </Box> |
| 146 | + <Text size="large">Email</Text> |
| 147 | + <form className="form" id="join-form" onSubmit={onsubmit}> |
| 148 | + <Box align="center" border={{ side: 'bottom', size: 'small' }}> |
| 149 | + <TextInput |
| 150 | + type="email" |
| 151 | + |
| 152 | + value={email} |
| 153 | + name="email" |
| 154 | + onChange={handlechange} |
| 155 | + style={{ position: 'relative', marginLeft: '-10px' }} |
| 156 | + required |
| 157 | + plain |
| 158 | + /> |
| 159 | + </Box> |
| 160 | + <br /> |
| 161 | + <Button |
| 162 | + label="Join us on Slack" |
| 163 | + primary |
| 164 | + reverse |
| 165 | + type="submit" |
| 166 | + onSubmit={onsubmit} |
| 167 | + icon={ |
| 168 | + <Image |
| 169 | + src="/img/home/hpe-element.png" |
| 170 | + style={{ width: '50px' }} |
| 171 | + /> |
| 172 | + } |
| 173 | + style={{ |
| 174 | + backgroundColor: '#01A982', |
| 175 | + borderRadius: '100px', |
| 176 | + color: '#ffffff', |
| 177 | + width: '250px', |
| 178 | + position: 'relative', |
| 179 | + height: '40px', |
| 180 | + }} |
| 181 | + /> |
| 182 | + </form> |
| 183 | + </Box> |
| 184 | + <Box align="center"> |
| 185 | + <Image src={image} alt="hpedev logo" /> |
| 186 | + </Box> |
| 187 | + </Box> |
| 188 | + <Box |
| 189 | + direction="row-responsive" |
| 190 | + pad="xlarge" |
| 191 | + gap="medium" |
| 192 | + align="center" |
| 193 | + style={{ marginTop: '-120px' }} |
| 194 | + > |
| 195 | + <Button label="50+ Channels" style={buttonstyle} /> |
| 196 | + <Button label="Over 4,000 members" style={buttonstyle} /> |
| 197 | + <Button label="6 Years+ Community" style={buttonstyle} /> |
| 198 | + </Box> |
| 199 | + </Layout> |
| 200 | + ); |
| 201 | +} |
| 202 | + |
| 203 | +Slacksignup.propTypes = { |
| 204 | + data: PropTypes.shape({ |
| 205 | + site: PropTypes.shape({ |
| 206 | + siteMetadata: PropTypes.shape({ |
| 207 | + title: PropTypes.string.isRequired, |
| 208 | + }).isRequired, |
| 209 | + }).isRequired, |
| 210 | + markdownRemark: PropTypes.shape({ |
| 211 | + frontmatter: PropTypes.shape({ |
| 212 | + title: PropTypes.string.isRequired, |
| 213 | + image: PropTypes.string, |
| 214 | + }).isRequired, |
| 215 | + rawMarkdownBody: PropTypes.string, |
| 216 | + }).isRequired, |
| 217 | + }), |
| 218 | +}; |
| 219 | +export const slack = graphql` |
| 220 | + query { |
| 221 | + site { |
| 222 | + siteMetadata { |
| 223 | + title |
| 224 | + } |
| 225 | + } |
| 226 | + markdownRemark(fields: { slug: { eq: "/" } }) { |
| 227 | + excerpt |
| 228 | + frontmatter { |
| 229 | + title |
| 230 | + image |
| 231 | + } |
| 232 | + rawMarkdownBody |
| 233 | + } |
| 234 | + } |
| 235 | +`; |
0 commit comments