summaryrefslogtreecommitdiff
path: root/packages/client/src/pages/admin/integrations.twitter.vue
blob: 1f8074535aa64648c7b677e08cc6bcbaa82fb13d (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
74
75
76
77
78
79
80
<template>
<FormSuspense :p="init">
	<div class="_formRoot">
		<FormSwitch v-model="enableTwitterIntegration" class="_formBlock">
			<template #label>{{ $ts.enable }}</template>
		</FormSwitch>

		<template v-if="enableTwitterIntegration">
			<FormInfo class="_formBlock">Callback URL: {{ `${uri}/api/tw/cb` }}</FormInfo>
		
			<FormInput v-model="twitterConsumerKey" class="_formBlock">
				<template #prefix><i class="fas fa-key"></i></template>
				<template #label>Consumer Key</template>
			</FormInput>

			<FormInput v-model="twitterConsumerSecret" class="_formBlock">
				<template #prefix><i class="fas fa-key"></i></template>
				<template #label>Consumer Secret</template>
			</FormInput>
		</template>

		<FormButton primary class="_formBlock" @click="save"><i class="fas fa-save"></i> {{ $ts.save }}</FormButton>
	</div>
</FormSuspense>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import FormSwitch from '@/components/form/switch.vue';
import FormInput from '@/components/form/input.vue';
import FormButton from '@/components/ui/button.vue';
import FormInfo from '@/components/ui/info.vue';
import FormSuspense from '@/components/form/suspense.vue';
import * as os from '@/os';
import * as symbols from '@/symbols';
import { fetchInstance } from '@/instance';

export default defineComponent({
	components: {
		FormSwitch,
		FormInput,
		FormInfo,
		FormButton,
		FormSuspense,
	},

	emits: ['info'],

	data() {
		return {
			[symbols.PAGE_INFO]: {
				title: 'Twitter',
				icon: 'fab fa-twitter'
			},
			enableTwitterIntegration: false,
			twitterConsumerKey: null,
			twitterConsumerSecret: null,
		}
	},

	methods: {
		async init() {
			const meta = await os.api('meta', { detail: true });
			this.uri = meta.uri;
			this.enableTwitterIntegration = meta.enableTwitterIntegration;
			this.twitterConsumerKey = meta.twitterConsumerKey;
			this.twitterConsumerSecret = meta.twitterConsumerSecret;
		},
		save() {
			os.apiWithDialog('admin/update-meta', {
				enableTwitterIntegration: this.enableTwitterIntegration,
				twitterConsumerKey: this.twitterConsumerKey,
				twitterConsumerSecret: this.twitterConsumerSecret,
			}).then(() => {
				fetchInstance();
			});
		}
	}
});
</script>