Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 6987 #2013

Open
wants to merge 14 commits into
base: development
Choose a base branch
from
2,118 changes: 1,155 additions & 963 deletions package-lock.json

Large diffs are not rendered by default.

48 changes: 41 additions & 7 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const defaultSession = {
email: null,
location: null,
language: "en",
blockList: [],
utm: {
gclid: undefined,
utm_campaign: undefined,
Expand Down Expand Up @@ -194,6 +195,10 @@ export function tagManager(eventName, payload = {}) {
export const apply = async (data, session) => {
console.log("Apply action called with session: ", session);

let isBlockNumber = session.blockList.find(
(element) => element.phone_regex === data.phone.phoneCode
);

let body = {};

Object.keys(data).forEach((key) => {
Expand All @@ -207,7 +212,7 @@ export const apply = async (data, session) => {
const action = "submit";
let token = await getToken(action);

if (!session || !session.utm || !session.utm.utm_test) {
if ((!session || !session.utm || !session.utm.utm_test) && !isBlockNumber) {
const _data = await save_form(
body,
[tag.value || tag],
Expand Down Expand Up @@ -255,8 +260,13 @@ export const requestSyllabus = async (data, session) => {
const automation = body.automation || "soft";
const action = "submit";
let token = await getToken(action);

let isBlockNumber = session.blockList.find(
(element) => element.phone_regex === data.phone.phoneCode
);

//tag automation
if (!session || !session.utm || !session.utm.utm_test) {
if ((!session || !session.utm || !session.utm.utm_test) && !isBlockNumber) {
const _data = await save_form(
body,
[tag.value || tag],
Expand Down Expand Up @@ -290,7 +300,12 @@ export const beHiringPartner = async (data, session) => {
for (let key in data) body[key] = data[key].value;
const action = "submit";
let token = await getToken(action);
if (!session || !session.utm || !session.utm.utm_test) {

let isBlockNumber = session.blockList.find(
(element) => element.phone_regex === data.phone.phoneCode
);

if ((!session || !session.utm || !session.utm.utm_test) && !isBlockNumber) {
const _data = await save_form(
body,
["hiring-partner"],
Expand All @@ -310,6 +325,7 @@ export const beHiringPartner = async (data, session) => {
}
return true;
};

export const applyJob = async (data) => {
console.log("New job application", data);
let body = {};
Expand All @@ -319,21 +335,33 @@ export const applyJob = async (data) => {
// if(!session || !session.utm || !session.utm.utm_test) return await save_form(body, ['hiring-partner'], ['hiring-partner']);
return true;
};

export const contactUs = async (data, session) => {
console.log("Succesfully contact us", data);
let body = {};
for (let key in data) body[key] = data[key].value;

// tag automation
//Contact us form don´t admit phone number so it's not posible block it
// let isBlockNumber = session.blockList.find(
// (element) => element.phone_regex === data.phone.phoneCode
// );
// if ((!session || !session.utm || !session.utm.utm_test) && !isBlockNumber)
if (!session || !session.utm || !session.utm.utm_test)
// tag automation
return await save_form(body, ["contact-us"], ["soft"], session);
return true;
};

export const newsletterSignup = async (data, session) => {
console.log("Succesfully newsletter signup", data);
let body = {};
for (let key in data) body[key] = data[key].value;

//Newaletter form don´t admit phone number so it's not posible block it
// let isBlockNumber = session.blockList.find(
// (element) => element.phone_regex === data.phone.phoneCode
// );
// if ((!session || !session.utm || !session.utm.utm_test) && !isBlockNumber)
// tag automation
if (!session || !session.utm || !session.utm.utm_test) {
const _data = await save_form(
Expand All @@ -358,8 +386,11 @@ export const outcomesReport = async (data, session) => {
let body = {};
for (let key in data) body[key] = data[key].value;

let isBlockNumber = session.blockList.find(
(element) => element.phone_regex === data.phone.phoneCode
);
// tag automation
if (!session || !session.utm || !session.utm.utm_test) {
if ((!session || !session.utm || !session.utm.utm_test) && !isBlockNumber) {
const _data = await save_form(
body,
["download_outcome"],
Expand Down Expand Up @@ -423,8 +454,11 @@ export const processFormEntry = async (data, session) => {
const action = "submit";
let token = await getToken(action);

// tag automation
if (!session || !session.utm || !session.utm.utm_test) {
let isBlockNumber = session.blockList.find(
(element) => element.phone_regex === data.phone.phoneCode
);
// tag automation
if ((!session || !session.utm || !session.utm.utm_test) && !isBlockNumber) {
const _data = await save_form(
body,
[tag.value || tag],
Expand Down
7 changes: 6 additions & 1 deletion src/components/LeadForm/PhoneInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ const PhoneInput = ({
}
setVal({
...formData,
phone: { ...phoneFormValues, value: cleanedPhoneInput, valid: true },
phone: {
...phoneFormValues,
value: cleanedPhoneInput,
valid: true,
phoneCode: prefixCode,
},
});
};

Expand Down
1 change: 1 addition & 0 deletions src/components/LeadForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const _fields = {
phone: {
value: "",
valid: false,
phoneCode: "",
required: true,
type: "phone",
place_holder: "Phone number",
Expand Down
5 changes: 4 additions & 1 deletion src/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
locByLanguage,
} from "./actions";

const blockList = require("./utils/dictionaries/blockList.json");

// import ActionsWorker from "./actions.worker.js";
export const SessionContext = createContext(defaultSession);

Expand Down Expand Up @@ -89,6 +91,7 @@ export default ({ children }) => {
};
const message = {
locationsArray: data.allLocationYaml,
blockListArray: blockList,
storedSession: getStorage("academy_session"),
path: window.location.pathname,
seed: {
Expand Down Expand Up @@ -141,7 +144,7 @@ export default ({ children }) => {
l.breathecode_location_slug ===
_s.location.breathecode_location_slug
);
const _session = { ..._s, location };
const _session = { ..._s, location, blockList };
setStorage(_session);
setSession(_session);
dayjs.locale(_session.language == "us" ? "en" : _session.language);
Expand Down
4 changes: 3 additions & 1 deletion src/templates/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const Apply = (props) => {
});
const [formData, setVal] = useState({
first_name: { value: "", valid: false },
phone: { value: "", valid: false },
phone: { value: "", phoneCode: "", valid: false },
email: { value: "", valid: false },
location: { value: "", valid: false },
consents: { value: [], valid: true },
Expand Down Expand Up @@ -103,6 +103,7 @@ const Apply = (props) => {
React.useEffect(() => {
tagManager("application_rendered");
}, []);

React.useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
// Pre-fill the location
Expand Down Expand Up @@ -184,6 +185,7 @@ const Apply = (props) => {
});
});
};

return (
<>
<Header
Expand Down
12 changes: 12 additions & 0 deletions src/utils/dictionaries/blockList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"academies": "madrid-spain",
"phone_regex": "+56",
"country_regex": "spain"
},
{
"academies": "lima-peru",
"phone_regex": "+51",
"country_regex": "peru"
}
]
22 changes: 18 additions & 4 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ const getRegion = (shortName, regions) => {
return region.length === 1 ? region[0] : null;
};

const initSession = async (locationsArray, storedSession, path, seed = {}) => {
const initSession = async (
locationsArray,
blockListArray,
storedSession,
path,
seed = {}
) => {
console.log("Initializing session");
var v4 = null;
var latitude = null;
Expand Down Expand Up @@ -274,6 +280,7 @@ const initSession = async (locationsArray, storedSession, path, seed = {}) => {
academyAliasDictionary[key] = alias.academy.slug;
});

const blockList = blockListArray.find((element) => element !== null);
const _session = {
...defaultSession,
...storedSession,
Expand All @@ -287,7 +294,7 @@ const initSession = async (locationsArray, storedSession, path, seed = {}) => {
longitude,
academyAliasDictionary,
pathsDictionary,

blockList: blockList,
// marketing utm info
utm: { ...storedSession.utm, ...utm },

Expand All @@ -303,7 +310,14 @@ const initSession = async (locationsArray, storedSession, path, seed = {}) => {
};

self.onmessage = async (message) => {
const { locationsArray, storedSession, seed, path } = message.data;
const _session = await initSession(locationsArray, storedSession, path, seed);
const { locationsArray, blockListArray, storedSession, seed, path } =
message.data;
const _session = await initSession(
locationsArray,
blockListArray,
storedSession,
path,
seed
);
self.postMessage(_session);
};