summaryrefslogtreecommitdiff
path: root/ui/lib/components/Invite.svelte
blob: f4babad7996d8c46379b595fd1c205c95a3442b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<script>
	import { base } from '$app/paths';
	import { createInvite } from '$lib/apiServer';
	import { clipboard } from '@skeletonlabs/skeleton';

	let invite = null;
	$: inviteUrl = invite ? new URL(`/invite/${invite.id}`, document.location) : null;
	$: inviteUrl, console.log("invite url", inviteUrl);

	async function onSubmit() {
		let response = await createInvite();
		if (response.status == 200) {
			invite = response.data;
		}
		console.log("base url", base);
	}

	async function onReset() {
		invite = null;
	}
</script>

<form
	on:submit|preventDefault={onSubmit}
	on:reset|preventDefault={onReset}>
	{#if inviteUrl}
	<button
		class="border-slate-500 border-solid border-2 font-bold p-1 rounded"
		use:clipboard={inviteUrl}
		type="reset">
		Copy Invite
	</button>
	{:else}
	<button
		class="border-slate-500 border-solid border-2 font-bold p-1 rounded"
		type="submit">
		Invite
	</button>
	{/if}
</form>