Skip to content

Commit 3c93c90

Browse files
committed
update response message style
1 parent a268db2 commit 3c93c90

File tree

4 files changed

+74
-55
lines changed

4 files changed

+74
-55
lines changed

components/ContactUsForm.js

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,87 @@
11
import { useForm } from 'react-hook-form';
2-
import { useRef, useState } from 'react';
2+
import { useRef } from 'react';
33
import MailchimpSubscribe from 'react-mailchimp-subscribe';
44
import ReCAPTCHA from 'react-google-recaptcha';
55
import Container from '@/components/containers/Container';
66
import contactUsFormStyles from '@/styles/Contact.module.scss';
77
import RevealContentContainer from '@/components/containers/RevealContentContainer';
88
import SubmitButton from '@/components/buttons/SubmitButton';
99

10-
export const ContactUsFormSubscribe = ({setMsg, setSubStatus, setSubMsg}) => {
10+
export const ContactUsFormSubscribe = ({ setMsg }) => {
1111
return (
1212
<MailchimpSubscribe
1313
url={process.env.NEXT_PUBLIC_MAILCHIMP_URL}
1414
render={({ subscribe, status, message }) => {
15-
setSubStatus(status)
16-
setSubMsg(message)
15+
console.info(`MailChimp (contact form): ${status} - ${message}`);
1716
return (
18-
<ContactUsForm
19-
subscribe={formData => subscribe(formData)}
20-
setResponseMessage={setMsg}
21-
/>
17+
<>
18+
<ContactUsForm
19+
subscribe={formData => subscribe(formData)}
20+
setResponseMessage={setMsg}
21+
/>
22+
{status === 'error' && (
23+
<div
24+
className={contactUsFormStyles.contact__respseonErrorMessage}
25+
>
26+
{`Newsletter subscription error: ${message}`}
27+
</div>
28+
)}
29+
</>
2230
);
23-
}
24-
}
31+
}}
2532
/>
2633
);
27-
2834
};
2935

3036
function ContactUsForm({ subscribe, setResponseMessage }) {
31-
const contactReCaptchaRef = useRef()
37+
const contactReCaptchaRef = useRef();
3238

3339
const {
3440
register,
3541
handleSubmit,
3642
reset,
37-
formState: { errors, isSubmitting }
43+
formState: { errors, isSubmitting },
3844
} = useForm({
3945
defaultValues: {
4046
Name: '',
4147
Email: '',
4248
Subject: '',
43-
Message: ''
44-
}
49+
Message: '',
50+
},
4551
});
4652

4753
async function onSubmit(data) {
48-
setResponseMessage(['Submitting...'])
54+
setResponseMessage(['Submitting...']);
4955

50-
contactReCaptchaRef.current.reset()
51-
const gReCaptchaToken = await contactReCaptchaRef.current.executeAsync()
56+
contactReCaptchaRef.current.reset();
57+
const gReCaptchaToken = await contactReCaptchaRef.current.executeAsync();
5258

5359
const res = await fetch('/api/contact', {
5460
method: 'POST',
5561
headers: {
56-
'Content-Type': 'application/json'
62+
'Content-Type': 'application/json',
5763
},
5864
body: JSON.stringify({
5965
name: data.Name,
6066
email: data.Email,
6167
subject: data.Subject,
6268
message: data.Message,
6369
subscribe: data.Subscribe,
64-
gReCaptchaToken
65-
})
70+
gReCaptchaToken,
71+
}),
6672
});
6773

6874
if (res.ok) {
69-
setResponseMessage(['Your message was sent successfully. We will be in touch with you as soon as possible.'])
75+
setResponseMessage([
76+
'Your message was sent successfully. We will be in touch with you as soon as possible.',
77+
]);
7078
} else {
7179
const jsonRes = await res.json();
72-
setResponseMessage([
73-
"Error Submitting Message",
80+
setResponseMessage([
81+
'Error Submitting Message',
7482
`Status Code: ${res.status} - ${jsonRes.message}`,
75-
"Please contact support at [email protected]"])
83+
'Please contact support at [email protected]',
84+
]);
7685
}
7786

