initial implementation of adding clients

This commit is contained in:
2024-12-23 00:05:00 -08:00
parent 5e3772d39b
commit 2b56cba770
8 changed files with 273 additions and 173 deletions

View File

@@ -0,0 +1,26 @@
import type { Actions } from './$types';
import { createClient } from '$lib/server/clients';
import { error } from '@sveltejs/kit';
export const actions = {
create: async (event) => {
if (!event.locals.user) return error(401, 'Unauthorized');
const name = 'New Client Name';
const res = await createClient({
name,
user: event.locals.user,
});
switch (res._tag) {
case 'ok': {
return {
status: 201,
};
}
case 'err': {
const [status, message] = res.error;
return error(status, message);
}
}
},
} satisfies Actions;

View File

@@ -1,7 +1,9 @@
<script lang="ts">
import * as Table from '$lib/components/ui/table';
import { Badge } from '$lib/components/ui/badge';
import { Button } from '$lib/components/ui/button';
import type { PageData } from './$types';
import { LucidePlus } from 'lucide-svelte';
const { data }: { data: PageData } = $props();
</script>
@@ -32,3 +34,11 @@
{/each}
</Table.Body>
</Table.Root>
<!--Floating action button for adding a new client-->
<form class="self-end mt-auto pt-4" method="post" action="?/create">
<Button type="submit">
<LucidePlus />
Add Client
</Button>
</form>