@@ -68,21 +68,6 @@ ${config.URL.BASE}${config.GIGS_PAGES_PATH}/${props.id}`,
6868 // exit no email sending
6969 return ;
7070 }
71- // process sent log
72- let { emailInvitesLog, emailInvitesStatus } = growSurf . data . metadata ;
73- if ( ! emailInvitesLog ) emailInvitesLog = '' ;
74- // check if email is in sent log alredy?
75- const foundInLog = emailInvitesLog . indexOf ( email ) ;
76- if ( foundInLog !== - 1 ) {
77- this . setState ( {
78- isReferrError : {
79- message : `${ email } was already invited.` ,
80- userError : true ,
81- } ,
82- } ) ;
83- // exit no email sending
84- return ;
85- }
8671 // check if email is already referred?
8772 const growCheck = await fetch ( `${ PROXY_ENDPOINT } /growsurf/participant/${ email } ` ) ;
8873 if ( growCheck . status === 200 ) {
@@ -125,43 +110,51 @@ ${config.URL.BASE}${config.GIGS_PAGES_PATH}/${props.id}`,
125110 // exit no email tracking due to the error
126111 return ;
127112 }
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
142- const updateRed = await fetch ( `${ PROXY_ENDPOINT } /growsurf/participant/${ growSurf . data . id } ` , {
143- method : 'PATCH' ,
144- headers : {
145- 'Content-Type' : 'application/json' ,
146- Authorization : `Bearer ${ tokenV3 } ` ,
147- } ,
148- body : JSON . stringify ( {
149- ...growSurf . data ,
150- metadata : {
151- ...growSurf . data . metadata ,
152- emailInvitesSent : Number ( growSurf . data . metadata . emailInvitesSent || 0 ) + 1 ,
153- emailInvitesLog : emailInvitesLog . join ( ) ,
154- emailInvitesStatus,
113+ // process sent log
114+ let { emailInvitesLog, emailInvitesStatus } = growSurf . data . metadata ;
115+ if ( ! emailInvitesLog ) emailInvitesLog = '' ;
116+ // check if email is in sent log alredy?
117+ const foundInLog = emailInvitesLog . indexOf ( email ) ;
118+ // only when email is new - put it in log, update counters and etc.
119+ if ( foundInLog === - 1 ) {
120+ // parse the log to array of emails
121+ if ( emailInvitesLog . length ) {
122+ emailInvitesLog = emailInvitesLog . split ( ',' ) ;
123+ } else emailInvitesLog = [ ] ;
124+ // prepare growSurf update payload
125+ // we keep only 10 emails in the log to justify program rules
126+ if ( emailInvitesLog . length < 10 ) {
127+ emailInvitesLog . push ( email ) ;
128+ }
129+ // Auto change status when 10 emails sent
130+ if ( emailInvitesLog . length === 10 && emailInvitesStatus !== 'Paid' && emailInvitesStatus !== 'Payment Pending' ) {
131+ emailInvitesStatus = 'Payment Pending' ;
132+ }
133+ // put the tracking update in growsurf
134+ const updateRed = await fetch ( `${ PROXY_ENDPOINT } /growsurf/participant/${ growSurf . data . id } ` , {
135+ method : 'PATCH' ,
136+ headers : {
137+ 'Content-Type' : 'application/json' ,
138+ Authorization : `Bearer ${ tokenV3 } ` ,
155139 } ,
156- } ) ,
157- } ) ;
158- if ( updateRed . status >= 300 ) {
159- this . setState ( {
160- isReferrError : await updateRed . json ( ) ,
140+ body : JSON . stringify ( {
141+ ...growSurf . data ,
142+ metadata : {
143+ ...growSurf . data . metadata ,
144+ emailInvitesSent : Number ( growSurf . data . metadata . emailInvitesSent || 0 ) + 1 ,
145+ emailInvitesLog : emailInvitesLog . join ( ) ,
146+ emailInvitesStatus,
147+ } ,
148+ } ) ,
161149 } ) ;
162- // exit no email tracking due to the error
163- // just notify the user about it
164- return ;
150+ if ( updateRed . status >= 300 ) {
151+ this . setState ( {
152+ isReferrError : await updateRed . json ( ) ,
153+ } ) ;
154+ // exit no email tracking due to the error
155+ // just notify the user about it
156+ return ;
157+ }
165158 }
166159 // finally do:
167160 this . setState ( {
0 commit comments