Advertisement
akbarism

dialog delete

Jun 10th, 2023
575
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.71 KB | None | 0 0
  1. <template>
  2.   <transition
  3.    enter-from-class="opacity-0"
  4.    leave-to-class="opacity-0 ease-in-out"
  5.    enter-active-class="transition ease-in-out duration-300"
  6.    leave-active-class="transition ease-in-out duration-300"
  7.  >
  8.     <div
  9.      class="fixed w-screen h-screen inset-0 bg-gray-600 bg-opacity-50 top-0 left-0 z-20 flex justify-center items-center"
  10.      role="dialog"
  11.      v-if="modelValue"
  12.      @click.self="$emit('update:modelValue', false)"
  13.    >
  14.       <Paper
  15.        style="width: 330px; max-height: 80vh"
  16.        class="rounded-lg flex flex-col p-6 relative"
  17.      >
  18.         <p class="text-xl text-center font-bold text-slate-700 mb-3">
  19.           Are You sure?
  20.         </p>
  21.         <p class="text-center text-sm mb-6">
  22.           Do you really want to delete this record? This process cannot be
  23.           undone.
  24.         </p>
  25.         <div class="grid grid-cols-2 gap-2">
  26.           <button
  27.            class="py-3 w-full font-medium text-slate-900 border-solid border-2 border-gray-200 hover:bg-slate-500/20 active:bg-slate-500/50 rounded-lg outline-none"
  28.            @click="$emit('update:modelValue', false)"
  29.          >
  30.             Cancel
  31.           </button>
  32.  
  33.           <button
  34.            class="py-3 w-full font-medium text-white border-solid border-2 border-red-500 bg-red-500 hover:bg-red-600 active:bg-red-700 rounded-lg outline-none"
  35.            @click="deleteData"
  36.          >
  37.             Delete
  38.           </button>
  39.         </div>
  40.         <div
  41.          v-if="vm.loading"
  42.          class="overlayed absolute w-full h-full bg-white top-0 left-0 rounded-lg flex justify-center items-center"
  43.        >
  44.           <mdicon name="circle-medium" class="animate-ping" />
  45.           <p class="text-base text-center font-bold text-slate-700 ml-1">
  46.             Loading...
  47.           </p>
  48.         </div>
  49.       </Paper>
  50.     </div>
  51.   </transition>
  52. </template>
  53.  
  54. <script setup>
  55. import { reactive } from "vue";
  56. import { mainStore } from "../../store/store";
  57. const store = mainStore();
  58. const props = defineProps({
  59.   modelValue: Boolean,
  60.   key: { type: String, default: "id" },
  61.   pocket: null,
  62. });
  63. const emit = defineEmits(["modelValue", "refetch"]);
  64. const vm = reactive({
  65.   loading: false,
  66. });
  67.  
  68. const deleteData = () => {
  69.   vm.loading = true;
  70.   store
  71.     .postApi({
  72.       path: props.pocket.path,
  73.       body: {
  74.         [props.pocket.key ?? "id"]: props.pocket[props.pocket.key ?? "id"],
  75.       },
  76.     })
  77.     .then((res) => {
  78.       store.toaster(res.message, "success");
  79.       vm.loading = false;
  80.       emit("update:modelValue", false);
  81.       emit("refetch");
  82.     })
  83.     .catch((err) => {
  84.       vm.loading = false;
  85.       console.log(err);
  86.     });
  87. };
  88. </script>
  89.  
  90. <style></style>
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement