merge new features #9
@@ -7,15 +7,14 @@
|
|||||||
|
|
||||||
let { data, form } = $props();
|
let { data, form } = $props();
|
||||||
|
|
||||||
let new_event = $state({});
|
let event = $state({});
|
||||||
let participants = $state([]);
|
let participants = $state([]);
|
||||||
let subject = $state('');
|
let email = $state({'body': '', 'subject': ''});
|
||||||
let body = $state('');
|
|
||||||
let authorized = $state(false);
|
let authorized = $state(false);
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (form && form.new_event) {
|
if (form && form.new_event) {
|
||||||
new_event = form.new_event;
|
event = form.new_event;
|
||||||
}
|
}
|
||||||
if (form && form.participants) {
|
if (form && form.participants) {
|
||||||
participants = form.participants;
|
participants = form.participants;
|
||||||
@@ -33,12 +32,20 @@
|
|||||||
|
|
||||||
let step: number = $state(0);
|
let step: number = $state(0);
|
||||||
|
|
||||||
let stepConditions = $derived([
|
// let stepConditions = $derived([
|
||||||
authorized,
|
// authorized,
|
||||||
!!new_event?.name,
|
// !!new_event?.name,
|
||||||
!!participants?.length,
|
// !!participants?.length,
|
||||||
!!subject && !!body
|
// !!subject && !!body
|
||||||
]);
|
// ]);
|
||||||
|
|
||||||
|
// for debugging purpouses
|
||||||
|
let stepConditions = [
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true
|
||||||
|
];
|
||||||
|
|
||||||
function nextStep() {
|
function nextStep() {
|
||||||
if (step < steps.length - 1) step += 1;
|
if (step < steps.length - 1) step += 1;
|
||||||
@@ -71,17 +78,17 @@
|
|||||||
{#if step == 0}
|
{#if step == 0}
|
||||||
<StepConnectGoogle bind:authorized />
|
<StepConnectGoogle bind:authorized />
|
||||||
{:else if step == 1}
|
{:else if step == 1}
|
||||||
<StepCreateEvent events={data.events} {new_event} />
|
<StepCreateEvent {event} />
|
||||||
{:else if step == 2}
|
{:else if step == 2}
|
||||||
<StepUploadFiles {participants} />
|
<StepUploadFiles {participants} />
|
||||||
{:else if step == 3}
|
{:else if step == 3}
|
||||||
<StepCraftEmail bind:subject bind:body />
|
<StepCraftEmail bind:email />
|
||||||
{:else if step == 4}
|
{:else if step == 4}
|
||||||
<StepOverview
|
<StepOverview
|
||||||
{new_event}
|
{data}
|
||||||
|
{event}
|
||||||
{participants}
|
{participants}
|
||||||
{subject}
|
{email}
|
||||||
{body}
|
|
||||||
{stepConditions}
|
{stepConditions}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let subject: string;
|
export let email: { subject: string, body: string } = { subject: '', body: '' };
|
||||||
export let body: string;
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form class="flex flex-col space-y-4 bg-white p-8 rounded border border-gray-300 w-full shadow-none">
|
<form class="flex flex-col space-y-4 bg-white p-8 rounded border border-gray-300 w-full shadow-none">
|
||||||
@@ -9,7 +8,7 @@
|
|||||||
Subject
|
Subject
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
bind:value={subject}
|
bind:value={email.subject}
|
||||||
class="mt-1 px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-200"
|
class="mt-1 px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-200"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
@@ -17,7 +16,7 @@
|
|||||||
<label class="flex flex-col text-gray-700">
|
<label class="flex flex-col text-gray-700">
|
||||||
Body
|
Body
|
||||||
<textarea
|
<textarea
|
||||||
bind:value={body}
|
bind:value={email.body}
|
||||||
class="mt-1 px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-200 resize-none"
|
class="mt-1 px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-200 resize-none"
|
||||||
rows="6"
|
rows="6"
|
||||||
required
|
required
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { enhance } from '$app/forms';
|
import { enhance } from '$app/forms';
|
||||||
|
|
||||||
let { events, new_event } = $props();
|
let { event } = $props();
|
||||||
let loading = $state(false);
|
let loading = $state(false);
|
||||||
|
|
||||||
function handleEnhance() {
|
function handleEnhance() {
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{#if Object.keys(new_event).length === 0}
|
{#if Object.keys(event).length === 0}
|
||||||
<div class="mt-4 rounded border-l-4 border-gray-500 bg-gray-100 p-4 text-gray-700">
|
<div class="mt-4 rounded border-l-4 border-gray-500 bg-gray-100 p-4 text-gray-700">
|
||||||
{#if loading}
|
{#if loading}
|
||||||
<strong>Loading...</strong>
|
<strong>Loading...</strong>
|
||||||
@@ -63,9 +63,9 @@
|
|||||||
{:else}
|
{:else}
|
||||||
<div class="rounded border-l-4 border-green-500 bg-green-100 p-4 text-green-700 mt-4">
|
<div class="rounded border-l-4 border-green-500 bg-green-100 p-4 text-green-700 mt-4">
|
||||||
<ol>
|
<ol>
|
||||||
<li><strong>{new_event.name}</strong></li>
|
<li><strong>{event.name}</strong></li>
|
||||||
<li>{new_event.date}</li>
|
<li>{event.date}</li>
|
||||||
<li>{new_event.description}</li>
|
<li>{event.description}</li>
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
59
src/routes/private/creator/steps/StepFinal.svelte
Normal file
59
src/routes/private/creator/steps/StepFinal.svelte
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import QRCode from 'qrcode';
|
||||||
|
|
||||||
|
const StepState = {
|
||||||
|
Waiting: 'waiting',
|
||||||
|
Processing: 'processing',
|
||||||
|
FinishedSuccess: 'finished_success',
|
||||||
|
FinishedFail: 'finished_fail'
|
||||||
|
};
|
||||||
|
|
||||||
|
let qr_codes_state = $state(StepState.Processing);
|
||||||
|
let emails_state = $state(StepState.FinishedSuccess);
|
||||||
|
|
||||||
|
// Inserts all participants into the database and returns their assigned IDs.
|
||||||
|
async function insert_data_supabase(data, participants, new_event) {
|
||||||
|
const names = participants.map((p) => p.name);
|
||||||
|
const surnames = participants.map((p) => p.surname);
|
||||||
|
const emails = participants.map((p) => p.email);
|
||||||
|
const {
|
||||||
|
data: { user },
|
||||||
|
error: authError
|
||||||
|
} = await data.supabase.auth.getUser();
|
||||||
|
const { data: user_profile, error: profileError } = await data.supabase
|
||||||
|
.from('profiles')
|
||||||
|
.select('*, section:sections (id, name)')
|
||||||
|
.eq('id', user?.id)
|
||||||
|
.single();
|
||||||
|
const { data: result, error: qrCodeError } = await data.supabase.rpc('create_qrcodes_bulk', {
|
||||||
|
p_section_id: user_profile?.section.id,
|
||||||
|
p_event_id: new_event.id,
|
||||||
|
p_names: names,
|
||||||
|
p_surnames: surnames,
|
||||||
|
p_emails: emails
|
||||||
|
});
|
||||||
|
|
||||||
|
return { result };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Creates a base64 interpretation of the ticket ID
|
||||||
|
function createB64QRCode(data) {
|
||||||
|
QRCode.toDataURL('I am a pony!')
|
||||||
|
.then((url) => {
|
||||||
|
const parts = url.split(',');
|
||||||
|
return { base64data: parts[1] };
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendEmail(email, subject, body, qr_code_base64) {
|
||||||
|
// Here you would implement the logic to send the email.
|
||||||
|
// This is a placeholder function.
|
||||||
|
console.log(`Sending email to ${email} with subject "${subject}" and body "${body}"`);
|
||||||
|
console.log(`QR Code Base64: ${qr_code_base64}`);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
Pl
|
||||||
Reference in New Issue
Block a user