2022-07-14 17:38:11 +09:00
|
|
|
<template>
|
2022-07-14 19:40:41 +09:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
|
2023-06-04 15:37:50 +09:00
|
|
|
<MkSpacer :contentMax="700">
|
2023-06-17 03:12:13 +09:00
|
|
|
<div v-if="tab === 'owned'">
|
|
|
|
<MkPagination v-slot="{items}" ref="pagingComponent" :pagination="ownedPagination">
|
|
|
|
<MkA v-for="group in items" :key="group.id" :class="$style.group" class="_panel" :to="`/my/groups/${ group.id }`">
|
|
|
|
<div :class="$style.name">{{ group.name }}</div>
|
2023-06-04 15:37:50 +09:00
|
|
|
<MkAvatars :userIds="group.userIds"/>
|
2023-02-07 14:23:48 +09:00
|
|
|
</MkA>
|
2022-07-14 19:40:41 +09:00
|
|
|
</MkPagination>
|
|
|
|
</div>
|
|
|
|
|
2023-06-17 03:12:13 +09:00
|
|
|
<div v-else-if="tab === 'joined'">
|
|
|
|
<MkPagination v-slot="{items}" ref="pagingComponent" :pagination="joinedPagination">
|
|
|
|
<MkA v-for="group in items" :key="group.id" :class="$style.group" class="_panel" :to="`/my/groups/${ group.id }`">
|
|
|
|
<div :class="$style.name">{{ group.name }}</div>
|
2023-06-04 15:37:50 +09:00
|
|
|
<MkAvatars :userIds="group.userIds"/>
|
2023-06-17 03:12:13 +09:00
|
|
|
<div :class="$style.actions">
|
|
|
|
<MkButton rounded danger @click="leave(group)">{{ i18n.ts.leaveGroup }}</MkButton>
|
2022-07-14 19:40:41 +09:00
|
|
|
</div>
|
2023-02-07 14:23:48 +09:00
|
|
|
</MkA>
|
2022-07-14 19:40:41 +09:00
|
|
|
</MkPagination>
|
|
|
|
</div>
|
|
|
|
|
2023-06-17 03:12:13 +09:00
|
|
|
<div v-else-if="tab === 'invites'">
|
2022-07-14 19:40:41 +09:00
|
|
|
<MkPagination v-slot="{items}" ref="pagingComponent" :pagination="invitationPagination">
|
2023-06-17 03:12:13 +09:00
|
|
|
<MkA v-for="invitation in items" :key="invitation.id" :class="$style.group" class="_panel">
|
|
|
|
<div :class="$style.name">{{ invitation.group.name }}</div>
|
2023-06-04 15:37:50 +09:00
|
|
|
<MkAvatars :userIds="invitation.group.userIds"/>
|
2023-06-17 03:12:13 +09:00
|
|
|
<div :class="$style.actions">
|
|
|
|
<MkButton primary rounded inline :class="$style.invitesButton" @click="acceptInvite(invitation)"><i class="ti ti-check"></i> {{ i18n.ts.accept }}</MkButton>
|
|
|
|
<MkButton rounded inline :class="$style.invitesButton" @click="rejectInvite(invitation)"><i class="ti ti-x"></i> {{ i18n.ts.reject }}</MkButton>
|
2022-07-14 19:40:41 +09:00
|
|
|
</div>
|
2023-02-07 14:23:48 +09:00
|
|
|
</MkA>
|
2022-07-14 19:40:41 +09:00
|
|
|
</MkPagination>
|
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2022-07-14 17:38:11 +09:00
|
|
|
</template>
|
|
|
|
|
2022-07-14 19:40:41 +09:00
|
|
|
<script lang="ts" setup>
|
2023-02-10 22:29:15 +09:00
|
|
|
import { } from 'vue';
|
2022-09-29 13:09:11 +09:00
|
|
|
import MkPagination from '@/components/MkPagination.vue';
|
|
|
|
import MkButton from '@/components/MkButton.vue';
|
|
|
|
import MkAvatars from '@/components/MkAvatars.vue';
|
2022-07-14 17:38:11 +09:00
|
|
|
import * as os from '@/os';
|
2022-07-14 19:40:41 +09:00
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
|
|
|
|
|
|
|
const pagingComponent = $ref<InstanceType<typeof MkPagination>>();
|
|
|
|
|
|
|
|
const ownedPagination = {
|
|
|
|
endpoint: 'users/groups/owned' as const,
|
|
|
|
limit: 10,
|
|
|
|
// sort: '+createdAt/updatedAt',
|
|
|
|
};
|
|
|
|
const joinedPagination = {
|
|
|
|
endpoint: 'users/groups/joined' as const,
|
|
|
|
limit: 10,
|
|
|
|
};
|
|
|
|
const invitationPagination = {
|
|
|
|
endpoint: 'i/user-group-invites' as const,
|
|
|
|
limit: 10,
|
|
|
|
};
|
|
|
|
|
|
|
|
let tab = $ref('owned');
|
|
|
|
|
|
|
|
async function create() {
|
|
|
|
const { canceled, result: name } = await os.inputText({
|
|
|
|
title: i18n.ts.groupName,
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
await os.apiWithDialog('users/groups/create', { name: name });
|
|
|
|
pagingComponent.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function acceptInvite(invitation) {
|
|
|
|
os.apiWithDialog('users/groups/invitations/accept', {
|
|
|
|
invitationId: invitation.id,
|
|
|
|
}).then(() => {
|
|
|
|
os.success();
|
|
|
|
pagingComponent.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function rejectInvite(invitation) {
|
|
|
|
os.apiWithDialog('users/groups/invitations/reject', {
|
|
|
|
invitationId: invitation.id,
|
|
|
|
}).then(() => {
|
|
|
|
pagingComponent.reload();
|
|
|
|
// this.$refs.invitations.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function leave(group) {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.t('leaveGroupConfirm', { name: group.name }),
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
os.apiWithDialog('users/groups/leave', {
|
|
|
|
groupId: group.id,
|
|
|
|
}).then(() => {
|
|
|
|
pagingComponent.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-04 15:32:11 +09:00
|
|
|
const headerActions = $computed(() => [{
|
|
|
|
icon: 'ti ti-plus',
|
|
|
|
text: i18n.ts.createGroup,
|
|
|
|
handler: create,
|
|
|
|
}]);
|
2022-07-14 19:40:41 +09:00
|
|
|
|
|
|
|
const headerTabs = $computed(() => [{
|
|
|
|
key: 'owned',
|
|
|
|
title: i18n.ts.ownedGroups,
|
2023-02-10 22:29:15 +09:00
|
|
|
icon: 'ti ti-flag',
|
2022-07-14 19:40:41 +09:00
|
|
|
}, {
|
|
|
|
key: 'joined',
|
|
|
|
title: i18n.ts.joinedGroups,
|
2023-02-07 14:23:48 +09:00
|
|
|
icon: 'ti ti-id-badge',
|
2022-07-14 19:40:41 +09:00
|
|
|
}, {
|
|
|
|
key: 'invites',
|
|
|
|
title: i18n.ts.invites,
|
2023-02-10 22:29:15 +09:00
|
|
|
icon: 'ti ti-mail-opened',
|
2022-07-14 19:40:41 +09:00
|
|
|
}]);
|
2023-02-10 20:19:16 +09:00
|
|
|
|
2022-07-14 19:40:41 +09:00
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.groups,
|
2023-02-10 22:29:15 +09:00
|
|
|
icon: 'ti ti-users',
|
2022-07-14 19:40:41 +09:00
|
|
|
actions: [{
|
2023-02-07 14:23:48 +09:00
|
|
|
icon: 'ti ti-plus',
|
2022-07-14 19:40:41 +09:00
|
|
|
text: i18n.ts.createGroup,
|
|
|
|
handler: create,
|
|
|
|
}],
|
2022-07-14 17:38:11 +09:00
|
|
|
});
|
2022-07-14 19:40:41 +09:00
|
|
|
|
2022-07-14 17:38:11 +09:00
|
|
|
</script>
|
|
|
|
|
2023-06-17 03:12:13 +09:00
|
|
|
<style lang="scss" module>
|
|
|
|
.actions {
|
|
|
|
margin-top: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.add {
|
|
|
|
margin: 0 auto var(--margin) auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.group {
|
|
|
|
display: block;
|
|
|
|
padding: 16px;
|
|
|
|
border: solid 1px var(--divider);
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
border: solid 1px var(--accent);
|
|
|
|
text-decoration: none;
|
2023-02-10 22:29:15 +09:00
|
|
|
}
|
2023-06-17 03:12:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
.name {
|
|
|
|
margin-bottom: 12px;
|
|
|
|
}
|
2023-02-10 22:29:15 +09:00
|
|
|
|
2023-06-17 03:12:13 +09:00
|
|
|
.invitesButton {
|
|
|
|
&:not(:last-child) {
|
|
|
|
margin-right: 5px;
|
2023-02-10 22:29:15 +09:00
|
|
|
}
|
|
|
|
}
|
2022-07-14 17:38:11 +09:00
|
|
|
</style>
|