Skip to content

Commit

Permalink
registration
Browse files Browse the repository at this point in the history
  • Loading branch information
allurei committed Dec 27, 2024
1 parent 63b235e commit fa4fdb6
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 57 deletions.
4 changes: 3 additions & 1 deletion src/lib/components/ilmo.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script>
import Ilmoformi from "$lib/components/ilmoformi.svelte";
export let id = 'ilmo';
export let form;
export let invited = false
</script>

<Ilmoformi invited={true} id />
<Ilmoformi {invited} {id} {form} />
78 changes: 59 additions & 19 deletions src/lib/components/ilmoformi.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { page } from '$app/stores';
export let invited = false;
export let id = 'ilmo';
export let form;
let fi = true;
let is_greeting = 'yes';
Expand All @@ -11,27 +12,32 @@
<div class="wrap">
<div class="flex-items bordered flower-bg">
<h2>Ilmoittautuminen</h2>
<form method="POST" action="?/{invited ? 'invited' : 'guest'}" use:enhance>
{#if form?.success !== true}
<form method="POST" action="?/{invited ? 'invited' : 'invited'}" use:enhance>
<div class="flex-item twelve row">
<a href=".">Etusivulle</a>
<a href="/tesmi/participants">Ilmoittautuneet</a>
</div>
<div class="flex-item six">
<label>
<span>{fi ? 'Etunimi' : 'First name'}</span>
<span>{fi ? 'Etunimi' : 'First name'}*</span>
<input type="text" name="first_name" required>
</label>
</div>
<div class="flex-item six">
<label>
<span>{fi ? 'Sukunimi' : 'Last name'}</span>
<span>{fi ? 'Sukunimi' : 'Last name'}*</span>
<input type="text" name="last_name" required>
</label>
</div>
<div class="flex-item six">
<label>
<span>{fi ? 'Sähköposti' : 'Email'}</span>
<span>{fi ? 'Sähköposti' : 'Email'}*</span>
<input type="email" name="email" required>
</label>
</div>
<div class="flex-item six">
<span>{fi ? 'Asteriskin jäsen' : 'Asteriski member'}</span>
<span>{fi ? 'Asteriskin jäsen' : 'Asteriski member'}*</span>
<div class="options">
<label>
<input type="radio" name="is_asteriski_member" value="yes" required checked>
Expand All @@ -44,7 +50,7 @@
</div>
</div>
<div class="flex-item six">
<span>{fi ? 'Juoma' : 'Drink'}</span>
<span>{fi ? 'Juoma' : 'Drink'}*</span>
<div class="options">
<label>
<input type="radio" name="is_alcohol_free" value="no" required checked>
Expand All @@ -57,7 +63,7 @@
</div>
</div>
<div class="flex-item six">
<span>{fi ? 'Menu' : 'Menu'}</span>
<span>{fi ? 'Menu' : 'Menu'}*</span>
<div class="options">
<label>
<input type="radio" name="menu" value="LI" required checked>
Expand All @@ -80,7 +86,7 @@
</label>
</div>
<div class="flex-item six">
<span>{fi ? 'Osallistutko silliaamiaiselle?' : 'Are you attending to herring breakfast?'}</span>
<span>{fi ? 'Osallistutko silliaamiaiselle?' : 'Are you attending to herring breakfast?'}*</span>
<div class="options">
<label>
<input type="radio" name="is_attending_sillis" value="yes" required checked>
Expand All @@ -105,7 +111,7 @@
</label>
</div>
<div class="flex-item six">
<span>{fi ? 'Nimeni saa näkyä ilmoittautuneuiden listassa' : 'My name can be shown in the list of those who registered'}</span>
<span>{fi ? 'Nimeni saa näkyä ilmoittautuneuiden listassa' : 'My name can be shown in the list of those who registered'}*</span>
<div class="options">
<label>
<input type="radio" name="show_name" value="yes" required checked>
Expand All @@ -119,7 +125,7 @@
</div>
{#if invited}
<div class="flex-item six">
<span>{fi ? 'Esitän tervehdyksen' : 'I want to offer my greetings'}</span>
<span>{fi ? 'Esitän tervehdyksen' : 'I want to offer my greetings'}*</span>
<div class="options">
<label>
<input type="radio" name="is_greeting" value="yes" bind:group={is_greeting} required checked>
Expand All @@ -134,7 +140,7 @@
{#if is_greeting === 'yes'}
<div class="flex-item six">
<label>
<span>{fi ? 'Tervehdyksessä edustamasi taho(t)' : 'The entity you represent when greeting'}</span>
<span>{fi ? 'Tervehdyksessä edustamasi taho(t)' : 'The entity you represent when greeting'}*</span>
<input type="text" name="party_representing" required>
</label>
</div>
Expand All @@ -145,21 +151,40 @@
<input type="checkbox" name="is_consenting" required>
<span>{fi
? 'Hyväksyn, että tietojani käytetään vuosijuhlien järjestämiseen. Tiedot poistetaan vuosijuhlien jälkeen.'
: 'I consent that the data entered is used to organize the 50th anniversary event. Data is removed after the event.'}
: 'I consent that the data entered is used to organize the 50th anniversary event. Data is removed after the event.'}*
</span>
</label>
</div>
<div class="flex-item six">
<div class="flex-item six row">
{#if form?.success === false}
{#if form?.ilmo === false}
<p class="bold">{fi
?'Ilmoittautuminen ei ole auki!'
: 'Registration is not open!'}
</p>
{:else}
<p class="bold">{fi
?'Jotain meni pieleen. Yritä hetken kuluttua uudelleen.'
: 'Something went wrong. Please try again later.'}
</p>
{/if}
{/if}
<button type="submit">{fi ? 'Lähetä' : 'Send'}</button>
</div>
</form>
{:else}
<div class="flex-item six thanks">
<h3>{fi
? 'Kiitos ilmoittautumisesta!'
: 'Thanks!'}
</h3>
<a href="/tesmi/ilmo">{fi ? 'Tee toinen ilmoittautuminen' : 'Register again'}</a>
<a href="/tesmi/participants">{fi ? 'Katso ilmoittautuneet' : 'See registered'}</a>
<a href=".">{fi ? 'Etusivulle' : 'To frontpage'}</a>
</div>

{/if}
</div>
{#if $page.form?.body}
Lähetit ilmon seuraavilla tiedoilla:
{#each Object.entries($page.form?.body) as [key, data]}
<p>{key + ': ' + data}</p>
{/each}
{/if}
</div>
</section>
<style lang="scss">
Expand Down Expand Up @@ -197,6 +222,15 @@
vertical-align: bottom;
cursor: pointer;
}
&.row {
flex-direction: row;
a:first-of-type {
margin-right: auto;
}
a:last-of-type {
margin-left: auto;
}
}
}
}
Expand Down Expand Up @@ -248,4 +282,10 @@
}
}
}
.thanks {
align-items: center;
a {
margin: 5px 0;
}
}
</style>
24 changes: 0 additions & 24 deletions src/routes/+page.server.js

