EditRequest.vue 2.0 KB

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