diff --git a/src/pages/apply.astro b/src/pages/apply.astro index 10c904c..d29164a 100644 --- a/src/pages/apply.astro +++ b/src/pages/apply.astro @@ -137,6 +137,8 @@ import '../styles/apply.scss'; // === PASTE YOUR GOOGLE SCRIPT URL HERE ONCE === const SCRIPT_URL = 'https://script.google.com/macros/s/AKfycby_xG6EGVuLXvgs9ro20rMkK2zSyElPCHeMU_2F2Q_0WE08gtCNzrO-SEyjDAqS46Hr/exec'; + const STATUS_CSV_URL = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vRZvHQma9ZHzgyb3tmkCzXKZVpW9esnVAOQEN994ZuUvszO6dhE4fzq0psXLA2lTtDuefUIXNQvvfN_/pub?gid=202325095&single=true&output=csv'; + // --- ELEMENTS --- const loadingStatus = document.getElementById('loading-status'); const closedMessage = document.getElementById('closed-message'); @@ -150,24 +152,24 @@ import '../styles/apply.scss'; const loadingMsg = document.getElementById('loading-msg'); const successMsg = document.getElementById('success-message'); - // --- STEP 1: CHECK GOOGLE SHEET STATUS --- - // Added the protective if-statement here! + // --- STEP 1: CHECK GOOGLE SHEET STATUS VIA CSV --- if (loadingStatus && closedMessage && registrationContent) { - fetch(SCRIPT_URL) - .then(response => response.json()) - .then(data => { - loadingStatus.style.display = 'none'; // Hide the spinner + // We fetch the lightning-fast CSV instead of the script + fetch(STATUS_CSV_URL) + .then(response => response.text()) // Parse it as raw text, not JSON + .then(csvText => { + loadingStatus.style.display = 'none'; - // Look at the B1 cell value from the Google Sheet - if (data.status === 'OPEN') { - registrationContent.style.display = 'block'; // Reveal the portal! + // CSV text usually comes with a newline at the end, so we use .trim() to clean it + // We also check if it includes 'OPEN' just in case there are other headers + if (csvText.trim().includes('OPEN')) { + registrationContent.style.display = 'block'; } else { - closedMessage.style.display = 'block'; // Show the closed message + closedMessage.style.display = 'block'; } }) .catch(error => { - console.error("Status check failed:", error); // Added this to clear the warning - // If the internet is down or script fails, fail gracefully by showing closed + console.error("Status check failed:", error); loadingStatus.style.display = 'none'; closedMessage.style.display = 'block'; });