This file was deleted.

24 changes: 17 additions & 7 deletions src/routes/tesmi/ilmo/+page.server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { fail } from '@sveltejs/kit';

export const actions = {
invited: async ({ request }) => {
const data = await request.formData();
Expand All @@ -13,12 +15,20 @@ export const actions = {
})

const res = await response.json();

return {
success: true,
};

if (response.ok) {
return {
success: true,
};
}
if (res?.non_field_errors[0] === 'Ilmoittautuminen ei ole auki') {
return fail(400, {
success: false,
ilmo: false
});
}
return fail(400, {
success: false
});
},
guest: async (event) => {
// TODO
}
};
5 changes: 2 additions & 3 deletions src/routes/tesmi/ilmo/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script>
import Ilmo from "$lib/components/ilmo.svelte";
export let form;
</script>



<Ilmo />
<Ilmo {form}/>
34 changes: 34 additions & 0 deletions src/routes/tesmi/kutsuvieras-ilmo/+page.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { fail } from '@sveltejs/kit';

export const actions = {
invited: async ({ request }) => {
const data = await request.formData();

let body = {};
data.forEach((value, key) => body[key] = value);
body = JSON.stringify(body);

const response = await fetch('https://api.viiskyt.asteriski.fi/api/participants/', {
method: 'POST',
headers: { "Content-Type": "application/json" },
body
})

const res = await response.json();

if (response.ok) {
return {
success: true,
};
}
if (res?.non_field_errors[0] === 'Ilmoittautuminen ei ole auki') {
return fail(400, {
success: false,
ilmo: false
});
}
return fail(400, {
success: false
});
},
};
6 changes: 6 additions & 0 deletions src/routes/tesmi/kutsuvieras-ilmo/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
import Ilmo from "$lib/components/ilmo.svelte";
export let form;
</script>

<Ilmo {form} invited={true}/>
2 changes: 0 additions & 2 deletions src/routes/tesmi/participants/+page.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ export const load = async ({fetch, params }) => {

return {
participants: data,
api: api
};
}

return {
participants: [],
api: api
};
}
1 change: 0 additions & 1 deletion src/routes/tesmi/participants/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
export let data;
const participants = data.participants;
console.log(data.participants)
console.log(data.api)
</script>


Expand Down

0 comments on commit fa4fdb6

Please sign in to comment.