Skip to content

Commit 5be58ca

Browse files
committed
Convert ContactUsForm to styled Components
1 parent 1779643 commit 5be58ca

File tree

4 files changed

+386
-124
lines changed

4 files changed

+386
-124
lines changed

components/ContactUsForm.js renamed to components/ContactUsForm/ContactUsForm.js

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ 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/Container';
6-
import contactUsFormStyles from '@/styles/Contact.module.scss';
76
import RevealContentContainer from '@/components/containers/RevealContentContainer/RevealContentContainer';
87
import SubmitButton from '@/components/buttons/SubmitButton/SubmitButton';
8+
import S from './styles';
99

1010
export const ContactUsFormSubscribe = ({ setMsg }) => {
1111
return (
@@ -20,11 +20,9 @@ export const ContactUsFormSubscribe = ({ setMsg }) => {
2020
setResponseMessage={setMsg}
2121
/>
2222
{status === 'error' && (
23-
<div
24-
className={contactUsFormStyles.contact__respseonErrorMessage}
25-
>
23+
<S.ResponseOnErrorMsg>
2624
{`Newsletter subscription error: ${message}`}
27-
</div>
25+
</S.ResponseOnErrorMsg>
2826
)}
2927
</>
3028
);
@@ -93,11 +91,8 @@ function ContactUsForm({ subscribe, setResponseMessage }) {
9391
return (
9492
<RevealContentContainer>
9593
<Container>
96-
<form
97-
onSubmit={handleSubmit(onSubmit)}
98-
className={contactUsFormStyles.contact__form}
99-
>
100-
<input
94+
<S.Form onSubmit={handleSubmit(onSubmit)}>
95+
<S.Input
10196
type='text'
10297
placeholder='name'
10398
{...register('Name', {
@@ -107,83 +102,82 @@ function ContactUsForm({ subscribe, setResponseMessage }) {
107102
//no white space pattern
108103
pattern: /[^\s-]/i,
109104
})}
110-
className={`${contactUsFormStyles.contact__input} ${contactUsFormStyles.contact__name}`}
105+
$inputType='name'
111106
/>
112-
<p className={contactUsFormStyles.contact__errorMessage}>
107+
<S.ErrorMsg>
113108
{errors.Name?.type === 'required'
114109
? 'Name is required'
115110
: errors.Name?.type === 'pattern'
116111
? 'No whitespace'
117112
: errors.Name?.type === 'minLength'
118113
? 'Must be more than 1 character'
119114
: undefined}
120-
</p>
121-
<input
115+
</S.ErrorMsg>
116+
<S.Input
122117
type='email'
123118
placeholder='email'
124119
{...register('Email', {
125120
required: true,
126121
pattern: /^\S+@\S+$/i,
127122
})}
128-
className={`${contactUsFormStyles.contact__input} ${contactUsFormStyles.contact__email}`}
123+
$inputType='email'
129124
/>
130-
<p className={contactUsFormStyles.contact__errorMessage}>
125+
<S.ErrorMsg>
131126
{errors.Email?.type === 'required' && 'Email is required'}
132-
</p>
133-
<input
127+
</S.ErrorMsg>
128+
<S.Input
134129
type='text'
135130
placeholder='subject'
136131
{...register('Subject', {
137132
required: true,
138133
minLength: 2,
139134
pattern: /[^\s-]/i,
140135
})}
141-
className={`${contactUsFormStyles.contact__input} ${contactUsFormStyles.contact__subject}`}
136+
$inputType='email'
142137
/>
143-
<p className={contactUsFormStyles.contact__errorMessage}>
138+
<S.ErrorMsg>
144139
{errors.Subject?.type === 'required'
145140
? 'Subject is required'
146141
: errors.Subject?.type === 'pattern'
147142
? 'No whitespace'
148143
: errors.Subject?.type === 'minLength'
149144
? 'Must be more than 1 character'
150145
: undefined}
151-
</p>
152-
<textarea
146+
</S.ErrorMsg>
147+
<S.TextArea
153148
{...register('Message', {
154149
required: true,
155150
minLength: 2,
156151
pattern: /[^\s-]/i,
157152
})}
158153
placeholder='Write your message here'
159-
className={`${contactUsFormStyles.contact__input} ${contactUsFormStyles.contact__message}`}
154+
$inputType='message'
160155
/>
161-
<p className={contactUsFormStyles.contact__errorMessage}>
156+
<S.ErrorMsg>
162157
{errors.Message?.type === 'required'
163158
? 'Message is required'
164159
: errors.Message?.type === 'pattern'
165160
? 'No whitespace'
166161
: errors.Message?.type === 'minLength'
167162
? 'Must be more than 1 character'
168163
: undefined}
169-
</p>
170-
<div className={contactUsFormStyles.contact__subscribe}>
171-
<input
172-
className={contactUsFormStyles.contact__subscribeInput}
164+
</S.ErrorMsg>
165+
<S.SubscribeWrapper>
166+
<S.SubscribeInput
173167
type='checkbox'
174168
placeholder='Subscribe to our DevNews!'
175169
{...register('Subscribe', {})}
176170
/>
177171
Subscribe to our DevNews!
178-
</div>
172+
</S.SubscribeWrapper>
179173
<SubmitButton label='Submit' disabled={isSubmitting} />
180174

181175
<ReCAPTCHA
182176
ref={contactReCaptchaRef}
183177
size='invisible'
184178
sitekey={process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY}
185179
/>
186-
</form>
180+
</S.Form>
187181
</Container>
188182
</RevealContentContainer>
189183
);

0 commit comments

Comments
 (0)