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

Allow option to pre-fill the course, region and location from the application form #2211

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/components/LeadForm/PhoneInput/index.js
Original file line number Diff line number Diff line change
@@ -131,15 +131,17 @@ const PhoneInput = ({
}, [selectedCountry]);

React.useEffect(() => {
if (
setShowPhoneWarning &&
campusDial &&
campusDial !== "" &&
campusDial.dialCode !== selectedCountry.dialCode
)
if (!setShowPhoneWarning) return;
if (!campusDial || !campusDial.dialCode) {
setShowPhoneWarning(false);
return;
}
if (campusDial.dialCode !== selectedCountry.dialCode) {
setShowPhoneWarning(true);
else if (setShowPhoneWarning) setShowPhoneWarning(false);
}, [campusDial, selectedCountry]);
} else {
setShowPhoneWarning(false);
}
}, [campusDial, selectedCountry, setShowPhoneWarning]);

const handleSearchChange = (e) => {
const {
56 changes: 29 additions & 27 deletions src/templates/apply.js
Original file line number Diff line number Diff line change
@@ -112,28 +112,34 @@ const Apply = (props) => {
}, []);
React.useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);

// Pre-fill the region
let _region = urlParams.get("region");
if (!_region && session.location?.meta_info?.region) {
_region = session.location.meta_info.region; // e.g. 'latam'
}

// Pre-fill the location
let _location = urlParams.get("location");
if (!_location && session.location)
if (!_location && session.location)
_location = session.location.active_campaign_location_slug;

if (typeof _location === "string" && session.locations)
_location = session.locations.find(
(l) =>
l.active_campaign_location_slug === _location ||
l.breathecode_location_slug === _location
);
else _location = null;
else _location = null;

if (_location) _location = _location.active_campaign_location_slug;

// Pre-fill the course
let _course = urlParams.get("course");
if (!_course && props.location.state) _course = props.location.state.course;

if (typeof _course === "string")
_course = programs.find((p) => p.value === _course);

// Pre-fill the utm_url
let _utm_url = undefined;
if (props.location.state)
@@ -144,13 +150,16 @@ const Apply = (props) => {
utm_url: _utm_url,
// this is the line that automatically sets the location, we don't want that anymore
// its better if leads choose the location themselves
// location: {value: _location || "", valid: typeof (_location) === "string" && _location !== ""},
location: {value: _location || "", valid: typeof (_location) === "string" && _location !== ""
},
course: {
value: _course || null,
valid: _course && _course.value ? true : false,
},
referral_key: { value: session?.utm?.referral_code || null, valid: true },
}));

setRegionVal(_region || null);
}, [session]);

let privacy = data.privacy.edges.find(
@@ -540,9 +549,11 @@ const Apply = (props) => {
tabindex="1"
bgColor={Colors.black}
options={regions}
// value={locations?.find(
// (el) => el.value === formData.location.value
// )}
value={
regionVal
? regions.find((r) => r.value === regionVal)
: null
}
placeholder={yml.left.regions_title}
inputId="dropdown_region_selector"
onChange={(value) => {
@@ -581,29 +592,20 @@ const Apply = (props) => {
margin_tablet="11px 0 23px 0"
>
<SelectRaw
tabindex="1"
bgColor={Colors.black}
options={
regionVal === "online"
? [
{
dialCode: null,
label: "Online",
region: "online",
value: "online",
},
]
: locations?.filter(
(academy) => academy.region === regionVal
)
? [{ dialCode: null, label: "Online", region: "online", value: "online" }]
: locations?.filter((academy) => academy.region === regionVal)
}
value={formData.location.value}
value={locations?.find(
(el) => el.value === formData.location.value
)}
placeholder={yml.left.locations_title}
inputId={"dropdown_academy_selector"}
onChange={(value, valid) => {
setVal({ ...formData, location: { value, valid } });
}}
/>
onChange={(value, valid) =>
setVal({ ...formData, location: { value, valid } })}
/>
</Div>
)}
{formData.referral_key.value &&