Sharkey/packages/frontend/src/components/SkApprovalUser.vue

118 lines
2.6 KiB
Vue
Raw Normal View History

2023-10-20 00:02:01 +02:00
<template>
<MkFolder :expanded="false">
<template #icon><i class="ph-user ph-bold ph-lg"></i></template>
<template #label>{{ i18n.ts.user }}: {{ user.username }}</template>
<div class="_gaps_s" :class="$style.root">
<div :class="$style.items">
<div>
<div :class="$style.label">{{ i18n.ts.createdAt }}</div>
<div><MkTime :time="user.createdAt" mode="absolute"/></div>
</div>
<div v-if="email">
<div :class="$style.label">{{ i18n.ts.emailAddress }}</div>
<div>{{ email }}</div>
</div>
<div>
<div :class="$style.label">Reason</div>
<div>{{ reason }}</div>
</div>
</div>
<div :class="$style.buttons">
2023-10-20 00:13:21 +02:00
<MkButton inline success @click="approveAccount()">{{ i18n.ts.approveAccount }}</MkButton>
<MkButton inline danger @click="deleteAccount()">{{ i18n.ts.denyAccount }}</MkButton>
2023-10-20 00:02:01 +02:00
</div>
</div>
</MkFolder>
</template>
<script lang="ts" setup>
2023-12-23 02:09:23 +01:00
import { ref } from 'vue';
2023-10-20 00:02:01 +02:00
import * as Misskey from 'misskey-js';
import MkFolder from '@/components/MkFolder.vue';
import MkButton from '@/components/MkButton.vue';
import { i18n } from '@/i18n.js';
import * as os from '@/os.js';
2024-01-09 02:57:57 +01:00
import { misskeyApi } from '@/scripts/misskey-api.js';
2023-10-20 00:02:01 +02:00
const props = defineProps<{
user: Misskey.entities.User;
}>();
2023-12-23 02:09:23 +01:00
let reason = ref('');
let email = ref('');
2023-10-20 00:02:01 +02:00
function getReason() {
2024-01-09 02:57:57 +01:00
return misskeyApi('admin/show-user', {
2023-10-20 00:02:01 +02:00
userId: props.user.id,
}).then(info => {
2023-12-23 02:09:23 +01:00
reason.value = info?.signupReason;
email.value = info?.email;
2023-10-20 00:02:01 +02:00
});
}
2023-10-31 19:57:52 +01:00
2023-10-20 00:02:01 +02:00
getReason();
const emits = defineEmits<{
(event: 'deleted', value: string): void;
}>();
2023-10-20 00:13:21 +02:00
async function deleteAccount() {
2023-10-20 00:02:01 +02:00
const confirm = await os.confirm({
type: 'warning',
text: i18n.ts.deleteAccountConfirm,
});
if (confirm.canceled) return;
const typed = await os.inputText({
2023-10-20 00:13:21 +02:00
text: i18n.t('typeToConfirm', { x: props.user.username }),
2023-10-20 00:02:01 +02:00
});
if (typed.canceled) return;
2023-10-20 00:13:21 +02:00
if (typed.result === props.user.username) {
2023-10-20 00:02:01 +02:00
await os.apiWithDialog('admin/delete-account', {
2023-10-20 00:13:21 +02:00
userId: props.user.id,
2023-10-20 00:02:01 +02:00
});
2023-10-20 00:13:21 +02:00
emits('deleted', props.user.id);
2023-10-20 00:02:01 +02:00
} else {
os.alert({
type: 'error',
text: 'input not match',
});
}
}
2023-10-20 00:13:21 +02:00
async function approveAccount() {
2023-10-20 00:02:01 +02:00
const confirm = await os.confirm({
type: 'warning',
text: i18n.ts.approveConfirm,
});
if (confirm.canceled) return;
2024-01-09 02:57:57 +01:00
await misskeyApi('admin/approve-user', { userId: props.user.id });
2023-10-20 00:13:21 +02:00
emits('deleted', props.user.id);
2023-10-20 00:02:01 +02:00
}
</script>
<style lang="scss" module>
.root {
text-align: left;
}
.items {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
grid-gap: 12px;
}
.label {
font-size: 0.85em;
padding: 0 0 8px 0;
user-select: none;
opacity: 0.7;
}
.buttons {
display: flex;
gap: 8px;
}
2023-10-20 00:13:21 +02:00
</style>