index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <AppSection label="teams">
  3. <h4 class="text-secondaryDark">
  4. {{ $t("team.title") }}
  5. </h4>
  6. <div class="mt-1 text-secondaryLight">
  7. <SmartAnchor
  8. :label="$t('team.join_beta')"
  9. to="https://hoppscotch.io/beta"
  10. blank
  11. class="link"
  12. />
  13. </div>
  14. <div class="space-y-4 mt-4">
  15. <ButtonSecondary
  16. :label="$t('team.create_new')"
  17. outline
  18. @click.native="displayModalAdd(true)"
  19. />
  20. <p v-if="$apollo.queries.myTeams.loading">
  21. {{ $t("state.loading") }}
  22. </p>
  23. <div v-if="myTeams.length === 0" class="flex items-center">
  24. <i class="mr-4 material-icons">help_outline</i>
  25. {{ $t("empty.teams") }}
  26. </div>
  27. <div v-else class="grid gap-4 sm:grid-cols-2 md:grid-cols-3">
  28. <TeamsTeam
  29. v-for="(team, index) in myTeams"
  30. :key="`team-${index}`"
  31. :team-i-d="team.id"
  32. :team="team"
  33. @edit-team="editTeam(team, team.id)"
  34. />
  35. </div>
  36. </div>
  37. <TeamsAdd :show="showModalAdd" @hide-modal="displayModalAdd(false)" />
  38. <TeamsEdit
  39. :team="myTeams[0]"
  40. :show="showModalEdit"
  41. :editing-team="editingTeam"
  42. :editingteam-i-d="editingteamID"
  43. @hide-modal="displayModalEdit(false)"
  44. />
  45. </AppSection>
  46. </template>
  47. <script>
  48. import { defineComponent } from "@nuxtjs/composition-api"
  49. import gql from "graphql-tag"
  50. import { currentUser$ } from "~/helpers/fb/auth"
  51. import { useReadonlyStream } from "~/helpers/utils/composables"
  52. export default defineComponent({
  53. setup() {
  54. return {
  55. currentUser: useReadonlyStream(currentUser$, null),
  56. }
  57. },
  58. data() {
  59. return {
  60. showModalAdd: false,
  61. showModalEdit: false,
  62. editingTeam: {},
  63. editingteamID: "",
  64. me: {},
  65. myTeams: [],
  66. }
  67. },
  68. apollo: {
  69. me: {
  70. query: gql`
  71. query GetMe {
  72. me {
  73. uid
  74. eaInvited
  75. }
  76. }
  77. `,
  78. pollInterval: 100000,
  79. },
  80. myTeams: {
  81. query: gql`
  82. query GetMyTeams {
  83. myTeams {
  84. id
  85. name
  86. myRole
  87. ownersCount
  88. members {
  89. user {
  90. photoURL
  91. displayName
  92. email
  93. uid
  94. }
  95. role
  96. }
  97. }
  98. }
  99. `,
  100. pollInterval: 10000,
  101. },
  102. },
  103. beforeDestroy() {
  104. document.removeEventListener("keydown", this._keyListener)
  105. },
  106. methods: {
  107. displayModalAdd(shouldDisplay) {
  108. this.showModalAdd = shouldDisplay
  109. },
  110. displayModalEdit(shouldDisplay) {
  111. this.showModalEdit = shouldDisplay
  112. if (!shouldDisplay) this.resetSelectedData()
  113. },
  114. editTeam(team, teamID) {
  115. this.editingTeam = team
  116. this.editingteamID = teamID
  117. this.displayModalEdit(true)
  118. },
  119. resetSelectedData() {
  120. this.$data.editingTeam = undefined
  121. this.$data.editingteamID = undefined
  122. },
  123. },
  124. })
  125. </script>