page-delete.vue 3.34 KB
Newer Older
Nicolas Giard's avatar
Nicolas Giard committed
1
<template lang='pug'>
2 3 4 5 6 7 8
  v-dialog(
    v-model='isShown'
    max-width='550'
    persistent
    overlay-color='red darken-4'
    overlay-opacity='.7'
    )
Nick's avatar
Nick committed
9
    v-card
Nicolas Giard's avatar
Nicolas Giard committed
10
      .dialog-header.is-short.is-red
11
        v-icon.mr-2(color='white') mdi-file-document-box-remove-outline
12
        span {{$t('common:page.delete')}}
13
      v-card-text.pt-5
14
        i18next.body-1(path='common:page.deleteTitle', tag='div')
15 16
          span.red--text.text--darken-2(place='title') {{pageTitle}}
        .caption {{$t('common:page.deleteSubtitle')}}
17
        v-chip.mt-3.ml-0.mr-1(label, color='red lighten-4', small)
Nicolas Giard's avatar
Nicolas Giard committed
18
          .caption.red--text.text--darken-2 {{pageLocale.toUpperCase()}}
19
        v-chip.mt-3.mx-0(label, color='red lighten-5', small)
Nicolas Giard's avatar
Nicolas Giard committed
20 21 22
          span.red--text.text--darken-2 /{{pagePath}}
      v-card-chin
        v-spacer
23 24
        v-btn(text, @click='discard', :disabled='loading') {{$t('common:actions.cancel')}}
        v-btn.px-4(color='red darken-2', @click='deletePage', :loading='loading').white--text {{$t('common:actions.delete')}}
Nicolas Giard's avatar
Nicolas Giard committed
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
</template>

<script>
import _ from 'lodash'
import { get } from 'vuex-pathify'

import deletePageMutation from 'gql/common/common-pages-mutation-delete.gql'

export default {
  props: {
    value: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      loading: false
    }
  },
  computed: {
    isShown: {
      get() { return this.value },
      set(val) { this.$emit('input', val) }
    },
    pageTitle: get('page/title'),
    pagePath: get('page/path'),
    pageLocale: get('page/locale'),
    pageId: get('page/id')
  },
  watch: {
    isShown(newValue, oldValue) {
      if (newValue) {
        document.body.classList.add('page-deleted-pending')
      }
    }
  },
  methods: {
    discard() {
      document.body.classList.remove('page-deleted-pending')
      this.isShown = false
    },
    async deletePage() {
      this.loading = true
      this.$store.commit(`loadingStart`, 'page-delete')
      this.$nextTick(async () => {
        try {
          const resp = await this.$apollo.mutate({
            mutation: deletePageMutation,
            variables: {
              id: this.pageId
            }
          })
          if (_.get(resp, 'data.pages.delete.responseResult.succeeded', false)) {
            this.isShown = false
            _.delay(() => {
              document.body.classList.add('page-deleted')
              _.delay(() => {
                window.location.assign('/')
              }, 1200)
            }, 400)
          } else {
87
            throw new Error(_.get(resp, 'data.pages.delete.responseResult.message', this.$t('common:error.unexpected')))
Nicolas Giard's avatar
Nicolas Giard committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101
          }
        } catch (err) {
          this.$store.commit('pushGraphError', err)
        }
        this.$store.commit(`loadingStop`, 'page-delete')
        this.loading = false
      })
    }
  }
}
</script>

<style lang='scss'>
  body.page-deleted-pending {
102 103 104 105
    perspective: 50vw;
    height: 100vh;
    overflow: hidden;

Nicolas Giard's avatar
Nicolas Giard committed
106 107 108 109
    .application {
      background-color: mc('grey', '900');
    }
    .application--wrap {
110
      transform-style: preserve-3d;
Nicolas Giard's avatar
Nicolas Giard committed
111 112 113 114 115 116
      transform: translateZ(-5vw) rotateX(2deg);
      border-radius: 7px;
      overflow: hidden;
    }
  }
  body.page-deleted {
117 118
    perspective: 50vw;

Nicolas Giard's avatar
Nicolas Giard committed
119
    .application--wrap {
120
      transform-style: preserve-3d;
Nicolas Giard's avatar
Nicolas Giard committed
121 122 123 124 125
      transform: translateZ(-1000vw) rotateX(60deg);
      opacity: 0;
    }
  }
</style>