Files
cloudron-box/dashboard/src/components/CloudronAccount.vue
T

109 lines
4.0 KiB
Vue
Raw Normal View History

2025-01-24 18:28:45 +01:00
<script setup>
import { ref, onMounted } from 'vue';
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';
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();
const dashboardModel = DashboardModel.create();
2025-01-24 18:28:45 +01: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 () => {
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')">
<!-- 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
<div class="info-row" v-if="email">
2025-03-21 11:42:30 +01:00
<div class="info-label">{{ $t('settings.appstoreAccount.email') }}</div>
<!-- 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
<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>
<div style="display: flex; align-items: center;">
{{ $t('settings.appstoreAccount.description') }}
</div>
<div style="display: flex; align-items: center;">
<Button :href="`${consoleServerOrigin}/#/claim/${cloudronId}`" target="_blank">{{ $t('settings.appstoreAccount.setupAction') }}</Button>
</div>
2025-03-21 11:42:30 +01:00
</SettingsItem>
</div>
2025-01-24 18:28:45 +01:00
</div>
<div v-else>
<Spinner class="pankow-spinner-large"/>
</div>
2025-01-24 18:28:45 +01:00
</Section>
</div>
</template>