index.vue 2.8 KB

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