-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add services and customer care sections to homepage; Add newsletter s…
…ubscription form to footer
- Loading branch information
Showing
10 changed files
with
465 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
form.newsletter-form div.form { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
} | ||
|
||
form.newsletter-form div.form .input { | ||
margin-right: 15px; | ||
max-width: 240px; | ||
} | ||
|
||
form.newsletter-form div.form .btn { | ||
height: 40px; | ||
padding: 0 30px; | ||
min-width: 120px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import React, { useState } from 'react' | ||
import { | ||
Button, | ||
FormControl, | ||
FormHelperText, | ||
InputLabel, | ||
OutlinedInput, | ||
CircularProgress, | ||
} from '@mui/material' | ||
import validator from 'validator' | ||
import * as movininTypes from ':movinin-types' | ||
import env from '@/config/env.config' | ||
import { strings as commonStrings } from '@/lang/common' | ||
import { strings } from '@/lang/newsletter-form' | ||
import * as helper from '@/common/helper' | ||
import * as UserService from '@/services/UserService' | ||
import { useRecaptchaContext, RecaptchaContextType } from '@/context/RecaptchaContext' | ||
|
||
import '@/assets/css/newsletter-form.css' | ||
|
||
const NewsletterForm = () => { | ||
const { reCaptchaLoaded, generateReCaptchaToken } = useRecaptchaContext() as RecaptchaContextType | ||
|
||
const [email, setEmail] = useState('') | ||
const [emailValid, setEmailValid] = useState(true) | ||
const [submitting, setSubmitting] = useState(false) | ||
|
||
const validateEmail = (_email: string) => { | ||
if (_email) { | ||
if (validator.isEmail(_email)) { | ||
setEmailValid(true) | ||
return true | ||
} | ||
|
||
setEmailValid(false) | ||
return false | ||
} | ||
|
||
setEmailValid(true) | ||
return false | ||
} | ||
|
||
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => { | ||
try { | ||
e.preventDefault() | ||
setSubmitting(true) | ||
|
||
if (!validateEmail(email)) { | ||
return | ||
} | ||
|
||
let recaptchaToken = '' | ||
if (reCaptchaLoaded) { | ||
recaptchaToken = await generateReCaptchaToken() | ||
if (!(await helper.verifyReCaptcha(recaptchaToken))) { | ||
recaptchaToken = '' | ||
} | ||
|
||
if (!recaptchaToken) { | ||
helper.error('reCAPTCHA error') | ||
} | ||
} | ||
|
||
const payload: movininTypes.SendEmailPayload = { | ||
from: email, | ||
to: env.CONTACT_EMAIL, | ||
subject: 'New Newsletter Subscription', | ||
message: '', | ||
isContactForm: false, | ||
} | ||
const status = await UserService.sendEmail(payload) | ||
|
||
if (status === 200) { | ||
setEmail('') | ||
helper.info(strings.SUCCESS) | ||
} else { | ||
helper.error() | ||
} | ||
} catch (err) { | ||
helper.error(err) | ||
} finally { | ||
setSubmitting(false) | ||
} | ||
} | ||
|
||
return ( | ||
<form className="newsletter-form" onSubmit={handleSubmit}> | ||
<h1>{strings.TITLE}</h1> | ||
<p>{strings.SUB_TITLE}</p> | ||
|
||
<div className="form"> | ||
<FormControl fullWidth margin="normal" size="small" className="input"> | ||
<InputLabel className="required">{commonStrings.EMAIL}</InputLabel> | ||
<OutlinedInput | ||
type="text" | ||
label={commonStrings.EMAIL} | ||
size="small" | ||
error={!emailValid} | ||
required | ||
autoComplete="off" | ||
value={email} | ||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { | ||
setEmail(e.target.value) | ||
|
||
if (!e.target.value) { | ||
setEmailValid(true) | ||
} | ||
}} | ||
/> | ||
<FormHelperText error={!emailValid}>{(!emailValid && commonStrings.EMAIL_NOT_VALID) || ''}</FormHelperText> | ||
</FormControl> | ||
|
||
<Button type="submit" variant="contained" className="btn-primary btn" aria-label="Subscribe"> | ||
{ | ||
submitting | ||
? <CircularProgress color="inherit" size={24} /> | ||
: strings.SUBSCRIBE | ||
} | ||
</Button> | ||
</div> | ||
</form> | ||
) | ||
} | ||
|
||
export default NewsletterForm |
Oops, something went wrong.