3
3
* driven by recruitCRM
4
4
*/
5
5
6
- import { isEmpty , find } from 'lodash' ;
6
+ import { isEmpty } from 'lodash' ;
7
7
import actions from 'actions/recruitCRM' ;
8
8
import LoadingIndicator from 'components/LoadingIndicator' ;
9
9
import GigDetails from 'components/Gigs/GigDetails' ;
@@ -12,7 +12,6 @@ import React from 'react';
12
12
import { connect } from 'react-redux' ;
13
13
import { config } from 'topcoder-react-utils' ;
14
14
import fetch from 'isomorphic-fetch' ;
15
- import moment from 'moment' ;
16
15
import RecruitCRMJobApply from './RecruitCRMJobApply' ;
17
16
18
17
const PROXY_ENDPOINT = `${ config . URL . COMMUNITY_APP } /api` ;
@@ -62,37 +61,28 @@ ${config.URL.BASE}${config.GIGS_PAGES_PATH}/${props.id}`,
62
61
if ( profile . email === email ) {
63
62
this . setState ( {
64
63
isReferrError : {
65
- message : 'We not allow sending to yourself.' ,
64
+ message : 'You are not allowed to send to yourself.' ,
66
65
userError : true ,
67
66
} ,
68
67
} ) ;
69
68
// exit no email sending
70
69
return ;
71
70
}
72
71
// process sent log
73
- let { emailInvitesLog } = growSurf . data . metadata ;
74
- if ( ! emailInvitesLog ) emailInvitesLog = [ ] ;
72
+ let { emailInvitesLog, emailInvitesStatus } = growSurf . data . metadata ;
73
+ if ( ! emailInvitesLog ) emailInvitesLog = '' ;
75
74
// 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 ) {
78
77
this . setState ( {
79
78
isReferrError : {
80
- message : `${ email } was already invited on ${ foundInLog . d } .` ,
79
+ message : `${ email } was already invited.` ,
81
80
userError : true ,
82
81
} ,
83
82
} ) ;
84
83
// exit no email sending
85
84
return ;
86
85
}
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
- }
96
86
// check if email is already referred?
97
87
const growCheck = await fetch ( `${ PROXY_ENDPOINT } /growsurf/participant/${ email } ` ) ;
98
88
if ( growCheck . status === 200 ) {
@@ -108,7 +98,7 @@ ${config.URL.BASE}${config.GIGS_PAGES_PATH}/${props.id}`,
108
98
return ;
109
99
}
110
100
}
111
- // email the invite
101
+ // // email the invite
112
102
const res = await fetch ( `${ PROXY_ENDPOINT } /mailchimp/email` , {
113
103
method : 'POST' ,
114
104
body : JSON . stringify ( {
@@ -135,7 +125,20 @@ ${config.URL.BASE}${config.GIGS_PAGES_PATH}/${props.id}`,
135
125
// exit no email tracking due to the error
136
126
return ;
137
127
}
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
139
142
const updateRed = await fetch ( `${ PROXY_ENDPOINT } /growsurf/participant/${ growSurf . data . id } ` , {
140
143
method : 'PATCH' ,
141
144
headers : {
@@ -147,7 +150,8 @@ ${config.URL.BASE}${config.GIGS_PAGES_PATH}/${props.id}`,
147
150
metadata : {
148
151
...growSurf . data . metadata ,
149
152
emailInvitesSent : Number ( growSurf . data . metadata . emailInvitesSent || 0 ) + 1 ,
150
- emailInvitesLog : newEmailInvitesLog ,
153
+ emailInvitesLog : emailInvitesLog . join ( ) ,
154
+ emailInvitesStatus,
151
155
} ,
152
156
} ) ,
153
157
} ) ;
0 commit comments