<script>
	import { writable } from 'svelte/store';
	import { createInvite } from '$lib/apiServer';
	import Invite from '$lib/components/Invite.svelte';

	let invites = writable([]);
	$: $invites, console.log('invites', $invites);

	async function onSubmit() {
		let response = await createInvite();
		if (response.status == 200) {
			invites.update((val) => [...val, response.data]);
		}
	}
</script>

<ul>
	{#each $invites as invite}
		<li><Invite id={invite.id} /></li>
	{/each}
</ul>
<form on:submit|preventDefault={onSubmit}>
	<button class="btn variant-filled" type="submit"> Create Invitation </button>
</form>
