- Sirkul logo everywhere (header wordmark, phone monogram, favicon, footer); brand name "Sirkul Makeup" - One font (Plus Jakarta Sans) across app and waitlist; cursive serif removed - Habesha model photos from Wikimedia Commons (CC BY-SA, credited in footer and waitlist) - Landing: light/dark theme toggle, live waitlist pill, photo category cards, how-it-works + grouped payment panel, photo CTA; less emphasis on languages - Footer: framed card with starter-kit list (IconPark icons), student-work photo reel, credits - Waitlist: international country-code picker, live "people waiting" pill fed by a doGet signup count in the Apps Script (count only, no personal data) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
3.0 KiB
JavaScript
65 lines
3.0 KiB
JavaScript
/**
|
|
* Waitlist receiver for apps/demo/public/waitlist/index.html → one row per signup in a Google Sheet.
|
|
*
|
|
* Setup (once, in the Google account that should own the list):
|
|
* 1. Create a Google Sheet, e.g. "Sirkul Makeup waitlist".
|
|
* 2. Extensions → Apps Script. Replace Code.gs with this file and save.
|
|
* 3. Deploy → New deployment → type "Web app". Execute as: Me. Who has access: Anyone.
|
|
* 4. Authorize, then copy the Web app URL (ends in /exec).
|
|
* 5. Paste it into ENDPOINT (the page POSTs signups and GETs the count) in apps/demo/public/waitlist/index.html, then commit and deploy.
|
|
* After editing this script, use Deploy → Manage deployments → Edit → New version (the URL stays the same).
|
|
*/
|
|
const SHEET_NAME = 'Signups';
|
|
const HEADER = ['Signed up (UTC)', 'Name', 'Email', 'Phone', 'Language', 'Page'];
|
|
|
|
function doPost(e) {
|
|
let data;
|
|
try { data = JSON.parse((e && e.postData && e.postData.contents) || '{}'); } catch (_) { return reply({ ok: false, error: 'bad_json' }); }
|
|
if (data.company) return reply({ ok: true }); // honeypot filled → bot; pretend success
|
|
const row = clean(data);
|
|
if (row.error) return reply({ ok: false, error: row.error });
|
|
|
|
const lock = LockService.getScriptLock();
|
|
lock.waitLock(10000);
|
|
try {
|
|
const sheet = getSheet();
|
|
const last = sheet.getLastRow();
|
|
const emails = last > 1 ? sheet.getRange(2, 3, last - 1, 1).getValues().map((r) => String(r[0]).toLowerCase()) : [];
|
|
if (emails.indexOf(row.email) === -1) {
|
|
sheet.appendRow([new Date().toISOString(), safe(row.name), safe(row.email), "'" + row.phone, safe(row.locale), safe(row.page)]);
|
|
}
|
|
} finally { lock.releaseLock(); }
|
|
return reply({ ok: true });
|
|
}
|
|
|
|
/** Public signup count for the page's "people waiting" pill. Only the number leaves the sheet. */
|
|
function doGet() {
|
|
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_NAME);
|
|
return reply({ ok: true, count: sheet ? Math.max(0, sheet.getLastRow() - 1) : 0 });
|
|
}
|
|
|
|
/** Server-side check: the page validates too, but anyone can POST here. */
|
|
function clean(d) {
|
|
const name = String(d.name || '').trim().slice(0, 80);
|
|
const email = String(d.email || '').trim().toLowerCase().slice(0, 120);
|
|
const phone = String(d.phone || '').replace(/[\s()-]/g, '');
|
|
if (name.length < 2) return { error: 'name' };
|
|
if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email)) return { error: 'email' };
|
|
if (!/^\+\d{8,15}$/.test(phone)) return { error: 'phone' };
|
|
return { name, email, phone, locale: String(d.locale || '').slice(0, 20), page: String(d.page || '').slice(0, 200) };
|
|
}
|
|
|
|
/** Cells starting with = + - @ would run as formulas when someone opens the sheet. */
|
|
function safe(v) { return /^[=+\-@]/.test(v) ? "'" + v : v; }
|
|
|
|
function getSheet() {
|
|
const ss = SpreadsheetApp.getActiveSpreadsheet();
|
|
let sheet = ss.getSheetByName(SHEET_NAME);
|
|
if (!sheet) { sheet = ss.insertSheet(SHEET_NAME); sheet.appendRow(HEADER); sheet.setFrozenRows(1); }
|
|
return sheet;
|
|
}
|
|
|
|
function reply(obj) {
|
|
return ContentService.createTextOutput(JSON.stringify(obj)).setMimeType(ContentService.MimeType.JSON);
|
|
}
|