Use human readable description if possible (#1688)

* Use human readable description if possible

* lint
This commit is contained in:
Paulus Schoutsen 2018-09-21 09:20:07 +02:00 committed by GitHub
parent 03525c010f
commit e1407a7d73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -196,41 +196,11 @@ class HaConfigCloudAccount extends EventsMixin(PolymerElement) {
}
_formatSubscription(subInfo) {
if (subInfo === null) {
return 'Fetching subscription…';
}
/* eslint-disable camelcase */
const { subscription, source, customer_exists } = subInfo;
// Check if we're before Oct 17.
const beforeOct17 = Date.now() < 1539734400000;
if (!customer_exists) {
return `Legacy user. Subscription expire${beforeOct17 ? 's' : 'd'} Oct 17, 2018.`;
}
if (!subscription || subscription.status === 'canceled') {
return 'No subscription';
}
const periodExpires = formatDateTime(new Date(subscription.current_period_end * 1000));
if (subscription.status === 'trialing' && !source) {
return `Trial user. Trial expires ${periodExpires}.`;
}
if (subscription.status === 'trialing') {
return `Active user. You will be charged on ${periodExpires}.`;
}
if (subscription.status === 'active' && subscription.cancel_at_period_end) {
return `Active user. Scheduled to cancel on ${periodExpires}`;
}
if (subscription.status === 'active') {
return `Active user. You will be charged on ${periodExpires}.`;
}
return 'Unable to determine subscription status.';
return subInfo === null
? 'Fetching subscription…'
: subInfo.human_description.replace(
'{periodEnd}', formatDateTime(new Date(subInfo.subscription.current_period_end * 1000))
);
}
_alexaChanged(ev) {