2024-11-14 10:20:34 +00:00
|
|
|
<script>
|
2024-11-15 04:51:49 +00:00
|
|
|
import { toast } from 'svelte-sonner';
|
2025-08-11 22:07:09 +00:00
|
|
|
import { onMount, getContext } from 'svelte';
|
2025-09-06 20:16:07 +00:00
|
|
|
import { page } from '$app/stores';
|
2024-11-15 04:51:49 +00:00
|
|
|
|
|
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
|
|
|
|
|
import { deleteGroupById, updateGroupById } from '$lib/apis/groups';
|
|
|
|
|
|
2024-11-14 10:20:34 +00:00
|
|
|
import Pencil from '$lib/components/icons/Pencil.svelte';
|
|
|
|
|
import User from '$lib/components/icons/User.svelte';
|
|
|
|
|
import UserCircleSolid from '$lib/components/icons/UserCircleSolid.svelte';
|
2025-11-21 00:12:56 +00:00
|
|
|
import EditGroupModal from './EditGroupModal.svelte';
|
2024-11-14 10:20:34 +00:00
|
|
|
|
|
|
|
|
export let group = {
|
|
|
|
|
name: 'Admins',
|
|
|
|
|
user_ids: [1, 2, 3]
|
|
|
|
|
};
|
2025-09-28 13:42:10 +00:00
|
|
|
export let defaultPermissions = {};
|
2024-11-14 10:20:34 +00:00
|
|
|
|
2024-11-15 04:51:49 +00:00
|
|
|
export let setGroups = () => {};
|
|
|
|
|
|
2024-11-14 10:20:34 +00:00
|
|
|
let showEdit = false;
|
2024-11-15 04:51:49 +00:00
|
|
|
|
|
|
|
|
const updateHandler = async (_group) => {
|
|
|
|
|
const res = await updateGroupById(localStorage.token, group.id, _group).catch((error) => {
|
2025-01-21 06:41:32 +00:00
|
|
|
toast.error(`${error}`);
|
2024-11-15 04:51:49 +00:00
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
toast.success($i18n.t('Group updated successfully'));
|
|
|
|
|
setGroups();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const deleteHandler = async () => {
|
|
|
|
|
const res = await deleteGroupById(localStorage.token, group.id).catch((error) => {
|
2025-01-21 06:41:32 +00:00
|
|
|
toast.error(`${error}`);
|
2024-11-15 04:51:49 +00:00
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
toast.success($i18n.t('Group deleted successfully'));
|
|
|
|
|
setGroups();
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-08-11 22:07:09 +00:00
|
|
|
|
|
|
|
|
onMount(() => {
|
2025-09-06 20:16:07 +00:00
|
|
|
const groupId = $page.url.searchParams.get('id');
|
2025-08-11 22:07:09 +00:00
|
|
|
if (groupId && groupId === group.id) {
|
|
|
|
|
showEdit = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-11-14 10:20:34 +00:00
|
|
|
</script>
|
|
|
|
|
|
2025-11-21 00:12:56 +00:00
|
|
|
<EditGroupModal
|
2024-11-15 04:51:49 +00:00
|
|
|
bind:show={showEdit}
|
|
|
|
|
edit
|
|
|
|
|
{group}
|
2025-09-28 13:42:10 +00:00
|
|
|
{defaultPermissions}
|
2024-11-15 04:51:49 +00:00
|
|
|
onSubmit={updateHandler}
|
|
|
|
|
onDelete={deleteHandler}
|
|
|
|
|
/>
|
2024-11-14 10:20:34 +00:00
|
|
|
|
2024-11-18 17:00:51 +00:00
|
|
|
<button
|
|
|
|
|
class="flex items-center gap-3 justify-between px-1 text-xs w-full transition"
|
|
|
|
|
on:click={() => {
|
|
|
|
|
showEdit = true;
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-07-14 17:24:31 +00:00
|
|
|
<div class="flex items-center gap-1.5 w-full font-medium flex-1">
|
2024-11-14 10:20:34 +00:00
|
|
|
<div>
|
|
|
|
|
<UserCircleSolid className="size-4" />
|
|
|
|
|
</div>
|
2025-07-14 16:08:49 +00:00
|
|
|
<div class="line-clamp-1">
|
|
|
|
|
{group.name}
|
|
|
|
|
</div>
|
2024-11-14 10:20:34 +00:00
|
|
|
</div>
|
|
|
|
|
|
2025-07-14 17:24:31 +00:00
|
|
|
<div class="flex items-center gap-1.5 w-fit font-medium text-right justify-end">
|
2025-11-17 10:09:21 +00:00
|
|
|
{group?.member_count}
|
2024-11-14 10:20:34 +00:00
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<User className="size-3.5" />
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-11-18 17:00:51 +00:00
|
|
|
<div class=" rounded-lg p-1 hover:bg-gray-100 dark:hover:bg-gray-850 transition">
|
2024-11-14 11:16:26 +00:00
|
|
|
<Pencil className="size-3.5" />
|
2024-11-18 17:00:51 +00:00
|
|
|
</div>
|
2024-11-14 10:20:34 +00:00
|
|
|
</div>
|
2024-11-18 17:00:51 +00:00
|
|
|
</button>
|