GroupInvite.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="group-invite-component">
  3. <div class="container">
  4. <div class="row justify-content-center mt-5">
  5. <div class="col-12 col-md-7">
  6. <div class="card shadow-none border" style="min-height: 300px;">
  7. <div class="card-body d-flex justify-content-center align-items-center">
  8. <transition-group name="fade">
  9. <div v-if="tab === 'initial'" key="initial">
  10. <p class="text-center mb-1"><b-spinner variant="lighter" /></p>
  11. <p class="text-center small text-muted mb-0">{{ loadingStatus }}</p>
  12. </div>
  13. <div v-else-if="tab === 'loading'" key="loading">
  14. <p class="text-center mb-1"><b-spinner variant="lighter" /></p>
  15. </div>
  16. <div v-else-if="tab === 'login'" key="login">
  17. <p class="text-center mb-0">Please <a href="/login">login</a> to continue</p>
  18. </div>
  19. <div v-else-if="tab === 'form'" key="form">
  20. <div class="d-flex justify-content-center align-items-center flex-column">
  21. <p class="text-center h4 font-weight-bold"><a href="#">@dansup</a> invited you to join</p>
  22. <div class="card my-3 shadow-none border" style="width: 300px;">
  23. <img v-if="group.metadata && group.metadata.hasOwnProperty('header')" :src="group.metadata.header.url" class="card-img-top" style="width: 100%; height: 100px;object-fit: cover;">
  24. <div v-else class="card-img-top" style="width: 100px; height: 100px;padding: 5px;">
  25. <div class="bg-primary d-flex align-items-center justify-content-center" style="width: 100%; height:100%;">
  26. <i class="fal fa-users text-white fa-lg"></i>
  27. </div>
  28. </div>
  29. <div class="card-body">
  30. <p class="h5 font-weight-bold mb-1 text-dark">
  31. {{ group.name || 'Untitled Group' }}
  32. </p>
  33. <transition name="fade">
  34. <p v-if="showMore" class="text-muted small mb-1">
  35. {{ group.description }}
  36. </p>
  37. </transition>
  38. <p class="mb-1">
  39. <span class="text-muted mr-2">
  40. <i class="far fa-users fa-sm text-lighter mr-1"></i>
  41. <span class="small font-weight-bold">{{ prettyCount(group.member_count) }} Members</span>
  42. </span>
  43. <span v-if="!group.local" class="remote-label ml-2">
  44. <i class="fal fa-globe"></i> Remote
  45. </span>
  46. </p>
  47. <transition name="fade">
  48. <div v-if="showMore">
  49. <p class="text-muted small mb-1">
  50. <i class="far fa-tag fa-sm text-lighter mr-2"></i>
  51. <span class="font-weight-bold">Category: {{ group.category.name }}</span>
  52. </p>
  53. <p class="text-muted small mb-1">
  54. <i class="far fa-clock fa-sm text-lighter mr-2"></i>
  55. <span class="font-weight-bold">Created {{ timeago(group.created_at) }} ago</span>
  56. </p>
  57. </div>
  58. </transition>
  59. </div>
  60. </div>
  61. </div>
  62. <div class="d-flex justify-content-between">
  63. <button class="btn btn-light border-lighter font-weight-bold btn-sm" @click="showMoreInfo">
  64. {{ showMore ? 'Less' :'More' }} info
  65. </button>
  66. <div>
  67. <button class="btn btn-light font-weight-bold btn-sm" @click="declineInvite">Decline</button>
  68. <button class="btn btn-primary font-weight-bold btn-sm" @click="acceptInvite">Accept</button>
  69. </div>
  70. </div>
  71. <!-- <p class="text-center h4 font-weight-bold">by <a href="#" class="font-weight-bold">@dansup</a></p> -->
  72. </div>
  73. <div v-else-if="tab === 'existingmember'" key="existingmember">
  74. <p class="text-center mb-0">You already are a member of this group</p>
  75. <p class="text-center mb-0">
  76. <a :href="group.url" class="font-weight-bold">View Group</a>
  77. </p>
  78. </div>
  79. <div v-else-if="tab === 'notinvited'" key="notinvited">
  80. <p class="text-center mb-0">We cannot find an active invitation for your account.</p>
  81. </div>
  82. <div v-else-if="tab === 'error'" key="error">
  83. <p class="text-center mb-0">An unknown error occured. Please try again later.</p>
  84. </div>
  85. <div v-else key="unknown">
  86. <p class="text-center mb-0">An unknown error occured. Please try again later.</p>
  87. </div>
  88. </transition-group>
  89. </div>
  90. </div>
  91. <!-- <h4>You've been invited to {{ group.name }}</h4> -->
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. </template>
  97. <script type="text/javascript">
  98. export default {
  99. props: [
  100. 'id'
  101. ],
  102. data() {
  103. return {
  104. loadingStatus: 'Determining invite eligibility',
  105. tab: 'initial',
  106. profile: {},
  107. group: {},
  108. showMore: false
  109. }
  110. },
  111. mounted() {
  112. axios.get('/api/pixelfed/v1/accounts/verify_credentials')
  113. .then(res => {
  114. this.profile = res.data;
  115. this.fetchGroup();
  116. }).catch(err => {
  117. if(err.response.status === 403) {
  118. this.tab = 'login';
  119. return;
  120. } else {
  121. this.tab = 'error';
  122. return
  123. }
  124. });
  125. },
  126. methods: {
  127. fetchGroup() {
  128. axios.get(`/api/v0/groups/${this.id}`)
  129. .then(res => {
  130. this.group = res.data;
  131. this.loadingStatus = 'Checking group invitations';
  132. this.checkForInvitation();
  133. }).catch(err => {
  134. this.tab = 'error';
  135. });
  136. },
  137. checkForInvitation() {
  138. axios.post(`/api/v0/groups/${this.group.id}/invite/check`)
  139. .then(res => {
  140. this.tab = res.data.can_join == true ? 'form' : 'notinvited';
  141. }).catch(err => {
  142. if(err.response.status === 422 && err.response.data.error === 'Already a member') {
  143. this.tab = 'existingmember';
  144. } else {
  145. this.tab = 'error';
  146. }
  147. })
  148. },
  149. prettyCount(val) {
  150. return App.util.format.count(val);
  151. },
  152. timeago(ts) {
  153. return App.util.format.timeAgo(ts);
  154. },
  155. showMoreInfo() {
  156. event.currentTarget.blur();
  157. this.showMore = !this.showMore;
  158. },
  159. acceptInvite() {
  160. event.currentTarget.blur();
  161. this.tab = 'loading';
  162. axios.post(`/api/v0/groups/${this.group.id}/invite/accept`)
  163. .then(res => {
  164. setTimeout(() => {
  165. location.href = res.data.next_url;
  166. }, 2000);
  167. }).catch(err => {
  168. this.tab = 'error';
  169. });
  170. },
  171. declineInvite() {
  172. event.currentTarget.blur();
  173. this.tab = 'loading';
  174. axios.post(`/api/v0/groups/${this.group.id}/invite/decline`)
  175. .then(res => {
  176. location.href = res.data.next_url;
  177. }).catch(err => {
  178. this.tab = 'error';
  179. });
  180. },
  181. }
  182. }
  183. </script>
  184. <style lang="scss">
  185. .group-invite-component {
  186. .btn-light {
  187. border-color: #E5E7EB;
  188. }
  189. }
  190. </style>