switch to use:enchance for all forms, split overview into its own file
This commit is contained in:
parent
365c43c501
commit
f47d113a01
5 changed files with 367 additions and 81 deletions
|
|
@ -8,7 +8,6 @@
|
|||
import type { SessionValidationResult } from '$lib/server/auth';
|
||||
import {
|
||||
GroupID,
|
||||
ServerID,
|
||||
type OverviewData,
|
||||
type OverviewGroup,
|
||||
type OverviewServer,
|
||||
|
|
@ -16,6 +15,11 @@
|
|||
} from '$lib';
|
||||
import Button from './ui/button/button.svelte';
|
||||
import Input from './ui/input/input.svelte';
|
||||
import { enhance } from '$app/forms';
|
||||
import { invalidateAll } from '$app/navigation';
|
||||
import { fill_overview_data } from '$lib/state.svelte';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import type { PageServerLoad } from '../../routes/app/$types';
|
||||
|
||||
// Props for the member sidebar.
|
||||
let {
|
||||
|
|
@ -23,12 +27,14 @@
|
|||
members = $bindable<OverviewUser[]>([]),
|
||||
user,
|
||||
data,
|
||||
psd,
|
||||
currentEntity,
|
||||
currentEntityId = $bindable<string | null>(null)
|
||||
}: {
|
||||
open: boolean;
|
||||
members: OverviewUser[];
|
||||
data: OverviewData;
|
||||
psd: PageServerLoad;
|
||||
user: SessionValidationResult['user'];
|
||||
currentEntity: OverviewGroup | OverviewServer;
|
||||
currentEntityId: string | null;
|
||||
|
|
@ -62,12 +68,31 @@
|
|||
<Tabs.Trigger value="admins">Admin Settings</Tabs.Trigger>
|
||||
{/if}
|
||||
</Tabs.List>
|
||||
{#if ServerID.is(currentEntityId)}
|
||||
<h1>not done yet for later</h1>
|
||||
{:else if GroupID.is(currentEntityId)}
|
||||
{#if GroupID.is(currentEntityId)}
|
||||
{#if user.id == currentEntity.ownerId}
|
||||
<Tabs.Content value="admins">
|
||||
<form method="POST" action="?/configureGroup" class="space-y-4 p-2">
|
||||
<form
|
||||
method="POST"
|
||||
action="?/configureGroup"
|
||||
class="space-y-4 p-2"
|
||||
use:enhance={() => {
|
||||
return async ({ result }) => {
|
||||
if (result.type == 'success') {
|
||||
toast.success('Configured group succesfully');
|
||||
}
|
||||
|
||||
if (result.type == 'error' || result.type == 'failure') {
|
||||
toast.error(
|
||||
'Could not configure group successfully: ' +
|
||||
(result.error || result.data?.error)
|
||||
);
|
||||
}
|
||||
|
||||
await invalidateAll();
|
||||
await fill_overview_data(psd);
|
||||
};
|
||||
}}
|
||||
>
|
||||
<input type="hidden" name="groupId" value={currentEntityId} />
|
||||
|
||||
<div class="flex items-center justify-between">
|
||||
|
|
@ -111,6 +136,23 @@
|
|||
method="POST"
|
||||
action="?/deleteGroup"
|
||||
class="border-t border-red-500/30 pt-4"
|
||||
use:enhance={() => {
|
||||
return async ({ result }) => {
|
||||
if (result.type == 'success') {
|
||||
toast.success('Group deleted successfully');
|
||||
}
|
||||
|
||||
if (result.type == 'error' || result.type == 'failure') {
|
||||
toast.error(
|
||||
'Could not delete group successfully: ' +
|
||||
(result.error || result.data?.error)
|
||||
);
|
||||
}
|
||||
|
||||
await invalidateAll();
|
||||
await fill_overview_data(psd);
|
||||
};
|
||||
}}
|
||||
>
|
||||
<input type="hidden" name="groupId" value={currentEntityId} />
|
||||
|
||||
|
|
@ -129,7 +171,28 @@
|
|||
)}
|
||||
|
||||
{#if addableMembers.length !== 0}
|
||||
<form method="POST" action="?/addMembers" class="space-y-4">
|
||||
<form
|
||||
method="POST"
|
||||
action="?/addMembers"
|
||||
class="space-y-4"
|
||||
use:enhance={() => {
|
||||
return async ({ result }) => {
|
||||
if (result.type == 'success') {
|
||||
toast.success('Users added successfully');
|
||||
}
|
||||
|
||||
if (result.type == 'error' || result.type == 'failure') {
|
||||
toast.error(
|
||||
'Could not add users successfully: ' +
|
||||
(result.error || result.data?.error)
|
||||
);
|
||||
}
|
||||
|
||||
await invalidateAll();
|
||||
await fill_overview_data(psd);
|
||||
};
|
||||
}}
|
||||
>
|
||||
<input type="hidden" name="groupId" value={currentEntityId} />
|
||||
|
||||
<h1>Add members</h1>
|
||||
|
|
@ -148,7 +211,28 @@
|
|||
{/if}
|
||||
|
||||
{#if (currentEntity as OverviewGroup).permissions.changeTitle || user.id == currentEntity.ownerId}
|
||||
<form method="POST" action="?/changeTitle" class="space-y-4">
|
||||
<form
|
||||
method="POST"
|
||||
action="?/changeTitle"
|
||||
class="space-y-4"
|
||||
use:enhance={() => {
|
||||
return async ({ result }) => {
|
||||
if (result.type == 'success') {
|
||||
toast.success('Title changed successfully');
|
||||
}
|
||||
|
||||
if (result.type == 'error' || result.type == 'failure') {
|
||||
toast.error(
|
||||
'Could not change title successfully: ' +
|
||||
(result.error || result.data?.error)
|
||||
);
|
||||
}
|
||||
|
||||
await invalidateAll();
|
||||
await fill_overview_data(psd);
|
||||
};
|
||||
}}
|
||||
>
|
||||
<input type="hidden" name="groupId" value={currentEntityId} />
|
||||
|
||||
<h1>Change title</h1>
|
||||
|
|
@ -161,7 +245,28 @@
|
|||
{/if}
|
||||
|
||||
{#if (currentEntity as OverviewGroup).permissions.removeMembers || user.id == currentEntity.ownerId}
|
||||
<form method="POST" action="?/removeMembers" class="space-y-4">
|
||||
<form
|
||||
method="POST"
|
||||
action="?/removeMembers"
|
||||
class="space-y-4"
|
||||
use:enhance={() => {
|
||||
return async ({ result }) => {
|
||||
if (result.type == 'success') {
|
||||
toast.success('Users removed successfully');
|
||||
}
|
||||
|
||||
if (result.type == 'error' || result.type == 'failure') {
|
||||
toast.error(
|
||||
'Could not remove users successfully: ' +
|
||||
(result.error || result.data?.error)
|
||||
);
|
||||
}
|
||||
|
||||
await invalidateAll();
|
||||
await fill_overview_data(psd);
|
||||
};
|
||||
}}
|
||||
>
|
||||
<input type="hidden" name="groupId" value={currentEntityId} />
|
||||
|
||||
<h1>Remove members</h1>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue