diff --git a/src/lib/api/getAll.ts b/src/lib/api/getAll.ts new file mode 100644 index 0000000..8c098a0 --- /dev/null +++ b/src/lib/api/getAll.ts @@ -0,0 +1,24 @@ +export async function getAllUsers(token: string) { + try { + const response = await fetch( + 'https://sucu-backend-2024-689509857491.asia-southeast1.run.app/api/v1/users', + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + } + } + ); + + if (!response.ok) { + const errorData = await response.json(); + throw new Error(`Error: ${errorData.message}`); + } + + const data = await response.json(); + return data; + } catch (error) { + console.error('Failed to fetch users:', error); + } +} diff --git a/src/lib/components/Pagination/Pagination.svelte b/src/lib/components/Pagination/Pagination.svelte index 263838e..ff87a5f 100644 --- a/src/lib/components/Pagination/Pagination.svelte +++ b/src/lib/components/Pagination/Pagination.svelte @@ -1,4 +1,5 @@ -
- - -
+{#if isAdminPage} +
+ + +
+{:else if isAuthLoginPage} +
+ +
+{:else} +
+ + +
+{/if} diff --git a/src/routes/admin/users/+page.svelte b/src/routes/admin/users/+page.svelte new file mode 100644 index 0000000..3f6af9c --- /dev/null +++ b/src/routes/admin/users/+page.svelte @@ -0,0 +1,194 @@ + + + + +
+
+

{title}

+

{subtitle}

+
+ +
+ +
+ +
+ +
+
+ +
+
เลือกทั้งหมด
+
+
+
+ + +
+ + + {#each filteredUsers as user} +
+
+ toggleSelectItem(user.id)} + class="h-4 w-4 rounded border-gray-300" + /> +
+
{user.title}
+
{user.id}
+
สร้างเมื่อ {user.date}
+
+ + {user.role} + +
+
+ + {#if activePopoverId === user.id} +
+
+ + +
+
+ {/if} +
+
+ {/each} + + +
+ user.id)} on:pageChange={handlePageChange} /> +
+
+