Skip to content

Referral lock #5890

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

Merged
merged 4 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ workflows:
filters:
branches:
only:
- free
- referral-lock
# This is stage env for production QA releases
- "build-prod-staging":
context : org-global
Expand Down
93 changes: 43 additions & 50 deletions src/shared/containers/Gigs/RecruitCRMJobDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,6 @@ ${config.URL.BASE}${config.GIGS_PAGES_PATH}/${props.id}`,
// exit no email sending
return;
}
// process sent log
let { emailInvitesLog, emailInvitesStatus } = growSurf.data.metadata;
if (!emailInvitesLog) emailInvitesLog = '';
// check if email is in sent log alredy?
const foundInLog = emailInvitesLog.indexOf(email);
if (foundInLog !== -1) {
this.setState({
isReferrError: {
message: `${email} was already invited.`,
userError: true,
},
});
// exit no email sending
return;
}
// check if email is already referred?
const growCheck = await fetch(`${PROXY_ENDPOINT}/growsurf/participant/${email}`);
if (growCheck.status === 200) {
Expand Down Expand Up @@ -125,43 +110,51 @@ ${config.URL.BASE}${config.GIGS_PAGES_PATH}/${props.id}`,
// exit no email tracking due to the error
return;
}
// parse the log to array of emails
if (emailInvitesLog.length) {
emailInvitesLog = emailInvitesLog.split(',');
} else emailInvitesLog = [];
// prepare growSurf update payload
// we keep only 10 emails in the log to justify program rules
if (emailInvitesLog.length < 10) {
emailInvitesLog.push(email);
}
// Auto change status when 10 emails sent
if (emailInvitesLog.length === 10 && emailInvitesStatus !== 'Paid' && emailInvitesStatus !== 'Payment Pending') {
emailInvitesStatus = 'Payment Pending';
}
// put the tracking update in growsurf
const updateRed = await fetch(`${PROXY_ENDPOINT}/growsurf/participant/${growSurf.data.id}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${tokenV3}`,
},
body: JSON.stringify({
...growSurf.data,
metadata: {
...growSurf.data.metadata,
emailInvitesSent: Number(growSurf.data.metadata.emailInvitesSent || 0) + 1,
emailInvitesLog: emailInvitesLog.join(),
emailInvitesStatus,
// process sent log
let { emailInvitesLog, emailInvitesStatus } = growSurf.data.metadata;
if (!emailInvitesLog) emailInvitesLog = '';
// check if email is in sent log alredy?
const foundInLog = emailInvitesLog.indexOf(email);
// only when email is new - put it in log, update counters and etc.
if (foundInLog === -1) {
// parse the log to array of emails
if (emailInvitesLog.length) {
emailInvitesLog = emailInvitesLog.split(',');
} else emailInvitesLog = [];
// prepare growSurf update payload
// we keep only 10 emails in the log to justify program rules
if (emailInvitesLog.length < 10) {
emailInvitesLog.push(email);
}
// Auto change status when 10 emails sent
if (emailInvitesLog.length === 10 && emailInvitesStatus !== 'Paid' && emailInvitesStatus !== 'Payment Pending') {
emailInvitesStatus = 'Payment Pending';
}
// put the tracking update in growsurf
const updateRed = await fetch(`${PROXY_ENDPOINT}/growsurf/participant/${growSurf.data.id}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${tokenV3}`,
},
}),
});
if (updateRed.status >= 300) {
this.setState({
isReferrError: await updateRed.json(),
body: JSON.stringify({
...growSurf.data,
metadata: {
...growSurf.data.metadata,
emailInvitesSent: Number(growSurf.data.metadata.emailInvitesSent || 0) + 1,
emailInvitesLog: emailInvitesLog.join(),
emailInvitesStatus,
},
}),
});
// exit no email tracking due to the error
// just notify the user about it
return;
if (updateRed.status >= 300) {
this.setState({
isReferrError: await updateRed.json(),
});
// exit no email tracking due to the error
// just notify the user about it
return;
}
}
// finally do:
this.setState({
Expand Down