@@ -115,8 +115,8 @@ export async function fetchMemberInfo(eid) {
115115 throw new Error ( 'Failed to load membership data' ) ;
116116 }
117117
118- // Check if any data was returned
119- const memberExists = membershipRows && membershipRows . length > 1 ; // More than just headers
118+ // Use the checkMemberExists helper to determine if the member exists
119+ const memberExists = checkMemberExists ( eid ) ;
120120
121121 // Update the status message if element exists
122122 if ( statusElement ) {
@@ -186,6 +186,31 @@ export function getPurchasesByEid(eid) {
186186 return purchasesByEid . get ( eid . toLowerCase ( ) ) || null ;
187187}
188188
189+ /**
190+ * Check if a member with the given EID exists in the loaded data
191+ * @param {string } eid - The EID to check
192+ * @returns {boolean } - True if the member exists
193+ */
194+ export function checkMemberExists ( eid ) {
195+ // If no data loaded or no EID provided, return false
196+ if ( ! membershipRows || ! eid ) return false ;
197+
198+ // Normalize the search EID
199+ const normalizedSearchEid = eid . trim ( ) . toLowerCase ( ) ;
200+
201+ // Check if there's an EID match in the first column
202+ for ( let i = 1 ; i < membershipRows . length ; i ++ ) {
203+ if ( membershipRows [ i ] . length > 0 ) {
204+ const rowEid = membershipRows [ i ] [ 0 ] . trim ( ) . toLowerCase ( ) ;
205+ if ( rowEid === normalizedSearchEid ) {
206+ return true ;
207+ }
208+ }
209+ }
210+
211+ return false ;
212+ }
213+
189214/**
190215 * Check if membership data is loaded
191216 * @returns {boolean } - True if data is loaded
@@ -248,12 +273,17 @@ function initializeModule() {
248273 setTimeout ( ( ) => {
249274 loadMembershipData ( currentEid ) . then ( success => {
250275 if ( success ) {
251- console . log ( `Auto-loaded membership data for ${ currentEid } ` ) ;
276+ // Check if member truly exists by exact EID match
277+ const memberExists = checkMemberExists ( currentEid ) ;
278+
279+ console . log ( `Auto-loaded membership data for ${ currentEid } , member exists: ${ memberExists } ` ) ;
280+
252281 // Dispatch a custom event that other scripts can listen for
253282 document . dispatchEvent ( new CustomEvent ( 'eidDataLoaded' , {
254283 detail : {
255284 eid : currentEid ,
256- success : true
285+ success : true ,
286+ memberExists : memberExists
257287 }
258288 } ) ) ;
259289 }
0 commit comments