trashposs/packages/client/src/pages/my-groups/group.vue

191 lines
3.6 KiB
Vue
Raw Normal View History

<template>
2022-09-14 02:08:09 +02:00
<MkStickyContainer>
<template #header><MkPageHeader/></template>
2022-09-14 02:08:09 +02:00
<div class="mk-group-page">
2022-09-14 02:19:34 +02:00
<div class="_section">
2022-09-14 02:56:19 +02:00
<div
class="_content"
style="display: flex; gap: var(--margin); flex-wrap: wrap"
>
2022-09-14 02:32:43 +02:00
<MkButton inline @click="invite()">{{ i18n.ts.invite }}</MkButton>
2022-09-14 02:56:19 +02:00
<MkButton inline @click="renameGroup()">{{
i18n.ts.rename
}}</MkButton>
2022-09-14 02:32:43 +02:00
<MkButton inline @click="transfer()">{{ i18n.ts.transfer }}</MkButton>
2022-09-14 02:56:19 +02:00
<MkButton inline @click="deleteGroup()">{{
i18n.ts.delete
}}
</MkButton>
</div>
2022-09-14 02:19:34 +02:00
</div>
<div class="_section members _gap">
<div class="_content">
<div class="users">
<div v-for="user in users" :key="user.id" class="user _panel">
2022-09-14 02:56:19 +02:00
<MkAvatar :user="user" class="avatar" :show-indicator="true" />
2022-09-14 02:19:34 +02:00
<div class="body">
2022-09-14 02:56:19 +02:00
<MkUserName :user="user" class="name" />
<MkAcct :user="user" class="acct" />
2022-09-14 02:19:34 +02:00
</div>
<div class="action">
2022-09-14 02:56:19 +02:00
<button class="_button" @click="removeUser(user)">
<i class="fas fa-times"></i>
</button>
</div>
</div>
</div>
</div>
2022-09-14 02:19:34 +02:00
</div>
2022-09-14 02:08:09 +02:00
</div>
</MkStickyContainer>
</template>
2022-09-14 02:08:09 +02:00
<script lang="ts" setup>
2022-09-14 02:56:19 +02:00
import { computed, ref, watch } from "vue";
import MkButton from "@/components/MkButton.vue";
import { definePageMetadata } from "@/scripts/page-metadata";
import { i18n } from "@/i18n";
import { useRouter } from "@/router";
import * as os from "@/os";
2022-09-14 02:14:56 +02:00
const props = defineProps<{
groupId: {
2022-09-14 02:56:19 +02:00
type: string;
required: true;
};
2022-09-14 02:14:56 +02:00
}>();
2022-09-14 02:43:23 +02:00
const users = ref<any[]>([]);
2022-09-14 02:40:06 +02:00
const group = ref<any>();
2022-09-14 02:32:43 +02:00
const router = useRouter();
2022-09-14 02:56:19 +02:00
watch(
() => props.groupId,
() => {
fetch();
}
);
2022-09-14 02:08:09 +02:00
2022-09-14 02:35:08 +02:00
async function fetch() {
2022-09-14 02:56:19 +02:00
os.api("users/groups/show", {
2022-09-14 02:32:43 +02:00
groupId: props.groupId,
2022-09-14 02:56:19 +02:00
}).then((gp) => {
2022-09-14 02:41:58 +02:00
group.value = gp;
2022-09-14 02:56:19 +02:00
os.api("users/show", {
userIds: group.value.userIds,
}).then((us) => {
2022-09-14 02:41:58 +02:00
users.value = us;
2022-09-14 02:14:56 +02:00
});
});
}
2022-09-14 02:35:08 +02:00
fetch();
2022-09-14 02:14:56 +02:00
function invite() {
2022-09-14 02:56:19 +02:00
os.selectUser().then((user) => {
os.apiWithDialog("users/groups/invite", {
2022-09-14 02:52:31 +02:00
groupId: group.value.id,
userId: user.id,
2022-09-14 02:14:56 +02:00
});
});
2022-09-14 02:16:27 +02:00
}
2022-09-14 02:14:56 +02:00
function removeUser(user) {
2022-09-14 02:56:19 +02:00
os.api("users/groups/pull", {
2022-09-14 02:52:31 +02:00
groupId: group.value.id,
2022-09-14 02:56:19 +02:00
userId: user.id,
2022-09-14 02:14:56 +02:00
}).then(() => {
2022-09-14 02:56:19 +02:00
users.value = users.value.filter((x) => x.id !== user.id);
2022-09-14 02:14:56 +02:00
});
2022-09-14 02:16:27 +02:00
}
2022-09-14 02:14:56 +02:00
async function renameGroup() {
const { canceled, result: name } = await os.inputText({
2022-09-14 02:32:43 +02:00
title: i18n.ts.groupName,
2022-09-14 02:56:19 +02:00
default: group.value.name,
2022-09-14 02:14:56 +02:00
});
if (canceled) return;
2022-09-14 02:56:19 +02:00
await os.api("users/groups/update", {
2022-09-14 02:52:31 +02:00
groupId: group.value.id,
2022-09-14 02:56:19 +02:00
name: name,
2022-09-14 02:14:56 +02:00
});
2022-09-14 02:52:31 +02:00
group.value.name = name;
2022-09-14 02:16:27 +02:00
}
2022-09-14 02:14:56 +02:00
function transfer() {
2022-09-14 02:56:19 +02:00
os.selectUser().then((user) => {
os.apiWithDialog("users/groups/transfer", {
2022-09-14 02:52:31 +02:00
groupId: group.value.id,
userId: user.id,
2022-09-14 02:14:56 +02:00
});
});
2022-09-14 02:16:27 +02:00
}
2022-09-14 02:14:56 +02:00
async function deleteGroup() {
const { canceled } = await os.confirm({
2022-09-14 02:56:19 +02:00
type: "warning",
text: i18n.t("removeAreYouSure", { x: group.value.name }),
2022-09-14 02:14:56 +02:00
});
if (canceled) return;
2022-09-14 02:56:19 +02:00
await os.apiWithDialog("users/groups/delete", {
2022-09-14 02:52:31 +02:00
groupId: group.value.id,
2022-09-14 02:14:56 +02:00
});
2022-09-14 02:56:19 +02:00
router.push("/my/groups");
2022-09-14 02:14:56 +02:00
}
2022-09-14 02:56:19 +02:00
definePageMetadata(
computed(() => ({
title: i18n.ts.members,
icon: "fas fa-users",
})),
2022-09-14 02:56:19 +02:00
);
</script>
<style lang="scss" scoped>
2022-09-14 02:56:19 +02:00
.mk-group-page {
> ._section {
> ._content {
padding-top: 1rem;
justify-content: center;
2022-09-14 02:08:09 +02:00
}
2022-09-14 02:56:19 +02:00
}
> .members {
> ._content {
> .users {
> ._panel {
margin: 1rem 2rem;
}
> .user {
display: flex;
align-items: center;
padding: 16px;
> .avatar {
width: 50px;
height: 50px;
}
2022-09-14 02:56:19 +02:00
> .body {
flex: 1;
padding: 8px;
2022-09-14 02:56:19 +02:00
> .name {
display: block;
font-weight: bold;
}
2022-09-14 02:56:19 +02:00
> .acct {
opacity: 0.5;
}
}
}
}
}
}
2022-09-14 02:56:19 +02:00
}
</style>