7887
if (data.Subscribe) {
@@ -81,7 +90,7 @@ function ContactUsForm({ subscribe, setResponseMessage }) {
8190
reset();
8291
}
8392

84-
console.info('these are errors;', errors);
93+
console.info('Contact Form: these are errors;', errors);
8594

8695
return (
8796
<RevealContentContainer>
@@ -98,25 +107,25 @@ function ContactUsForm({ subscribe, setResponseMessage }) {
98107
minLength: 2,
99108
maxLength: 80,
100109
//no white space pattern
101-
pattern: /[^\s-]/i
110+
pattern: /[^\s-]/i,
102111
})}
103112
className={`${contactUsFormStyles.contact__input} ${contactUsFormStyles.contact__name}`}
104113
/>
105114
<p className={contactUsFormStyles.contact__errorMessage}>
106115
{errors.Name?.type === 'required'
107116
? 'Name is required'
108117
: errors.Name?.type === 'pattern'
109-
? 'No whitespace'
110-
: errors.Name?.type === 'minLength'
111-
? 'Must be more than 1 character'
112-
: undefined}
118+
? 'No whitespace'
119+
: errors.Name?.type === 'minLength'
120+
? 'Must be more than 1 character'
121+
: undefined}
113122
</p>
114123
<input
115124
type='email'
116125
placeholder='email'
117126
{...register('Email', {
118127
required: true,
119-
pattern: /^\S+@\S+$/i
128+
pattern: /^\S+@\S+$/i,
120129
})}
121130
className={`${contactUsFormStyles.contact__input} ${contactUsFormStyles.contact__email}`}
122131
/>
@@ -129,24 +138,24 @@ function ContactUsForm({ subscribe, setResponseMessage }) {
129138
{...register('Subject', {
130139
required: true,
131140
minLength: 2,
132-
pattern: /[^\s-]/i
141+
pattern: /[^\s-]/i,
133142
})}
134143
className={`${contactUsFormStyles.contact__input} ${contactUsFormStyles.contact__subject}`}
135144
/>
136145
<p className={contactUsFormStyles.contact__errorMessage}>
137146
{errors.Subject?.type === 'required'
138147
? 'Subject is required'
139148
: errors.Subject?.type === 'pattern'
140-
? 'No whitespace'
141-
: errors.Subject?.type === 'minLength'
142-
? 'Must be more than 1 character'
143-
: undefined}
149+
? 'No whitespace'
150+
: errors.Subject?.type === 'minLength'
151+
? 'Must be more than 1 character'
152+
: undefined}
144153
</p>
145154
<textarea
146155
{...register('Message', {
147156
required: true,
148157
minLength: 2,
149-
pattern: /[^\s-]/i
158+
pattern: /[^\s-]/i,
150159
})}
151160
placeholder='Write your message here'
152161
className={`${contactUsFormStyles.contact__input} ${contactUsFormStyles.contact__message}`}
@@ -155,10 +164,10 @@ function ContactUsForm({ subscribe, setResponseMessage }) {
155164
{errors.Message?.type === 'required'
156165
? 'Message is required'
157166
: errors.Message?.type === 'pattern'
158-
? 'No whitespace'
159-
: errors.Message?.type === 'minLength'
160-
? 'Must be more than 1 character'
161-
: undefined}
167+
? 'No whitespace'
168+
: errors.Message?.type === 'minLength'
169+
? 'Must be more than 1 character'
170+
: undefined}
162171
</p>
163172
<div className={contactUsFormStyles.contact__subscribe}>
164173
<input

pages/contact.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
11
import { useState } from 'react';
2-
import { ContactUsFormSubscribe } from '../components/ContactUsForm';
2+
import { ContactUsFormSubscribe } from '@/components/ContactUsForm';
33
import contactUsFormStyles from '@/styles/Contact.module.scss';
44
import Bracket from '@/components/decorations/Bracket';
55

66
export default function ContactUs() {
77
const [message, setMessage] = useState([]);
8-
const [subStatus, setSubStatus] = useState('');
9-
const [subMsg, setSubMsg] = useState('');
108

119
return (
1210
<div className={contactUsFormStyles.contact}>
1311
<div className={contactUsFormStyles.contact__formAndDecorations}>
1412
<Bracket className={contactUsFormStyles.contact__yellowBracket} />
15-
<div>
16-
<ContactUsFormSubscribe
17-
setMsg={setMessage}
18-
setSubStatus={setSubStatus}
19-
setSubMsg={setSubMsg} />
20-
</div>
13+
<ContactUsFormSubscribe setMsg={setMessage} />
2114
<img
2215
src='/images/svg/yellow-colon.svg'
2316
className={contactUsFormStyles.contact__yellowColon}
2417
/>
2518
<div className={contactUsFormStyles.contact__response_message}>
26-
{message?.map(m => <>{m}<br /></>)}
27-
{subStatus && <><b>Subscription Status: </b> {subStatus}<br /></>}
28-
{subMsg}
19+
{message?.map((m, i) => (
20+
<span key={i}>
21+
{m}
22+
<br />
23+
</span>
24+
))}
2925
</div>
3026
</div>
31-
3227
</div>
3328
);
3429
}

styles/Contact.module.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,25 @@
143143
}
144144

145145
&__response_message {
146+
position: absolute;
147+
right: 8%;
148+
bottom: -5%;
149+
width: 26rem;
150+
margin: auto;
151+
152+
@include mobile {
153+
position: unset;
154+
margin-top: 1rem;
155+
}
156+
}
157+
158+
&__respseonErrorMessage {
146159
position: absolute;
147160
right: 8%;
148161
bottom: -15%;
149162
width: 26rem;
150163
margin: auto;
164+
color: $error;
151165

152166
@include mobile {
153167
position: unset;

styles/_variables.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ $dark-bg-color: #023047;
1717
$light-bg-color: #8cd5e8;
1818
$primary-accent-color: #ffcc4c;
1919
$secondary-accent-color: #19aad1;
20+
$error: #ab5252;
2021
$black: #000000;
2122
$white: #ffffff;
2223
$transparent: transparent;

0 commit comments

Comments
 (0)