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

189 lines
3.4 KiB
Vue
Raw Normal View History

<template>
2022-09-14 02:08:09 +02:00
<MkStickyContainer>
<template #header><MkPageHeader :actions="headerActions"/></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 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)">
2022-11-07 03:49:47 +01:00
<i class="ph-x-bold ph-lg"></i>
2022-09-14 02:56:19 +02:00
</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 { 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,
2022-11-07 21:29:56 +01:00
icon: "ph-users-three-bold ph-lg",
})),
2022-09-14 02:56:19 +02:00
);
const headerActions = $computed(() => [
{
2022-11-07 03:49:47 +01:00
icon: 'ph-plus-bold ph-lg',
text: i18n.ts.invite,
handler: invite,
}, {
2022-11-07 03:49:47 +01:00
icon: 'ph-cursor-text-bold ph-lg',
text: i18n.ts.rename,
handler: renameGroup,
}, {
2022-11-07 03:49:47 +01:00
icon: 'ph-arrows-left-right-bold ph-lg',
text: i18n.ts.transfer,
handler: transfer,
}, {
2022-11-07 03:49:47 +01:00
icon: 'ph-trash-bold ph-lg',
text: i18n.ts.delete,
handler: deleteGroup,
},
]);
</script>
<style lang="scss" scoped>
2022-09-14 02:56:19 +02:00
.mk-group-page {
> .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>