Skip to content

Commit

Permalink
Add newsletter signup checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
255kb committed Dec 21, 2023
1 parent b5bcbc1 commit 96e81bc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 20 additions & 1 deletion pages/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ const Signup: FunctionComponent = function () {
if (!data['work_address']) {
delete data['work_address'];

if (data['newsletter']) {
localStorage.setItem('newsletter', 'true');
}

try {
const userCredentials = await signUp(data.email, data.password);

Expand Down Expand Up @@ -142,7 +146,8 @@ const Signup: FunctionComponent = function () {
{...registerFormField('password')}
/>
</div>
<div className='form-check mb-5'>

<div className='form-check mb-2'>
<input
className='form-check-input'
type='checkbox'
Expand All @@ -157,6 +162,20 @@ const Signup: FunctionComponent = function () {
<Link href={'/terms/'}>terms of service</Link>.
</label>
</div>
<div className='form-check mb-5'>
<input
className='form-check-input'
type='checkbox'
value=''
id='newsletter'
{...registerFormField('newsletter')}
/>
<label className='form-check-label' htmlFor='newsletter'>
I want to receive Mockoon's newsletter (usually once a
month or less). Your email will not be shared or used for
any other purpose.
</label>
</div>
<FormHoneypot
inputRegister={registerFormField('work_address')}
/>
Expand Down
8 changes: 7 additions & 1 deletion utils/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ const useCurrentUser = () => {
refetchOnMount: false,
queryFn: async () => {
const token = await getIdToken();
let query = '';

if (!token) {
return null;
}

return fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/user`, {
if (localStorage.getItem('newsletter')) {
localStorage.removeItem('newsletter');
query = '?newsletter=true';
}

return fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/user${query}`, {
headers: {
Authorization: `Bearer ${token}`
}
Expand Down

0 comments on commit 96e81bc

Please sign in to comment.