Files
hoppscotch/components/teams/Add.vue
Liyas Thomas 1bc57f159c merge feat/teams-new-ui
Co-authored-by: Isha Gupta <40794215+IshaGupta18@users.noreply.github.com>
Co-authored-by: Liyas Thomas <liyascthomas@gmail.com>
Co-authored-by: Osheen Sachdev <45964755+oshhh@users.noreply.github.com>
Co-authored-by: Rohan Rajpal <rohan46000@gmail.com>
Co-authored-by: Raghav Gupta <raghav.gupta0307@gmail.com>
2021-04-26 09:37:18 +00:00

93 lines
2.1 KiB
Vue

<template>
<SmartModal v-if="show" @close="hideModal">
<div slot="header">
<ul>
<li>
<div class="row-wrapper">
<h3 class="title">{{ $t("new_team") }}</h3>
<div>
<button class="icon" @click="hideModal">
<i class="material-icons">close</i>
</button>
</div>
</div>
</li>
</ul>
</div>
<div slot="body">
<ul>
<li>
<input
type="text"
v-model="name"
:placeholder="$t('my_new_team')"
@keyup.enter="addNewTeam"
/>
</li>
</ul>
</div>
<div slot="footer">
<div class="row-wrapper">
<span></span>
<span>
<button class="icon" @click="hideModal">
{{ $t("cancel") }}
</button>
<button class="icon primary" @click="addNewTeam">
{{ $t("save") }}
</button>
</span>
</div>
</div>
</SmartModal>
</template>
<script>
import team_utils from "~/helpers/teams/utils"
export default {
props: {
show: Boolean,
},
data() {
return {
name: undefined,
}
},
methods: {
addNewTeam() {
console.log("addNewTeam start")
// We save the user input in case of an error
const name = this.name
// We clear it early to give the UI a snappy feel
this.name = ""
if (name != null && name.replace(/\s/g, "").length < 6) {
this.$toast.error(this.$t("string_length_insufficient"), {
icon: "error",
})
console.log("String length less than 6")
return
}
// Call to the graphql mutation
team_utils
.createTeam(this.$apollo, name)
.then((data) => {
// Result
this.hideModal()
console.log(data)
})
.catch((error) => {
// Error
console.error(error)
// We restore the initial user input
this.name = name
})
},
hideModal() {
this.$data.name = undefined
this.$emit("hide-modal")
},
},
}
</script>