mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-07-08 07:12:46 +00:00
DEV: Clean up helpers (#279)
* remove an unused helper * move a single-use helper to its call-site as a getter * convert `format-currency` to a pure function helper
This commit is contained in:
parent
7107966af6
commit
fe53f2cbc0
@ -1,15 +1,25 @@
|
||||
import Component from "@ember/component";
|
||||
import { LinkTo } from "@ember/routing";
|
||||
import { service } from "@ember/service";
|
||||
import { classNames, tagName } from "@ember-decorators/component";
|
||||
import icon from "discourse/helpers/d-icon";
|
||||
import { i18n } from "discourse-i18n";
|
||||
import userViewingSelf from "../../helpers/user-viewing-self";
|
||||
|
||||
@tagName("li")
|
||||
@classNames("user-main-nav-outlet", "billing")
|
||||
export default class Billing extends Component {
|
||||
@service currentUser;
|
||||
|
||||
get viewingSelf() {
|
||||
return (
|
||||
this.currentUser &&
|
||||
this.currentUser.username.toLowerCase() ===
|
||||
this.model.username.toLowerCase()
|
||||
);
|
||||
}
|
||||
|
||||
<template>
|
||||
{{#if (userViewingSelf this.model)}}
|
||||
{{#if this.viewingSelf}}
|
||||
<LinkTo @route="user.billing">
|
||||
{{icon "far-credit-card"}}
|
||||
{{i18n "discourse_subscriptions.navigation.billing"}}
|
||||
|
@ -1,6 +1,4 @@
|
||||
import { helper } from "@ember/component/helper";
|
||||
|
||||
export function formatCurrency([currency, amount]) {
|
||||
export default function formatCurrency(currency, amount) {
|
||||
let currencySign;
|
||||
|
||||
switch (currency.toUpperCase()) {
|
||||
@ -38,8 +36,6 @@ export function formatCurrency([currency, amount]) {
|
||||
currencySign = "$";
|
||||
}
|
||||
|
||||
let formattedAmount = parseFloat(amount).toFixed(2);
|
||||
const formattedAmount = parseFloat(amount).toFixed(2);
|
||||
return currencySign + formattedAmount;
|
||||
}
|
||||
|
||||
export default helper(formatCurrency);
|
||||
|
@ -1,7 +0,0 @@
|
||||
import Helper from "@ember/component/helper";
|
||||
|
||||
export default Helper.helper(function (params) {
|
||||
const payment = params[0];
|
||||
|
||||
return `<a href=\"${payment.url}\">${payment.payment_intent_id}</a>`;
|
||||
});
|
@ -1,11 +0,0 @@
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export default function userViewingSelf(model) {
|
||||
if (User.current()) {
|
||||
return (
|
||||
User.current().username.toLowerCase() === model.username.toLowerCase()
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
import { setupTest } from "ember-qunit";
|
||||
import { module, test } from "qunit";
|
||||
import { formatCurrency } from "discourse/plugins/discourse-subscriptions/discourse/helpers/format-currency";
|
||||
import formatCurrency from "discourse/plugins/discourse-subscriptions/discourse/helpers/format-currency";
|
||||
|
||||
module("Subscriptions | Unit | Helper | format-currency", function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test("it formats USD correctly", function (assert) {
|
||||
let result = formatCurrency(["USD", 338.2]);
|
||||
test("formats USD correctly", function (assert) {
|
||||
const result = formatCurrency("USD", 338.2);
|
||||
assert.equal(result, "$338.20", "Formats USD correctly");
|
||||
});
|
||||
|
||||
test("it rounds correctly", function (assert) {
|
||||
let result = formatCurrency(["USD", 338.289]);
|
||||
test("rounds correctly", function (assert) {
|
||||
const result = formatCurrency("USD", 338.289);
|
||||
assert.equal(result, "$338.29", "Rounds correctly");
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user