Edit.vue 1.7 KB

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