Skip to content

Commit

Permalink
fix: admin UI (#102)
Browse files Browse the repository at this point in the history
* fix: date now shows when peminjaman is late

* feat: add link to user in peminjaman table

* ui: add empty message in request table

* refactor(ui): use await in front of useAsyncData to display loading indicator

* docs: revamp readme and remove alpha testing announcement
  • Loading branch information
Klrfl authored Feb 5, 2025
1 parent 4c49a8c commit 6c160eb
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 69 deletions.
50 changes: 0 additions & 50 deletions ANNOUNCEMENT.md

This file was deleted.

2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ To add a new admin user, add a new user like usual, through the app or Supabase
dashboard, then run this query in the SQL Editor on the dashboard:

```sql
update auth.users set raw_app_meta_data = raw_app_meta_data || '{"role": "super-admin"}' where auth.users.id = 'id';
update auth.users set raw_app_meta_data = raw_app_meta_data || '{"role": "super-admin"}' where auth.users.email = 'email';
```

This will add the role 'super-admin' to the target user.
Expand Down
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Metschoo Library

Metschoo Library is now in Alpha! Read [ANNOUNCEMENT](ANNOUNCEMENT.md) to learn more
[!./public/assets/metschoo-library-new.png](Screenshot of Metschoo Library)

Source code of Metschoo Library web app, made with Vue 3 and Supabase. Please see
[DEVELOPMENT.md](DEVELOPMENT.md) before doing anything

While the app can fully work, this app is still very ugly and the admin
dashboard is still very lackluster. Please see [DEVELOPMENT](DEVELOPMENT.md#Todo)
for things that needs attention.
This repository contains the web app for managing borrowings and more at
Metschoo Library, made with Nuxt 3 and Supabase. Please see
[DEVELOPMENT.md](DEVELOPMENT.md) if you want to contribute to this project.
2 changes: 1 addition & 1 deletion lib/peminjaman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function getPeminjamanData(searchFor?: PeminjamanSearchArgs): Promi
let query = supabase
.from("peminjaman")
.select(
"*, peminjaman_detail(*, peminjaman_state(name)), pengguna(nama, kelas, jurusan), buku(*)"
"*, peminjaman_detail(*, peminjaman_state(name)), pengguna(user_id, nama, kelas, jurusan), buku(*)"
)
.order("created_at", { referencedTable: "peminjaman_detail", ascending: false })

Expand Down
6 changes: 4 additions & 2 deletions pages/admin/buku/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const categoriesOptions = computed(() => {
return [{ id: 0, kategori: "semua" }, ...(categories.value || [])]
})
const { data: searchResults } = useAsyncData(async () => await searchBukus({}))
const { data: searchResults, status } = await useAsyncData(async () => await searchBukus({}))
const searchFor = ref<BukuSearchArgs>({
judul: "",
Expand All @@ -46,7 +46,6 @@ watch(
async function handleSearchBuku() {
await navigateTo({
path: route.path,
// query: { term: searchTerm.value, category: selectedCategory.value },
query: searchFor.value,
})
}
Expand Down Expand Up @@ -82,7 +81,10 @@ async function handleSearchBuku() {
<CTA fill type="submit" label="Cari" class="px-6 ms-auto" />
</form>

<LoadingSpinner v-if="status === 'pending'" />

<DataTable
v-else
:value="searchResults"
scroll-height="60vh"
scrollable
Expand Down
2 changes: 1 addition & 1 deletion pages/admin/buku/kategori.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const editCategory = async ({ kategori, id }: Kategori) => {
}
}
const { data: categories } = useAsyncData(async () => {
const { data: categories } = await useAsyncData(async () => {
const categories = await getAllAvailableCategories()
return categories
})
Expand Down
2 changes: 1 addition & 1 deletion pages/admin/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const supabase = useSupabaseClient<Database>()
const _peminjamanQuery = supabase
.from("peminjaman")
.select(
"*, peminjaman_detail(*, peminjaman_state(name)), pengguna(nama, kelas, jurusan), buku(*)"
"*, peminjaman_detail(*, peminjaman_state(name)), pengguna(user_id, nama, kelas, jurusan), buku(*)"
)
.order("created_at", { referencedTable: "peminjaman_detail", ascending: false })
.limit(1, { referencedTable: "peminjaman_detail" })
Expand Down
23 changes: 19 additions & 4 deletions pages/admin/peminjaman.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const searchFor = ref<PeminjamanSearchArgs>({
tenggat_waktu: [null, null],
})
const { data: peminjamanData } = useAsyncData(async () => await getPeminjamanData(searchFor.value))
const { data: peminjamanData } = await useAsyncData(
async () => await getPeminjamanData(searchFor.value)
)
const isLoading = ref(false)
Expand Down Expand Up @@ -112,12 +114,21 @@ async function handleFilterPeminjaman() {
<p>Menampilkan {{ peminjamanData?.length }} peminjaman.</p>
</template>

<Column field="pengguna.nama" header="Peminjam" />
<Column field="pengguna.nama" header="Peminjam">
<template #body="{ data }">
<NuxtLink
:to="`/admin/pengguna/${data.pengguna.user_id}`"
class="hover:underline inline-block py-2"
>
{{ data.pengguna.nama }}
</NuxtLink>
</template>
</Column>
<Column field="judul" header="Judul buku" class="!p-0">
<template #body="{ data }">
<NuxtLink
:to="`/admin/buku/${data.buku.no_isbn}`"
class="hover:underline py-4 w-full inline-block max-w-72 overflow-hidden whitespace-nowrap text-ellipsis"
class="hover:underline py-2 w-full inline-block max-w-72 overflow-hidden whitespace-nowrap text-ellipsis"
>
{{ data.buku.judul }}
</NuxtLink>
Expand All @@ -134,7 +145,11 @@ async function handleFilterPeminjaman() {

<Column header="Tanggal kembali">
<template #body="{ data }: { data: PeminjamanData[number] }">
{{ getPeminjamanStateDate(data, 5) }}
{{
[5, 6].includes(data.peminjaman_detail[0].state_id)
? getPeminjamanStateDate(data, data.peminjaman_detail[0].state_id)
: "-"
}}
</template>
</Column>

Expand Down
6 changes: 4 additions & 2 deletions pages/admin/request.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ const tabs = [

<TabPanels>
<TabPanel v-for="tab in tabs" :key="tab.status" :value="tab.status">
<h2>{{ tab.localized }}</h2>

<DataTable :value="requests?.filter((d) => d.is_accepted === tab.status) || []">
<template #empty>
<p>Belum ada request dari pengguna.</p>
</template>

<Column field="created_at" header="Tanggal request" sortable>
<template #body="{ data }">
{{ formatDate(new Date(data.created_at)) }}
Expand Down
Binary file added public/assets/metschoo-library-new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6c160eb

Please sign in to comment.