* Teams

* Fix errors on versions with no files
This commit is contained in:
Geometrically
2020-12-28 10:50:59 -07:00
committed by GitHub
parent 0b160a6741
commit 12840f2428
14 changed files with 787 additions and 82 deletions

View File

@@ -42,8 +42,8 @@
>
</p>
<button @click="logout">Continue</button>
</section></DashboardPage
>
</section>
</DashboardPage>
</template>
<script>
@@ -54,8 +54,8 @@ export default {
},
methods: {
async logout() {
await this.$auth. setToken('local', false)
await this.$router.go(
await this.$auth.setToken('local', false)
await this.$router.replace(
'https://api.modrinth.com/api/v1/auth/init?url=https://modrinth.com/'
)
},

View File

@@ -0,0 +1,146 @@
<template>
<DashboardPage>
<div class="section-header columns">
<h3 class="column-grow-1">My invites</h3>
</div>
<div v-for="invite in invites" :key="invite.team_id" class="invite columns">
<div class="text">
<p>
Invite to join <strong>{{ invite.username }}'s</strong> team.
</p>
</div>
<div class="actions">
<button @click="declineInvite(invite.team_id)">Decline</button>
<button @click="acceptInvite(invite.team_id)">Accept</button>
</div>
</div>
</DashboardPage>
</template>
<script>
import axios from 'axios'
import DashboardPage from '@/components/DashboardPage'
export default {
components: {
DashboardPage,
},
async asyncData(data) {
const config = {
headers: {
Authorization: data.$auth.getToken('local')
? data.$auth.getToken('local')
: '',
},
}
const teams = (
await axios.get(
`https://api.modrinth.com/api/v1/user/${data.$auth.user.id}/teams`,
config
)
).data.filter((it) => !it.accepted)
const members = (
await Promise.all(
teams.map((it) =>
axios.get(
`https://api.modrinth.com/api/v1/team/${it.team_id}/members`,
config
)
)
)
).map((it) => it.data)
const invites = []
for (let i = 0; i++; i < members.length) {
const owner = members[i].find((it) => it.role === 'Owner')
const ownerData = (
await axios.get(
`https://api.modrinth.com/api/v1/user/${owner.id}`,
config
)
).data
invites.push({
team_id: owner.team_id,
username: ownerData.username,
})
}
return {
invites,
}
},
methods: {
async acceptInvite(teamId) {
const config = {
headers: {
Authorization: this.$auth.getToken('local'),
},
}
this.$nuxt.$loading.start()
try {
await axios.post(
`https://api.modrinth.com/api/v1/team/${teamId}/join`,
config
)
await this.$router.go(null)
} catch (err) {
this.$notify({
group: 'main',
title: 'An Error Occurred',
text: err.response.data.description,
type: 'error',
})
}
this.$nuxt.$loading.finish()
},
async declineInvite(teamId) {
const config = {
headers: {
Authorization: this.$auth.getToken('local'),
},
}
this.$nuxt.$loading.start()
try {
await axios.delete(
`https://api.modrinth.com/api/v1/team/${teamId}/members/${this.$auth.user.id}`,
config
)
await this.$router.go(null)
} catch (err) {
this.$notify({
group: 'main',
title: 'An Error Occurred',
text: err.response.data.description,
type: 'error',
})
}
this.$nuxt.$loading.finish()
},
},
}
</script>
<style lang="scss" scoped>
.invite {
@extend %card;
padding: var(--spacing-card-sm) var(--spacing-card-lg);
margin-bottom: var(--spacing-card-sm);
align-items: center;
justify-content: space-between;
p {
margin: 0;
}
}
</style>