Skip to content

Commit c1c0dc0

Browse files
committed
store log as comma string
1 parent 7faa2d6 commit c1c0dc0

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/shared/containers/Gigs/RecruitCRMJobDetails.jsx

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* driven by recruitCRM
44
*/
55

6-
import { isEmpty, find } from 'lodash';
6+
import { isEmpty } from 'lodash';
77
import actions from 'actions/recruitCRM';
88
import LoadingIndicator from 'components/LoadingIndicator';
99
import GigDetails from 'components/Gigs/GigDetails';
@@ -12,7 +12,6 @@ import React from 'react';
1212
import { connect } from 'react-redux';
1313
import { config } from 'topcoder-react-utils';
1414
import fetch from 'isomorphic-fetch';
15-
import moment from 'moment';
1615
import RecruitCRMJobApply from './RecruitCRMJobApply';
1716

1817
const PROXY_ENDPOINT = `${config.URL.COMMUNITY_APP}/api`;
@@ -62,37 +61,28 @@ ${config.URL.BASE}${config.GIGS_PAGES_PATH}/${props.id}`,
6261
if (profile.email === email) {
6362
this.setState({
6463
isReferrError: {
65-
message: 'We not allow sending to yourself.',
64+
message: 'You are not allowed to send to yourself.',
6665
userError: true,
6766
},
6867
});
6968
// exit no email sending
7069
return;
7170
}
7271
// process sent log
73-
let { emailInvitesLog } = growSurf.data.metadata;
74-
if (!emailInvitesLog) emailInvitesLog = [];
72+
let { emailInvitesLog, emailInvitesStatus } = growSurf.data.metadata;
73+
if (!emailInvitesLog) emailInvitesLog = '';
7574
// check if email is in sent log alredy?
76-
const foundInLog = find(emailInvitesLog, ['e', email]);
77-
if (foundInLog) {
75+
const foundInLog = emailInvitesLog.indexOf(email);
76+
if (foundInLog !== -1) {
7877
this.setState({
7978
isReferrError: {
80-
message: `${email} was already invited on ${foundInLog.d}.`,
79+
message: `${email} was already invited.`,
8180
userError: true,
8281
},
8382
});
8483
// exit no email sending
8584
return;
8685
}
87-
// prepare new log payload
88-
emailInvitesLog.unshift({
89-
e: email, d: moment().format('MM-DD-YY'),
90-
});
91-
let newEmailInvitesLog = `${JSON.stringify(emailInvitesLog)}`;
92-
if (newEmailInvitesLog.length >= 500) {
93-
emailInvitesLog.pop();
94-
newEmailInvitesLog = `${JSON.stringify(emailInvitesLog)}`;
95-
}
9686
// check if email is already referred?
9787
const growCheck = await fetch(`${PROXY_ENDPOINT}/growsurf/participant/${email}`);
9888
if (growCheck.status === 200) {
@@ -108,7 +98,7 @@ ${config.URL.BASE}${config.GIGS_PAGES_PATH}/${props.id}`,
10898
return;
10999
}
110100
}
111-
// email the invite
101+
// // email the invite
112102
const res = await fetch(`${PROXY_ENDPOINT}/mailchimp/email`, {
113103
method: 'POST',
114104
body: JSON.stringify({
@@ -135,7 +125,20 @@ ${config.URL.BASE}${config.GIGS_PAGES_PATH}/${props.id}`,
135125
// exit no email tracking due to the error
136126
return;
137127
}
138-
// put tracking in growsurf
128+
// parse the log to array of emails
129+
if (emailInvitesLog.length) {
130+
emailInvitesLog = emailInvitesLog.split(',');
131+
} else emailInvitesLog = [];
132+
// prepare growSurf update payload
133+
// we keep only 10 emails in the log to justify program rules
134+
if (emailInvitesLog.length < 10) {
135+
emailInvitesLog.push(email);
136+
}
137+
// Auto change status when 10 emails sent
138+
if (emailInvitesLog.length === 10 && emailInvitesStatus !== 'Paid' && emailInvitesStatus !== 'Payment Pending') {
139+
emailInvitesStatus = 'Payment Pending';
140+
}
141+
// put the tracking update in growsurf
139142
const updateRed = await fetch(`${PROXY_ENDPOINT}/growsurf/participant/${growSurf.data.id}`, {
140143
method: 'PATCH',
141144
headers: {
@@ -147,7 +150,8 @@ ${config.URL.BASE}${config.GIGS_PAGES_PATH}/${props.id}`,
147150
metadata: {
148151
...growSurf.data.metadata,
149152
emailInvitesSent: Number(growSurf.data.metadata.emailInvitesSent || 0) + 1,
150-
emailInvitesLog: newEmailInvitesLog,
153+
emailInvitesLog: emailInvitesLog.join(),
154+
emailInvitesStatus,
151155
},
152156
}),
153157
});

0 commit comments

Comments
 (0)