Skip to content

Commit 7b3c6bd

Browse files
committed
react script
1 parent 6495e93 commit 7b3c6bd

12 files changed

+314
-20797
lines changed

component/InputFields.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import styles from '../styles/inputfield.module.css';
2+
import React, { useEffect, useState } from 'react'
3+
4+
const InputFields = ({placeholder, componentId, display, defaultValue}) => {
5+
6+
const [displayField, setDisplayField] = useState(false)
7+
8+
useEffect(() => {
9+
setDisplayField(display)
10+
}, [display])
11+
12+
return (
13+
<div className={displayField ? styles.formInput : styles.hidden} >
14+
<input
15+
type="text"
16+
id={componentId}
17+
className={styles.textBox}
18+
placeholder={placeholder}
19+
defaultValue={defaultValue}
20+
/>
21+
</div>
22+
);
23+
}
24+
25+
export default InputFields;

component/MapContainer.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@ import { Wrapper } from '@googlemaps/react-wrapper'
33

44
import styles from '../styles/map.module.css';
55

6-
const MapContainer = ({ mapCords, address }) => {
6+
const MapContainer = ({ mapCords, featureDecisionData }) => {
77

88
const apiKey = process.env.NEXT_PUBLIC_GOOGLE_API_KEY;
9-
console.log('MapContainer', apiKey, mapCords)
9+
const displayPooleStoreDetails = featureDecisionData?.ruleKey?.indexOf('poole') > -1;
1010

1111
return (
12-
<section className={styles.container}>
13-
<Wrapper apiKey={apiKey}>
14-
<Map mapCords={mapCords} />
15-
</Wrapper>
12+
<div className={styles.container}>
13+
<section className={styles.box}>
14+
Your nearest stores:
1615
</section>
17-
);
16+
<section className={styles.box}>
17+
<div className={styles.mapArea}>
18+
<Wrapper apiKey={apiKey}>
19+
<Map mapCords={mapCords} />
20+
</Wrapper>
21+
</div>
22+
</section>
23+
{displayPooleStoreDetails &&
24+
<section className={styles.box}>
25+
<strong>Your Local store:</strong> Culliford Cres, Canford Heath, Poole BH17 9DW. Hours: Open ⋅ Closes 11PM
26+
</section>
27+
}
28+
</div>
29+
);
1830
}
1931

2032
export default MapContainer;

component/PersonalizedForm.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import React from 'react'
2+
import { updateOdpProfileData, getOdpProfileData } from "../utils/odpConnector";
3+
import Cookies from 'js-cookie';
4+
import { useRouter } from 'next/router'
5+
import styles from '../styles/PersonalizedForm.module.css';
6+
import InputFields from './InputFields'
7+
8+
const fetchOdpData = async (email) => {
9+
return await getOdpProfileData(email);
10+
};
11+
12+
async function submitForm(event, router) {
13+
14+
event.preventDefault();
15+
16+
const email = event?.target?.username?.value;
17+
const location = event?.target?.location?.value;
18+
19+
if (email) {
20+
const response = await updateOdpProfileData(email, location);
21+
console.log('submitForm', response, email);
22+
23+
const profileData = await fetchOdpData(email).catch(console.error);
24+
const requestedSalesPack = profileData?.requested_sales_pack;
25+
const state = profileData?.state;
26+
27+
if (state) {
28+
Cookies.set('state', state);
29+
}
30+
if (requestedSalesPack) {
31+
Cookies.set('requestedSalesPack', true);
32+
}
33+
34+
Cookies.set('email', email);
35+
36+
router.reload(window.location.pathname)
37+
}
38+
39+
return;
40+
}
41+
42+
function resetCookies(router) {
43+
Cookies.remove('state');
44+
Cookies.remove('email');
45+
46+
router.reload(window.location.pathname)
47+
}
48+
49+
const PersonalizedForm = ({email, state}) => {
50+
51+
const router = useRouter();
52+
const displayLocation = (state == null || state?.length === 0) &&
53+
(email != null || email?.length > 0)
54+
55+
return (
56+
<>
57+
<form className={styles.formContainer} onSubmit={(e) => submitForm(e, router)}>
58+
59+
<InputFields componentId="username" placeholder="Add email" defaultValue={email} display={true} />
60+
61+
<InputFields componentId="location" placeholder="Add location" display={displayLocation} />
62+
63+
<div className={`${styles.contentArea}`}>
64+
Optimizely will store and process your personal data as described in our Privacy Policy. You can opt out at any time.
65+
</div>
66+
67+
<button type="submit" className={`${styles.signupBtn}`}>
68+
Sign Up
69+
</button>
70+
71+
</form>
72+
73+
74+
<button onClick={() => resetCookies(router)} >
75+
Reset cookies
76+
</button>
77+
</>
78+
)
79+
}
80+
81+
export default PersonalizedForm;

0 commit comments

Comments
 (0)