index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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="!myTeamsLoading">
  21. {{ $t("state.loading") }}
  22. </p>
  23. <div
  24. v-if="!myTeamsLoading && myTeams.myTeams.length === 0"
  25. class="flex items-center"
  26. >
  27. <i class="mr-4 material-icons">help_outline</i>
  28. {{ $t("empty.teams") }}
  29. </div>
  30. <div
  31. v-else-if="!myTeamsLoading && !isApolloError(myTeams)"
  32. class="grid gap-4 sm:grid-cols-2 md:grid-cols-3"
  33. >
  34. <TeamsTeam
  35. v-for="(team, index) in myTeams.myTeams"
  36. :key="`team-${String(index)}`"
  37. :team-i-d="team.id"
  38. :team="team"
  39. @edit-team="editTeam(team, team.id)"
  40. />
  41. </div>
  42. </div>
  43. <TeamsAdd :show="showModalAdd" @hide-modal="displayModalAdd(false)" />
  44. <!-- ¯\_(ツ)_/¯ -->
  45. <TeamsEdit
  46. v-if="!myTeamsLoading && myTeams.myTeams.length > 0"
  47. :team="myTeams.myTeams[0]"
  48. :show="showModalEdit"
  49. :editing-team="editingTeam"
  50. :editingteam-i-d="editingTeamID"
  51. @hide-modal="displayModalEdit(false)"
  52. />
  53. </AppSection>
  54. </template>
  55. <script setup lang="ts">
  56. import { gql } from "@apollo/client/core"
  57. import { ref } from "@nuxtjs/composition-api"
  58. import { useGQLQuery, isApolloError } from "~/helpers/apollo"
  59. const showModalAdd = ref(false)
  60. const showModalEdit = ref(false)
  61. const editingTeam = ref<any>({}) // TODO: Check this out
  62. const editingTeamID = ref<any>("")
  63. const { loading: myTeamsLoading, data: myTeams } = useGQLQuery({
  64. query: gql`
  65. query GetMyTeams {
  66. myTeams {
  67. id
  68. name
  69. myRole
  70. ownersCount
  71. members {
  72. user {
  73. photoURL
  74. displayName
  75. email
  76. uid
  77. }
  78. role
  79. }
  80. }
  81. }
  82. `,
  83. pollInterval: 10000,
  84. })
  85. const displayModalAdd = (shouldDisplay: boolean) => {
  86. showModalAdd.value = shouldDisplay
  87. }
  88. const displayModalEdit = (shouldDisplay: boolean) => {
  89. showModalEdit.value = shouldDisplay
  90. if (!shouldDisplay) resetSelectedData()
  91. }
  92. const editTeam = (team: any, teamID: any) => {
  93. editingTeam.value = team
  94. editingTeamID.value = teamID
  95. displayModalEdit(true)
  96. }
  97. const resetSelectedData = () => {
  98. editingTeam.value = undefined
  99. editingTeamID.value = undefined
  100. }
  101. </script>