aboutsummaryrefslogtreecommitdiff
path: root/front-end/src/components/global/ConfirmPrompt.vue
blob: 24d3b9cf7dfc0242e98491fe0f1feb23508f31f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<script setup lang="ts">
import { defaultTo } from 'lodash-es'
import { ref } from 'vue'
import { onClickOutside } from '@vueuse/core'
import { useConfirm } from '@vnuge/vnlib.browser'
import Dialog from './Dialog.vue'

interface MessageType{
  title: string,
  text: string
}

//Use component side of confirm
const { isRevealed, confirm, cancel, onReveal } = useConfirm()

const dialog = ref(null)
const message = ref<MessageType | undefined>()

//Cancel prompt when user clicks outside of dialog, only when its open
onClickOutside(dialog, () => isRevealed.value ? cancel() : null)

//Set message on reveal
onReveal(m => message.value = defaultTo(m, {}));

</script>
<template>
  <!-- Main modal -->
  <Dialog title="Confirm?" :open="isRevealed" @cancel="cancel">
      <template #body>
        <div class="p-4 space-y-4 md:p-5">
            <p class="text-base leading-relaxed text-gray-500 dark:text-gray-400">
              {{ message?.text }}
            </p>
        </div>
        <!-- Modal footer -->
        <div class="flex items-center justify-end p-4 border-t border-gray-200 rounded-b md:p-5 dark:border-gray-600">
            <button 
            @click="confirm()" 
            type="button"
            class="btn blue">
              Confirm
            </button>
          
            <button 
              @click="cancel()" 
              type="button" 
              class="btn light">
              Cancel
            </button>
        </div>
      </template>
  </Dialog>

</template>