summaryrefslogtreecommitdiff
path: root/packages/frontend/src/pages/settings/migration.vue
blob: 2ef8af7481d1b9b86c3fe51a3f4de2f7b07d6c7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<template>
<div class="_gaps_m">
	<FormSection first>
		<template #label>{{ i18n.ts._accountMigration.moveTo }}</template>
		<MkInput v-model="moveToAccount" manual-save>
			<template #prefix><i class="ti ti-plane-departure"></i></template>
			<template #label>{{ i18n.ts._accountMigration.moveToLabel }}</template>
		</MkInput>
	</FormSection>
	<FormInfo warn>{{ i18n.ts._accountMigration.moveAccountDescription }}</FormInfo>

	<FormSection>
		<template #label>{{ i18n.ts._accountMigration.moveFrom }}</template>
		<MkInput v-model="accountAlias" manual-save>
			<template #prefix><i class="ti ti-plane-arrival"></i></template>
			<template #label>{{ i18n.ts._accountMigration.moveFromLabel }}</template>
		</MkInput>
	</FormSection>
	<FormInfo warn>{{ i18n.ts._accountMigration.moveFromDescription }}</FormInfo>
</div>
</template>

<script lang="ts" setup>
import { ref, watch } from 'vue';
import FormSection from '@/components/form/section.vue';
import FormInfo from '@/components/MkInfo.vue';
import MkInput from '@/components/MkInput.vue';
import * as os from '@/os';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';

const moveToAccount = ref('');
const accountAlias = ref('');

async function move(): Promise<void> {
	const account = moveToAccount.value;
	const confirm = await os.confirm({
		type: 'warning',
		text: i18n.t('migrationConfirm', { account: account.toString() }),
	});
	if (confirm.canceled) return;
	os.apiWithDialog('i/move', {
		moveToAccount: account,
	});
}

async function save(): Promise<void> {
	const account = accountAlias.value;
	os.apiWithDialog('i/known-as', {
		alsoKnownAs: account,
	});
}

watch(accountAlias, async () => {
	await save();
});

watch(moveToAccount, async () => {
	await move();
});

definePageMetadata({
	title: i18n.ts.accountMigration,
	icon: 'ti ti-plane',
});
</script>

<style lang="scss">
.description {
	font-size: .85em;
	padding: 1rem;
}
</style>