2025-01-24 18:28:45 +01:00
|
|
|
<script setup>
|
|
|
|
|
|
2025-05-16 18:43:52 +02:00
|
|
|
import { ref, onMounted } from 'vue';
|
2025-04-21 12:01:17 +02:00
|
|
|
import { Button, Spinner } from 'pankow';
|
2025-01-24 18:28:45 +01:00
|
|
|
import { prettyDate } from 'pankow/utils';
|
|
|
|
|
import Section from '../components/Section.vue';
|
2025-03-21 11:42:30 +01:00
|
|
|
import SettingsItem from '../components/SettingsItem.vue';
|
2025-01-24 18:28:45 +01:00
|
|
|
import AppstoreModel from '../models/AppstoreModel.js';
|
2025-04-21 12:01:17 +02:00
|
|
|
import DashboardModel from '../models/DashboardModel.js';
|
2025-01-24 18:28:45 +01:00
|
|
|
|
2025-01-31 21:02:48 +01:00
|
|
|
const appstoreModel = AppstoreModel.create();
|
2025-04-21 12:01:17 +02:00
|
|
|
const dashboardModel = DashboardModel.create();
|
2025-01-24 18:28:45 +01:00
|
|
|
|
2025-04-21 12:01:17 +02:00
|
|
|
const consoleServerOrigin = ref();
|
2025-01-24 18:28:45 +01:00
|
|
|
const busy = ref(true);
|
|
|
|
|
const hasSubscription = ref(false);
|
|
|
|
|
const email = ref('');
|
|
|
|
|
const emailEncoded = ref('');
|
|
|
|
|
const emailVerified = ref(false);
|
|
|
|
|
const cloudronId = ref('');
|
|
|
|
|
const planId = ref('');
|
|
|
|
|
const planName = ref('');
|
2025-01-25 10:34:22 +01:00
|
|
|
const cancelAt = ref(0);
|
2025-01-24 18:28:45 +01:00
|
|
|
const status = ref('');
|
|
|
|
|
|
2025-03-21 11:42:30 +01:00
|
|
|
async function refresh() {
|
2025-01-24 18:28:45 +01:00
|
|
|
const [error, result] = await appstoreModel.getSubscription();
|
2025-01-25 10:34:22 +01:00
|
|
|
if (error) {
|
|
|
|
|
if (error.status === 402) return busy.value = false; // not yet registered
|
|
|
|
|
if (error.status === 412) return busy.value = false; // invalid appstore token
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
2025-01-24 18:28:45 +01:00
|
|
|
|
|
|
|
|
hasSubscription.value = true;
|
|
|
|
|
email.value = result.email;
|
|
|
|
|
emailEncoded.value = encodeURIComponent(result.email);;
|
|
|
|
|
emailVerified.value = result.emailVerified;
|
|
|
|
|
cloudronId.value = result.cloudronId;
|
|
|
|
|
planId.value = result.plan.id;
|
|
|
|
|
planName.value = result.plan.name;
|
|
|
|
|
cancelAt.value = result.cancel_at || 0;
|
|
|
|
|
status.value = result.status;
|
2025-03-21 11:42:30 +01:00
|
|
|
}
|
2025-01-24 18:28:45 +01:00
|
|
|
|
2025-03-21 11:42:30 +01:00
|
|
|
onMounted(async () => {
|
2025-04-21 12:01:17 +02:00
|
|
|
const [error, result] = await dashboardModel.config();
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
consoleServerOrigin.value = result.consoleServerOrigin;
|
|
|
|
|
|
2025-03-21 11:42:30 +01:00
|
|
|
await refresh();
|
2025-01-24 18:28:45 +01:00
|
|
|
busy.value = false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<Section :title="$t('settings.appstoreAccount.title')">
|
2025-04-16 10:45:17 +02:00
|
|
|
<!-- TODO: Show plan info -->
|
|
|
|
|
|
2025-03-21 11:42:30 +01:00
|
|
|
<div v-if="!busy">
|
|
|
|
|
<div v-if="hasSubscription">
|
|
|
|
|
<p>{{ $t('settings.appstoreAccount.description') }}</p>
|
2025-01-24 18:28:45 +01:00
|
|
|
|
2025-05-22 17:28:16 +02:00
|
|
|
<div class="info-row" v-if="email">
|
2025-03-21 11:42:30 +01:00
|
|
|
<div class="info-label">{{ $t('settings.appstoreAccount.email') }}</div>
|
2025-04-16 10:45:17 +02:00
|
|
|
<!-- TODO change to setup subscxription -->
|
|
|
|
|
<!-- TODO button is a link to console.cloudron.io/setup-subscription?cloudronId=xxx -->
|
2025-03-21 11:42:30 +01:00
|
|
|
<div class="info-value"><a :href="`${consoleServerOrigin}?email=${emailEncoded}`" target="_blank">{{ email }} <i v-show="!emailVerified" class="fas fa-exclamation-triangle text-danger" v-tooltip="$t('settings.appstoreAccount.emailNotVerified')"></i></a></div>
|
|
|
|
|
</div>
|
2025-01-24 18:28:45 +01:00
|
|
|
|
2025-03-21 11:42:30 +01:00
|
|
|
<div class="info-row">
|
|
|
|
|
<div class="info-label">{{ $t('settings.appstoreAccount.cloudronId') }}</div>
|
|
|
|
|
<div class="info-value">{{ cloudronId }}</div>
|
|
|
|
|
</div>
|
2025-01-24 18:28:45 +01:00
|
|
|
|
2025-03-21 11:42:30 +01:00
|
|
|
<div class="info-row">
|
|
|
|
|
<div class="info-label">{{ $t('settings.appstoreAccount.subscription') }}</div>
|
|
|
|
|
<div class="info-value">{{ planName }}</div>
|
|
|
|
|
</div>
|
2025-01-24 18:28:45 +01:00
|
|
|
|
2025-03-21 11:42:30 +01:00
|
|
|
<p class="text-danger" v-show="cancelAt">{{ $t('settings.appstoreAccount.subscriptionEndsAt') }} {{ prettyDate(cancelAt*1000) }}</p>
|
2025-01-24 18:28:45 +01:00
|
|
|
|
2025-05-22 17:28:16 +02:00
|
|
|
<Button :href="`${consoleServerOrigin}/#/claim/${cloudronId}`" target="_blank">
|
|
|
|
|
<span v-if="planName.toLowerCase() === 'free'">{{ $t('settings.appstoreAccount.subscriptionSetupAction') }}</span>
|
|
|
|
|
<span v-else-if="cancelAt">{{ $t('settings.appstoreAccount.subscriptionReactivateAction') }}</span>
|
|
|
|
|
<span v-else>{{ $t('settings.appstoreAccount.subscriptionChangeAction') }}</span>
|
2025-03-21 11:42:30 +01:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
2025-01-24 18:28:45 +01:00
|
|
|
|
2025-03-21 11:42:30 +01:00
|
|
|
<div v-else>
|
|
|
|
|
<SettingsItem>
|
2025-04-08 17:36:44 +02:00
|
|
|
<div style="display: flex; align-items: center;">
|
|
|
|
|
{{ $t('settings.appstoreAccount.description') }}
|
|
|
|
|
</div>
|
|
|
|
|
<div style="display: flex; align-items: center;">
|
2025-05-23 11:31:47 +02:00
|
|
|
<Button :href="`${consoleServerOrigin}/#/claim/${cloudronId}`" target="_blank">{{ $t('settings.appstoreAccount.setupAction') }}</Button>
|
2025-04-08 17:36:44 +02:00
|
|
|
</div>
|
2025-03-21 11:42:30 +01:00
|
|
|
</SettingsItem>
|
|
|
|
|
</div>
|
2025-01-24 18:28:45 +01:00
|
|
|
</div>
|
2025-04-21 12:01:17 +02:00
|
|
|
<div v-else>
|
|
|
|
|
<Spinner class="pankow-spinner-large"/>
|
|
|
|
|
</div>
|
2025-01-24 18:28:45 +01:00
|
|
|
</Section>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|