Compare commits
3 Commits
c24a845999
...
c063c1c5c4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c063c1c5c4 | ||
|
|
297641ee2d | ||
|
|
2c2ee18fa3 |
@@ -4,8 +4,6 @@ import Papa from 'papaparse';
|
|||||||
import { fail } from '@sveltejs/kit';
|
import { fail } from '@sveltejs/kit';
|
||||||
|
|
||||||
export async function load({ locals }) {
|
export async function load({ locals }) {
|
||||||
console.log("▶️ fetching events…");
|
|
||||||
|
|
||||||
const { data: events, error } = await locals.supabase
|
const { data: events, error } = await locals.supabase
|
||||||
.from('events')
|
.from('events')
|
||||||
.select('*')
|
.select('*')
|
||||||
@@ -23,8 +21,6 @@ export async function load({ locals }) {
|
|||||||
export const actions = {
|
export const actions = {
|
||||||
create: async (event) => {
|
create: async (event) => {
|
||||||
const formData = await event.request.formData();
|
const formData = await event.request.formData();
|
||||||
console.log(Array.from(formData.entries()));
|
|
||||||
console.log('create_event date', formData.get("date"), formData.get("name"), formData.get("description"));
|
|
||||||
let { data: new_event, error } = await event.locals.supabase.rpc("create_event",
|
let { data: new_event, error } = await event.locals.supabase.rpc("create_event",
|
||||||
{
|
{
|
||||||
"p_name": formData.get('name'),
|
"p_name": formData.get('name'),
|
||||||
@@ -51,8 +47,6 @@ export const actions = {
|
|||||||
parsedRows.shift();
|
parsedRows.shift();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Parsed rows:', parsedRows);
|
|
||||||
|
|
||||||
// Map each row to an object with keys: name, surname, email
|
// Map each row to an object with keys: name, surname, email
|
||||||
const participants = parsedRows.map((row: string[]) => ({
|
const participants = parsedRows.map((row: string[]) => ({
|
||||||
name: row[0],
|
name: row[0],
|
||||||
@@ -60,8 +54,6 @@ export const actions = {
|
|||||||
email: row[2]
|
email: row[2]
|
||||||
}));
|
}));
|
||||||
|
|
||||||
console.log('Mapped participants:', participants);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
participants,
|
participants,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
let participants = $state([]);
|
let participants = $state([]);
|
||||||
let subject = $state('');
|
let subject = $state('');
|
||||||
let body = $state('');
|
let body = $state('');
|
||||||
|
let authorized = $state(false);
|
||||||
|
|
||||||
// Update events and participants from the form data
|
$effect(() => {
|
||||||
$effect( () => {
|
|
||||||
if (form && form.new_event) {
|
if (form && form.new_event) {
|
||||||
new_event = form.new_event;
|
new_event = form.new_event;
|
||||||
}
|
}
|
||||||
@@ -31,17 +31,20 @@
|
|||||||
StepOverview
|
StepOverview
|
||||||
];
|
];
|
||||||
|
|
||||||
// State variable for current step
|
let step: number = $state(0);
|
||||||
let step = $state(0);
|
|
||||||
|
let stepConditions = $derived([
|
||||||
|
authorized,
|
||||||
|
!!new_event?.name,
|
||||||
|
!!participants?.length,
|
||||||
|
!!subject && !!body
|
||||||
|
]);
|
||||||
|
|
||||||
// Helper to go to next/previous step (optional)
|
|
||||||
function nextStep() {
|
function nextStep() {
|
||||||
if (step < steps.length - 1) step += 1;
|
if (step < steps.length - 1) step += 1;
|
||||||
console.log(step);
|
|
||||||
}
|
}
|
||||||
function prevStep() {
|
function prevStep() {
|
||||||
if (step > 0) step -= 1;
|
if (step > 0) step -= 1;
|
||||||
console.log(step);
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -58,16 +61,15 @@
|
|||||||
</span>
|
</span>
|
||||||
<button
|
<button
|
||||||
onclick={nextStep}
|
onclick={nextStep}
|
||||||
disabled={step === steps.length - 1}
|
disabled={step === steps.length - 1 || !stepConditions[step]}
|
||||||
class="min-w-[100px] py-2 px-4 bg-white border border-gray-300 text-gray-700 rounded hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed transition"
|
class="min-w-[100px] py-2 px-4 bg-white border border-gray-300 text-gray-700 rounded hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed transition"
|
||||||
>
|
>
|
||||||
Next
|
Next
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Render the current step component -->
|
|
||||||
{#if step == 0}
|
{#if step == 0}
|
||||||
<StepConnectGoogle />
|
<StepConnectGoogle bind:authorized />
|
||||||
{:else if step == 1}
|
{:else if step == 1}
|
||||||
<StepCreateEvent events={data.events} {new_event} />
|
<StepCreateEvent events={data.events} {new_event} />
|
||||||
{:else if step == 2}
|
{:else if step == 2}
|
||||||
@@ -75,5 +77,11 @@
|
|||||||
{:else if step == 3}
|
{:else if step == 3}
|
||||||
<StepCraftEmail bind:subject bind:body />
|
<StepCraftEmail bind:subject bind:body />
|
||||||
{:else if step == 4}
|
{:else if step == 4}
|
||||||
<StepOverview {new_event} {participants} {subject} {body} />
|
<StepOverview
|
||||||
|
{new_event}
|
||||||
|
{participants}
|
||||||
|
{subject}
|
||||||
|
{body}
|
||||||
|
{stepConditions}
|
||||||
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
|
|
||||||
|
export let authorized = false;
|
||||||
|
|
||||||
let refreshToken = '';
|
let refreshToken = '';
|
||||||
let authorized = false;
|
|
||||||
let loading = true;
|
let loading = true;
|
||||||
|
|
||||||
let to = '';
|
let to = '';
|
||||||
@@ -32,22 +33,6 @@
|
|||||||
/* ⇢ redirects straight to Google via server 302 */
|
/* ⇢ redirects straight to Google via server 302 */
|
||||||
const connect = () => goto('/private/api/gmail?action=auth');
|
const connect = () => goto('/private/api/gmail?action=auth');
|
||||||
|
|
||||||
async function sendEmail() {
|
|
||||||
const r = await fetch('/private/api/gmail', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({
|
|
||||||
action: 'send',
|
|
||||||
to,
|
|
||||||
subject,
|
|
||||||
text: body,
|
|
||||||
refreshToken
|
|
||||||
})
|
|
||||||
});
|
|
||||||
r.ok ? alert('Sent!') : alert(await r.text());
|
|
||||||
to = subject = body = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
async function disconnect() {
|
async function disconnect() {
|
||||||
if (!confirm('Disconnect Google account?')) return;
|
if (!confirm('Disconnect Google account?')) return;
|
||||||
await fetch('/private/api/gmail', {
|
await fetch('/private/api/gmail', {
|
||||||
|
|||||||
@@ -1,43 +1,62 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
let { new_event, participants, subject, body } = $props();
|
let { new_event, participants, subject, body, stepConditions } = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- New Event Overview -->
|
<!-- New Event Overview -->
|
||||||
<div class="bg-white border border-gray-300 rounded p-4 mb-4">
|
<div class="mb-4 rounded border border-gray-300 bg-white p-4">
|
||||||
<h2 class="text-xl font-bold mb-2">Event Overview</h2>
|
<h2 class="mb-2 text-xl font-bold">Event Overview</h2>
|
||||||
<ul class="space-y-1">
|
<ul class="space-y-1">
|
||||||
<li><span class="font-semibold">Name:</span> {new_event.name}</li>
|
<li><span class="font-semibold">Name:</span> {new_event.name}</li>
|
||||||
<li><span class="font-semibold">Date:</span> {new_event.date}</li>
|
<li><span class="font-semibold">Date:</span> {new_event.date}</li>
|
||||||
<li><span class="font-semibold">Description:</span> {new_event.description}</li>
|
<li><span class="font-semibold">Description:</span> {new_event.description}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Email Overview -->
|
<!-- Email Overview -->
|
||||||
<div class="bg-white border border-gray-300 rounded p-4 mb-4">
|
<div class="mb-4 rounded border border-gray-300 bg-white p-4">
|
||||||
<h2 class="text-xl font-bold mb-2">Email Preview</h2>
|
<h2 class="mb-2 text-xl font-bold">Email Preview</h2>
|
||||||
<div class="mb-2"><span class="font-semibold">Subject:</span> {subject}</div>
|
<div class="mb-2"><span class="font-semibold">Subject:</span> {subject}</div>
|
||||||
<div class="whitespace-pre-line border rounded p-2 bg-gray-50 text-gray-700"><span class="font-semibold"></span>
|
<div class="rounded border bg-gray-50 p-2 whitespace-pre-line text-gray-700">
|
||||||
<div>{body}</div>
|
<span class="font-semibold"></span>
|
||||||
</div>
|
<div>{body}</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Participants Overview -->
|
<!-- Participants Overview -->
|
||||||
<div class="bg-white border border-gray-300 rounded p-4">
|
<div class="rounded border border-gray-300 bg-white p-4">
|
||||||
<h2 class="text-xl font-bold mb-2">Participants ({participants.length})</h2>
|
<h2 class="mb-2 text-xl font-bold">Participants ({participants.length})</h2>
|
||||||
<ul class="space-y-1">
|
<ul class="space-y-1">
|
||||||
{#each participants.slice(0, 10) as p}
|
{#each participants.slice(0, 10) as p}
|
||||||
<li class="flex items-center gap-2 border-b last:border-b-0 pb-1">
|
<li class="flex items-center gap-2 border-b pb-1 last:border-b-0">
|
||||||
<span class="font-semibold">{p.name} {p.surname}</span>
|
<span class="font-semibold">{p.name} {p.surname}</span>
|
||||||
<span class="flex-1"></span>
|
<span class="flex-1"></span>
|
||||||
<span class="font-mono text-xs text-gray-600 text-right">{p.email}</span>
|
<span class="text-right font-mono text-xs text-gray-600">{p.email}</span>
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
<p class="text-sm text-gray-500 mt-2">Note: Only the first 10 participants are shown.</p>
|
<p class="mt-2 text-sm text-gray-500">Note: Only the first 10 participants are shown.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
class="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-4 rounded mt-4 transition-colors duration-200"
|
class="mt-4 w-full rounded bg-blue-600 px-4 py-3 font-bold text-white
|
||||||
|
transition-colors duration-200 hover:bg-blue-700
|
||||||
|
disabled:cursor-not-allowed disabled:bg-gray-300 disabled:text-gray-500"
|
||||||
|
disabled={!stepConditions.every(Boolean)}
|
||||||
>
|
>
|
||||||
Generate QR codes and send
|
Generate QR codes and send
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<div class="mt-2 space-y-1">
|
||||||
|
{#if !stepConditions[0]}
|
||||||
|
<p class="text-sm text-red-500">Please provide an event name before proceeding.</p>
|
||||||
|
{/if}
|
||||||
|
{#if !stepConditions[1]}
|
||||||
|
<p class="text-sm text-red-500">Please add at least one participant before proceeding.</p>
|
||||||
|
{/if}
|
||||||
|
{#if !stepConditions[2]}
|
||||||
|
<p class="text-sm text-red-500">Please provide an email subject before proceeding.</p>
|
||||||
|
{/if}
|
||||||
|
{#if !stepConditions[3]}
|
||||||
|
<p class="text-sm text-red-500">Please provide an email body before proceeding.</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (scanned_id === "") return;
|
if (scanned_id === "") return;
|
||||||
console.log('New QR code found:', scanned_id);
|
|
||||||
scan_state = ScanState.scanning;
|
scan_state = ScanState.scanning;
|
||||||
|
|
||||||
data.supabase
|
data.supabase
|
||||||
|
|||||||
Reference in New Issue
Block a user