catarse/catarse.js

View on GitHub
legacy/src/c/subscription-next-charge-date.js

Summary

Maintainability
A
25 mins
Test Coverage
import m from 'mithril';
import subscriptionNextChargeDateMethodInfo from './subscription-next-charge-date-method-info';

const subscriptionNextChargeDate = {
    view: function({
        attrs
    }) {
        const {
            subscription,
            last_payment
        } = attrs;

        const {
            status,
            next_charge_at
        } = subscription;

        const payment_method = last_payment ? last_payment.payment_method : '';
        const payment_method_details = last_payment ? last_payment.payment_method_details : '';

        if ((status === 'active' || status === 'started') && !!next_charge_at) {
            return m('div.card-secondary.fontsize-smaller.u-marginbottom-20', [
                m('span.fontweight-semibold', 'Próxima cobrança:'),
                m.trust(' '),
                m(subscriptionNextChargeDateMethodInfo, {
                    next_charge_at,
                    payment_method,
                    payment_method_details
                })
            ]);
        } else {
            return m('span[style="display:none"]');
        }
    }
};

export default subscriptionNextChargeDate;