Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoRCD committed Feb 18, 2025
1 parent a357a17 commit 8aee2cc
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,3 @@ async function onSubmit(event: FormSubmitEvent<Schema>) {
</template>
</UModal>
</template>

<style scoped>
</style>
40 changes: 40 additions & 0 deletions app/components/customers/DeleteModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script setup lang="ts">
defineProps<{
nbCustomers: number
}>()
const open = ref(false)
async function onSubmit() {
await new Promise(resolve => setTimeout(resolve, 1000))
open.value = false
}
</script>

<template>
<UModal
v-model:open="open"
:title="`Delete ${nbCustomers} customer${nbCustomers > 1 ? 's' : ''}`"
:description="`Are you sure, this action cannot be undone.`"
>
<slot />

<template #body>
<div class="flex justify-end gap-2">
<UButton
label="Cancel"
color="neutral"
variant="subtle"
@click="open = false"
/>
<UButton
label="Delete"
color="error"
variant="solid"
loading-auto
@click="onSubmit"
/>
</div>
</template>
</UModal>
</template>
38 changes: 35 additions & 3 deletions app/pages/customers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ const UAvatar = resolveComponent('UAvatar')
const UButton = resolveComponent('UButton')
const UBadge = resolveComponent('UBadge')
const UDropdownMenu = resolveComponent('UDropdownMenu')
const UCheckbox = resolveComponent('UCheckbox')
const table = useTemplateRef('table')
const columnFilters = ref([])
const columnVisibility = ref()
const rowSelection = ref({ 1: true })
const { data, status } = await useFetch<User[]>('/api/customers', {
lazy: true
Expand Down Expand Up @@ -66,6 +67,24 @@ function getRowItems(row: Row<User>) {
}
const columns: TableColumn<User>[] = [
{
id: 'select',
header: ({ table }) =>
h(UCheckbox, {
'modelValue': table.getIsSomePageRowsSelected()
? 'indeterminate'
: table.getIsAllPageRowsSelected(),
'onUpdate:modelValue': (value: boolean | 'indeterminate') =>
table.toggleAllPageRowsSelected(!!value),
'ariaLabel': 'Select all'
}),
cell: ({ row }) =>
h(UCheckbox, {
'modelValue': row.getIsSelected(),
'onUpdate:modelValue': (value: boolean | 'indeterminate') => row.toggleSelected(!!value),
'ariaLabel': 'Select row'
})
},
{
accessorKey: 'id',
header: 'ID'
Expand Down Expand Up @@ -181,7 +200,7 @@ const pagination = ref({
<UDashboardSidebarCollapse />
</template>
<template #right>
<AddCustomer />
<CustomersAddModal />
</template>
</UDashboardNavbar>
</template>
Expand All @@ -196,6 +215,19 @@ const pagination = ref({
@update:model-value="table?.tableApi?.getColumn('email')?.setFilterValue($event)"
/>
<div class="flex items-center gap-2">
<CustomersDeleteModal :nb-customers="table?.tableApi?.getFilteredSelectedRowModel().rows.length">
<UButton
v-if="table?.tableApi?.getFilteredSelectedRowModel().rows.length"
color="error"
variant="subtle"
icon="i-lucide-trash"
>
Delete
<UKbd>
{{ table?.tableApi?.getFilteredSelectedRowModel().rows.length }}
</UKbd>
</UButton>
</CustomersDeleteModal>
<USelect
v-model="statusFilter"
:items="[
Expand Down Expand Up @@ -235,11 +267,11 @@ const pagination = ref({
</UDropdownMenu>
</div>
</div>

<UTable
ref="table"
v-model:column-filters="columnFilters"
v-model:column-visibility="columnVisibility"
v-model:row-selection="rowSelection"
v-model:pagination="pagination"
:pagination-options="{
getPaginationRowModel: getPaginationRowModel()
Expand Down

0 comments on commit 8aee2cc

Please sign in to comment.