diff --git a/src/routes/events_leads/exhibit/[slug]/+page.svelte b/src/routes/events_leads/exhibit/[slug]/+page.svelte index b895a656..bf0f90c7 100644 --- a/src/routes/events_leads/exhibit/[slug]/+page.svelte +++ b/src/routes/events_leads/exhibit/[slug]/+page.svelte @@ -152,12 +152,54 @@ async function handle_submit_form(event) { // Data out let exhibit_do: key_val = {}; - let exhibit_do__license_li_json: key_val = {}; + // let exhibit_do__license_li_json: key_val = {}; // example: {"scott.idem@oneskyit.com": {"passcode": "12345", "updated_on": "2024-03-04T15:29:59"}, "test+holly@oneskyit.com": {"passcode": "12345", "updated_on": "2024-03-13T15:20:59"}} - if (typeof exhibit_di.passcode !== 'undefined') { - exhibit_do__license_li_json['passcode'] = exhibit_di.passcode; + + let exhibit_do__license_li_json: key_val[] = []; + if (typeof exhibit_di.license_max !== 'undefined') { + exhibit_do['license_max'] = exhibit_di.license_max; + + // Loop through the form data licenses up to the license max and create the license list JSON object. The license related fields are prefixed with "license_". This should be pushed to the exhibit_do__license_li_json list. + // for (let i = 0; i < exhibit_di.license_max; i++) { + for (let i = 0; i < (exhibit_di.license_max && 10); i++) { + // let license_key = exhibit_di[`license_${i}`]; + let license_email = exhibit_di[`license_${i}_email`]; + let license_full_name = exhibit_di[`license_${i}_full_name`]; + let license_passcode = exhibit_di[`license_${i}_passcode`]; + if (!license_passcode) { + // Generate a random 8 character passcode using a mix of lowercase letters and numbers. + license_passcode = Math.random().toString(36).substring(2, 10); + } + + // if (license_key && license_email && license_full_name && license_passcode) { + // exhibit_do__license_li_json.push({ + // [license_key]: { + // "email": license_email, + // "full_name": license_full_name, + // "passcode": license_passcode, + // 'updated_on': new Date().toISOString() + // } + // }); + // } + + if (license_email && license_full_name && license_passcode) { + exhibit_do__license_li_json.push({ + "email": license_email, + "full_name": license_full_name, + "passcode": license_passcode, + "session_count": 0, // Max 3 browser sessions? + 'updated_on': new Date().toISOString() + }); + } + } + + } + // if (typeof exhibit_di.license_1 !== 'undefined' && typeof exhibit_di.license_1_passcode !== 'undefined') { + // exhibit_do__license_li_json['passcode'] = exhibit_di.passcode; + // } + exhibit_do['license_li_json'] = exhibit_do__license_li_json; console.log('exhibit_do:', exhibit_do); @@ -284,8 +326,24 @@ function send_init_confirm_email({to_email}) { -{#if $event_exhibit_obj?.license_li_json} +{#if $event_exhibit_obj?.license_li_json.length < $event_exhibit_obj?.license_max} + +{:else} +No more! +{/if} +{#if $event_exhibit_obj?.license_max }