Edit.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <SmartModal
  3. v-if="show"
  4. dialog
  5. :title="`${$t('collection.edit')}`"
  6. @close="hideModal"
  7. >
  8. <template #body>
  9. <div class="flex flex-col px-2">
  10. <input
  11. id="selectLabelGqlEdit"
  12. v-model="name"
  13. v-focus
  14. class="input floating-input"
  15. placeholder=" "
  16. type="text"
  17. autocomplete="off"
  18. @keyup.enter="saveCollection"
  19. />
  20. <label for="selectLabelGqlEdit">
  21. {{ $t("action.label") }}
  22. </label>
  23. </div>
  24. </template>
  25. <template #footer>
  26. <span>
  27. <ButtonPrimary
  28. :label="`${$t('action.save')}`"
  29. @click.native="saveCollection"
  30. />
  31. <ButtonSecondary
  32. :label="`${$t('action.cancel')}`"
  33. @click.native="hideModal"
  34. />
  35. </span>
  36. </template>
  37. </SmartModal>
  38. </template>
  39. <script lang="ts">
  40. import { defineComponent } from "@nuxtjs/composition-api"
  41. import { editGraphqlCollection } from "~/newstore/collections"
  42. export default defineComponent({
  43. props: {
  44. show: Boolean,
  45. editingCollection: { type: Object, default: () => {} },
  46. editingCollectionIndex: { type: Number, default: null },
  47. editingCollectionName: { type: String, default: null },
  48. },
  49. data() {
  50. return {
  51. name: null as string | null,
  52. }
  53. },
  54. watch: {
  55. editingCollectionName(val) {
  56. this.name = val
  57. },
  58. },
  59. methods: {
  60. saveCollection() {
  61. if (!this.name) {
  62. this.$toast.error(`${this.$t("collection.invalid_name")}`)
  63. return
  64. }
  65. const collectionUpdated = {
  66. ...(this.editingCollection as any),
  67. name: this.name,
  68. }
  69. editGraphqlCollection(this.editingCollectionIndex, collectionUpdated)
  70. this.hideModal()
  71. },
  72. hideModal() {
  73. this.name = null
  74. this.$emit("hide-modal")
  75. },
  76. },
  77. })
  78. </script>