EditRequest.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <SmartModal
  3. v-if="show"
  4. :title="`${$t('modal.edit_request')}`"
  5. @close="hideModal"
  6. >
  7. <template #body>
  8. <div class="flex flex-col px-2">
  9. <input
  10. id="selectLabelGqlEditReq"
  11. v-model="requestUpdateData.name"
  12. v-focus
  13. class="input floating-input"
  14. placeholder=" "
  15. type="text"
  16. autocomplete="off"
  17. @keyup.enter="saveRequest"
  18. />
  19. <label for="selectLabelGqlEditReq">
  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="saveRequest"
  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, PropType } from "@nuxtjs/composition-api"
  40. import { HoppGQLRequest } from "~/helpers/types/HoppGQLRequest"
  41. import { editGraphqlRequest } from "~/newstore/collections"
  42. export default defineComponent({
  43. props: {
  44. show: Boolean,
  45. folderPath: { type: String, default: null },
  46. request: { type: Object as PropType<HoppGQLRequest>, default: () => {} },
  47. requestIndex: { type: Number, default: null },
  48. },
  49. data() {
  50. return {
  51. requestUpdateData: {
  52. name: null as any | null,
  53. },
  54. }
  55. },
  56. methods: {
  57. saveRequest() {
  58. if (!this.requestUpdateData.name) {
  59. this.$toast.error(`${this.$t("collection.invalid_name")}`, {
  60. icon: "error_outline",
  61. })
  62. return
  63. }
  64. const requestUpdated = {
  65. ...this.$props.request,
  66. name: this.$data.requestUpdateData.name || this.$props.request.name,
  67. }
  68. editGraphqlRequest(this.folderPath, this.requestIndex, requestUpdated)
  69. this.hideModal()
  70. },
  71. hideModal() {
  72. this.requestUpdateData = { name: null }
  73. this.$emit("hide-modal")
  74. },
  75. },
  76. })
  77. </script>