2020-02-08 15:11:12 +09:00
|
|
|
<template>
|
2021-12-14 22:27:33 +09:00
|
|
|
<MkSpacer :content-max="700">
|
|
|
|
<div v-if="tab === 'owned'" class="_content">
|
|
|
|
<MkButton primary style="margin: 0 auto var(--margin) auto;" @click="create"><i class="fas fa-plus"></i> {{ $ts.createGroup }}</MkButton>
|
2020-02-08 15:11:12 +09:00
|
|
|
|
2021-12-14 22:27:33 +09:00
|
|
|
<MkPagination v-slot="{items}" ref="owned" :pagination="ownedPagination">
|
|
|
|
<div v-for="group in items" :key="group.id" class="_card">
|
|
|
|
<div class="_title"><MkA :to="`/my/groups/${ group.id }`" class="_link">{{ group.name }}</MkA></div>
|
|
|
|
<div class="_content"><MkAvatars :user-ids="group.userIds"/></div>
|
|
|
|
</div>
|
|
|
|
</MkPagination>
|
|
|
|
</div>
|
2020-02-08 15:11:12 +09:00
|
|
|
|
2021-12-14 22:27:33 +09:00
|
|
|
<div v-else-if="tab === 'joined'" class="_content">
|
|
|
|
<MkPagination v-slot="{items}" ref="joined" :pagination="joinedPagination">
|
|
|
|
<div v-for="group in items" :key="group.id" class="_card">
|
|
|
|
<div class="_title">{{ group.name }}</div>
|
|
|
|
<div class="_content"><MkAvatars :user-ids="group.userIds"/></div>
|
|
|
|
<div class="_footer">
|
|
|
|
<MkButton danger @click="leave(group)">{{ $ts.leaveGroup }}</MkButton>
|
2020-02-08 15:47:16 +09:00
|
|
|
</div>
|
2021-12-14 22:27:33 +09:00
|
|
|
</div>
|
|
|
|
</MkPagination>
|
|
|
|
</div>
|
2020-02-08 15:11:12 +09:00
|
|
|
|
2021-12-14 22:27:33 +09:00
|
|
|
<div v-else-if="tab === 'invites'" class="_content">
|
|
|
|
<MkPagination v-slot="{items}" ref="invitations" :pagination="invitationPagination">
|
|
|
|
<div v-for="invitation in items" :key="invitation.id" class="_card">
|
|
|
|
<div class="_title">{{ invitation.group.name }}</div>
|
|
|
|
<div class="_content"><MkAvatars :user-ids="invitation.group.userIds"/></div>
|
|
|
|
<div class="_footer">
|
|
|
|
<MkButton primary inline @click="acceptInvite(invitation)"><i class="fas fa-check"></i> {{ $ts.accept }}</MkButton>
|
|
|
|
<MkButton primary inline @click="rejectInvite(invitation)"><i class="fas fa-ban"></i> {{ $ts.reject }}</MkButton>
|
2020-10-17 20:12:00 +09:00
|
|
|
</div>
|
2021-12-14 22:27:33 +09:00
|
|
|
</div>
|
|
|
|
</MkPagination>
|
2020-10-17 20:12:00 +09:00
|
|
|
</div>
|
2021-12-14 22:27:33 +09:00
|
|
|
</MkSpacer>
|
2020-02-08 15:11:12 +09:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-12-14 22:27:33 +09:00
|
|
|
import { defineComponent, computed } from 'vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import MkPagination from '@/components/ui/pagination.vue';
|
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkContainer from '@/components/ui/container.vue';
|
|
|
|
import MkAvatars from '@/components/avatars.vue';
|
|
|
|
import MkTab from '@/components/tab.vue';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import * as symbols from '@/symbols';
|
2020-02-08 15:11:12 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2020-02-08 15:11:12 +09:00
|
|
|
components: {
|
|
|
|
MkPagination,
|
|
|
|
MkButton,
|
|
|
|
MkContainer,
|
2020-10-17 20:12:00 +09:00
|
|
|
MkTab,
|
2020-02-08 16:51:27 +09:00
|
|
|
MkAvatars,
|
2020-02-08 15:11:12 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-12-14 22:27:33 +09:00
|
|
|
[symbols.PAGE_INFO]: computed(() => ({
|
2020-12-26 10:47:36 +09:00
|
|
|
title: this.$ts.groups,
|
2021-12-14 22:27:33 +09:00
|
|
|
icon: 'fas fa-users',
|
|
|
|
bg: 'var(--bg)',
|
|
|
|
actions: [{
|
|
|
|
icon: 'fas fa-plus',
|
|
|
|
text: this.$ts.createGroup,
|
|
|
|
handler: this.create,
|
|
|
|
}],
|
|
|
|
tabs: [{
|
|
|
|
active: this.tab === 'owned',
|
|
|
|
title: this.$ts.ownedGroups,
|
|
|
|
icon: 'fas fa-user-tie',
|
|
|
|
onClick: () => { this.tab = 'owned'; },
|
|
|
|
}, {
|
|
|
|
active: this.tab === 'joined',
|
|
|
|
title: this.$ts.joinedGroups,
|
|
|
|
icon: 'fas fa-id-badge',
|
|
|
|
onClick: () => { this.tab = 'joined'; },
|
|
|
|
}, {
|
|
|
|
active: this.tab === 'invites',
|
|
|
|
title: this.$ts.invites,
|
|
|
|
icon: 'fas fa-envelope-open-text',
|
|
|
|
onClick: () => { this.tab = 'invites'; },
|
|
|
|
},]
|
|
|
|
})),
|
2020-10-17 20:12:00 +09:00
|
|
|
tab: 'owned',
|
2020-02-08 15:11:12 +09:00
|
|
|
ownedPagination: {
|
|
|
|
endpoint: 'users/groups/owned',
|
|
|
|
limit: 10,
|
|
|
|
},
|
|
|
|
joinedPagination: {
|
|
|
|
endpoint: 'users/groups/joined',
|
|
|
|
limit: 10,
|
|
|
|
},
|
2020-02-13 02:17:54 +09:00
|
|
|
invitationPagination: {
|
2020-02-08 15:11:12 +09:00
|
|
|
endpoint: 'i/user-group-invites',
|
|
|
|
limit: 10,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
async create() {
|
2021-11-18 18:45:58 +09:00
|
|
|
const { canceled, result: name } = await os.inputText({
|
2020-12-26 10:47:36 +09:00
|
|
|
title: this.$ts.groupName,
|
2020-02-08 15:11:12 +09:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
2020-10-17 20:12:00 +09:00
|
|
|
await os.api('users/groups/create', { name: name });
|
2020-02-08 15:11:12 +09:00
|
|
|
this.$refs.owned.reload();
|
2020-10-17 20:12:00 +09:00
|
|
|
os.success();
|
2020-02-08 15:11:12 +09:00
|
|
|
},
|
2020-02-13 02:17:54 +09:00
|
|
|
acceptInvite(invitation) {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('users/groups/invitations/accept', {
|
2020-02-13 02:17:54 +09:00
|
|
|
invitationId: invitation.id
|
2020-02-09 03:40:09 +09:00
|
|
|
}).then(() => {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.success();
|
2020-02-13 02:17:54 +09:00
|
|
|
this.$refs.invitations.reload();
|
2020-02-09 03:40:09 +09:00
|
|
|
this.$refs.joined.reload();
|
|
|
|
});
|
|
|
|
},
|
2020-02-13 02:17:54 +09:00
|
|
|
rejectInvite(invitation) {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('users/groups/invitations/reject', {
|
2020-02-13 02:17:54 +09:00
|
|
|
invitationId: invitation.id
|
2020-02-09 03:40:09 +09:00
|
|
|
}).then(() => {
|
2020-02-13 02:17:54 +09:00
|
|
|
this.$refs.invitations.reload();
|
2020-02-09 03:40:09 +09:00
|
|
|
});
|
2021-12-14 22:27:33 +09:00
|
|
|
},
|
|
|
|
async leave(group) {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: this.$t('leaveGroupConfirm', { name: group.name }),
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
os.apiWithDialog('users/groups/leave', {
|
|
|
|
groupId: group.id,
|
|
|
|
}).then(() => {
|
|
|
|
this.$refs.joined.reload();
|
|
|
|
});
|
2020-02-09 03:40:09 +09:00
|
|
|
}
|
2020-02-08 15:11:12 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
</style>
|