Skip to content

Commit

Permalink
feat(nuxt-admin): add modal delete confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
gravitano committed Feb 25, 2023
1 parent f338d87 commit 77a6669
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
30 changes: 27 additions & 3 deletions starter/nuxt-admin/components/Dashboard/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import '@gits-id/pagination/src/VPagination.scss';
import '@gits-id/table/src/VDataTable.scss';
import '@gits-id/table/src/VDataTablePagination.scss';
import type {VDataTableHeader} from '@gits-id/ui';
import type {VDataTableHeader, VDataTableItem} from '@gits-id/ui';
const headers = ref<VDataTableHeader[]>([
{
Expand Down Expand Up @@ -271,6 +271,22 @@ const statusColor: Record<string, string> = {
Customer: 'success',
Churned: 'default',
};
const selectedItem = ref();
const dialogDelete = ref(false);
const deleteItem = (item: VDataTableItem) => {
selectedItem.value = item;
dialogDelete.value = true;
};
const onItemDeleted = () => {
const index = items.value.findIndex(
(item) => item.company.name === selectedItem.value.company.name,
);
items.value.splice(index, 1);
dialogDelete.value = false;
};
</script>

<template>
Expand Down Expand Up @@ -353,9 +369,17 @@ const statusColor: Record<string, string> = {
{{ item.about.description }}
</div>
</template>
<template #item.action>
<template #item.action="{item}">
<VBtn text fab size="sm" prefix-icon="ic:round-edit"></VBtn>
<VBtn text fab size="sm" prefix-icon="ic:round-delete"></VBtn>
<VBtn
text
fab
size="sm"
prefix-icon="ic:round-delete"
@click="deleteItem(item)"
></VBtn>
</template>
</VDataTable>

<ModalDelete v-model="dialogDelete" @yes="onItemDeleted" />
</template>
48 changes: 48 additions & 0 deletions starter/nuxt-admin/components/Modal/ModalDelete.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<script setup lang="ts">
import {useVModel} from '@vueuse/core';
interface Props {
modelValue?: boolean;
message?: string;
yesText?: string;
noText?: string;
title?: string;
}
const props = withDefaults(defineProps<Props>(), {
modelValue: false,
message: 'Are you sure want to delete this item?',
yesText: 'Yes, delete it!',
noText: 'Cancel',
title: 'Delete Confirmation',
});
const emit =
defineEmits<{
(e: 'update:modelValue', value: boolean): void;
(e: 'yes'): void;
(e: 'no'): void;
}>();
const isOpen = useVModel(props, 'modelValue', emit);
const yes = () => {
emit('yes');
isOpen.value = false;
};
const no = () => {
emit('no');
isOpen.value = false;
};
</script>

<template>
<VModal v-model="isOpen" :title="title" hide-x-button>
{{ message }}
<template #footer>
<VBtn @click="no"> {{ noText }}</VBtn>
<VBtn color="error" @click="yes"> {{ yesText }}</VBtn>
</template>
</VModal>
</template>

1 comment on commit 77a6669

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for gits-nuxt-admin ready!

✅ Preview
https://gits-nuxt-admin-hupoxf74a-gravitano.vercel.app

Built with commit 77a6669.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.