2023-07-27 14:31:52 +09:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2023-07-15 09:57:58 +09:00
|
|
|
<template>
|
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header>
|
|
|
|
<MkPageHeader/>
|
|
|
|
</template>
|
|
|
|
<MKSpacer v-if="!instance.disableRegistration || !($i && ($i.isAdmin || $i.policies.canInvite))" :contentMax="1200">
|
|
|
|
<div :class="$style.root">
|
|
|
|
<img :class="$style.img" :src="serverErrorImageUrl" class="_ghost"/>
|
|
|
|
<div :class="$style.text">
|
2023-10-01 04:53:52 +09:00
|
|
|
<i class="ph-warning ph-bold ph-lg"></i>
|
2023-07-15 09:57:58 +09:00
|
|
|
{{ i18n.ts.nothing }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</MKSpacer>
|
|
|
|
<MkSpacer v-else :contentMax="800">
|
|
|
|
<div class="_gaps_m" style="text-align: center;">
|
|
|
|
<div v-if="resetCycle && inviteLimit">{{ i18n.t('inviteLimitResetCycle', { time: resetCycle, limit: inviteLimit }) }}</div>
|
2023-10-01 04:53:52 +09:00
|
|
|
<MkButton inline primary rounded :disabled="currentInviteLimit !== null && currentInviteLimit <= 0" @click="create"><i class="ph-user-plus ph-bold ph-lg"></i> {{ i18n.ts.createInviteCode }}</MkButton>
|
2023-07-15 09:57:58 +09:00
|
|
|
<div v-if="currentInviteLimit !== null">{{ i18n.t('createLimitRemaining', { limit: currentInviteLimit }) }}</div>
|
|
|
|
|
|
|
|
<MkPagination ref="pagingComponent" :pagination="pagination">
|
|
|
|
<template #default="{ items }">
|
|
|
|
<div class="_gaps_s">
|
2023-09-04 13:33:38 +09:00
|
|
|
<MkInviteCode v-for="item in (items as Misskey.entities.Invite[])" :key="item.id" :invite="item" :onDeleted="deleted"/>
|
2023-07-15 09:57:58 +09:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</MkPagination>
|
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, ref, shallowRef } from 'vue';
|
2023-09-04 13:33:38 +09:00
|
|
|
import type * as Misskey from 'misskey-js';
|
2023-09-19 16:37:43 +09:00
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import * as os from '@/os.js';
|
2023-07-15 09:57:58 +09:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
|
|
|
import MkPagination, { Paging } from '@/components/MkPagination.vue';
|
|
|
|
import MkInviteCode from '@/components/MkInviteCode.vue';
|
2023-09-19 16:37:43 +09:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
|
|
|
import { serverErrorImageUrl, instance } from '@/instance.js';
|
|
|
|
import { $i } from '@/account.js';
|
2023-07-15 09:57:58 +09:00
|
|
|
|
|
|
|
const pagingComponent = shallowRef<InstanceType<typeof MkPagination>>();
|
|
|
|
const currentInviteLimit = ref<null | number>(null);
|
|
|
|
const inviteLimit = (($i != null && $i.policies.inviteLimit) || (($i == null && instance.policies.inviteLimit))) as number;
|
|
|
|
const inviteLimitCycle = (($i != null && $i.policies.inviteLimitCycle) || ($i == null && instance.policies.inviteLimitCycle)) as number;
|
|
|
|
|
|
|
|
const pagination: Paging = {
|
|
|
|
endpoint: 'invite/list' as const,
|
|
|
|
limit: 10,
|
|
|
|
};
|
|
|
|
|
|
|
|
const resetCycle = computed<null | string>(() => {
|
|
|
|
if (!inviteLimitCycle) return null;
|
|
|
|
|
|
|
|
const minutes = inviteLimitCycle;
|
|
|
|
if (minutes < 60) return minutes + i18n.ts._time.minute;
|
|
|
|
const hours = Math.floor(minutes / 60);
|
|
|
|
if (hours < 24) return hours + i18n.ts._time.hour;
|
|
|
|
return Math.floor(hours / 24) + i18n.ts._time.day;
|
|
|
|
});
|
|
|
|
|
|
|
|
async function create() {
|
|
|
|
const ticket = await os.api('invite/create');
|
|
|
|
os.alert({
|
|
|
|
type: 'success',
|
|
|
|
title: i18n.ts.inviteCodeCreated,
|
|
|
|
text: ticket.code,
|
|
|
|
});
|
|
|
|
|
|
|
|
pagingComponent.value?.prepend(ticket);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleted(id: string) {
|
|
|
|
if (pagingComponent.value) {
|
|
|
|
pagingComponent.value.items.delete(id);
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function update() {
|
|
|
|
currentInviteLimit.value = (await os.api('invite/limit')).remaining;
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.invite,
|
2023-10-01 04:53:52 +09:00
|
|
|
icon: 'ph-user-plus ph-bold ph-lg',
|
2023-07-15 09:57:58 +09:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
|
|
|
padding: 32px;
|
|
|
|
text-align: center;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.text {
|
|
|
|
margin: 0 0 8px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.img {
|
|
|
|
vertical-align: bottom;
|
|
|
|
width: 128px;
|
|
|
|
height: 128px;
|
|
|
|
margin-bottom: 16px;
|
|
|
|
border-radius: 16px;
|
|
|
|
}
|
|
|
|
</style>
|