Edit.vue 1.8 KB

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