initial implementation of adding clients
This commit is contained in:
26
src/routes/clients/+page.server.ts
Normal file
26
src/routes/clients/+page.server.ts
Normal 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;
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user