SiteDeleteDialog.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template lang="pug">
  2. q-dialog(ref='dialogRef', @hide='onDialogHide')
  3. q-card(style='min-width: 350px; max-width: 450px;')
  4. q-card-section.card-header
  5. q-icon(name='img:/_assets/icons/fluent-delete-bin.svg', left, size='sm')
  6. span {{t(`admin.sites.delete`)}}
  7. q-card-section
  8. .text-body2
  9. i18n-t(keypath='admin.sites.deleteConfirm')
  10. template(v-slot:siteTitle)
  11. strong {{props.site.title}}
  12. .text-body2.q-mt-md
  13. strong.text-negative {{t(`admin.sites.deleteConfirmWarn`)}}
  14. q-card-actions.card-actions
  15. q-space
  16. q-btn.acrylic-btn(
  17. flat
  18. :label='t(`common.actions.cancel`)'
  19. color='grey'
  20. padding='xs md'
  21. @click='onDialogCancel'
  22. )
  23. q-btn(
  24. unelevated
  25. :label='t(`common.actions.delete`)'
  26. color='negative'
  27. padding='xs md'
  28. @click='confirm'
  29. :loading='state.isLoading'
  30. )
  31. </template>
  32. <script setup>
  33. import gql from 'graphql-tag'
  34. import { useI18n } from 'vue-i18n'
  35. import { useDialogPluginComponent, useQuasar } from 'quasar'
  36. import { reactive } from 'vue'
  37. import { useAdminStore } from '../stores/admin'
  38. // PROPS
  39. const props = defineProps({
  40. site: {
  41. type: Object,
  42. required: true
  43. }
  44. })
  45. // EMITS
  46. defineEmits([
  47. ...useDialogPluginComponent.emits
  48. ])
  49. // QUASAR
  50. const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } = useDialogPluginComponent()
  51. const $q = useQuasar()
  52. // STORES
  53. const adminStore = useAdminStore()
  54. // I18N
  55. const { t } = useI18n()
  56. // DATA
  57. const state = reactive({
  58. isLoading: false
  59. })
  60. // METHODS
  61. async function confirm () {
  62. state.isLoading = true
  63. try {
  64. const resp = await APOLLO_CLIENT.mutate({
  65. mutation: gql`
  66. mutation deleteSite ($id: UUID!) {
  67. deleteSite(id: $id) {
  68. operation {
  69. succeeded
  70. message
  71. }
  72. }
  73. }
  74. `,
  75. variables: {
  76. id: props.site.id
  77. }
  78. })
  79. if (resp?.data?.deleteSite?.operation?.succeeded) {
  80. $q.notify({
  81. type: 'positive',
  82. message: t('admin.sites.deleteSuccess')
  83. })
  84. adminStore.$patch({
  85. sites: adminStore.sites.filter(s => s.id !== props.site.id)
  86. })
  87. onDialogOK()
  88. } else {
  89. throw new Error(resp?.data?.deleteSite?.operation?.message || 'An unexpected error occured.')
  90. }
  91. } catch (err) {
  92. $q.notify({
  93. type: 'negative',
  94. message: err.message
  95. })
  96. }
  97. state.isLoading = false
  98. }
  99. </script>