1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-30 19:52:20 +01:00

(bug) wrong number of credits + improved text

This commit is contained in:
Sylvain 2022-06-29 15:33:28 +02:00
parent 1b8282fda4
commit a41a22a050
4 changed files with 6 additions and 19 deletions

View File

@ -30,14 +30,7 @@ const CreditsPanel: React.FC<CreditsPanelProps> = ({ userId, onError, reservable
* Compute the remainings hours for the given credit
*/
const remainingHours = (credit: Credit): number => {
return credit.hours - usedHours(credit);
};
/**
* Compute the used credits hours for the given credit
*/
const usedHours = (credit: Credit): number => {
return credit.used_credits.map(uc => uc.hours_used).reduce((acc, val) => acc + val, 0);
return credit.hours - credit.hours_used;
};
/**
@ -64,7 +57,7 @@ const CreditsPanel: React.FC<CreditsPanelProps> = ({ userId, onError, reservable
<FabPanel className="credits-panel" header={header()}>
<ul>
{credits.map(c => <li key={c.id}>
<HtmlTranslate trKey="app.logged.dashboard.reservations.credits_panel.reamaining_credits_html" options={{ NAME: c.creditable.name, REMAINING: remainingHours(c), USED: usedHours(c) }} />
<HtmlTranslate trKey="app.logged.dashboard.reservations.credits_panel.reamaining_credits_html" options={{ NAME: c.creditable.name, REMAINING: remainingHours(c), USED: c.hours_used }} />
</li>)}
{credits.length === 0 && noCredits()}
</ul>

View File

@ -14,9 +14,5 @@ export interface Credit {
id: number,
name: string
},
used_credits?: [{
id: number,
created_at: TDateISO,
hours_used: number
}]
hours_used?: number
}

View File

@ -2,7 +2,5 @@
json.array!(@credits) do |credit|
json.partial! 'api/credits/credit', credit: credit
json.used_credits credit.users_credits do |uc|
json.extract! uc, :id, :created_at, :hours_used
end
json.hours_used credit.users_credits.find_by(user_id: @user.id)&.hours_used
end

View File

@ -154,8 +154,8 @@ en:
credits_panel:
title_Space: "My space credits"
title_Machine: "My machines credits"
reamaining_credits_html: "<strong>{NAME}</strong>: You can book <em>{REMAINING}</em> slots for free. You have already used {USED} credits."
no_credits: "No credits"
reamaining_credits_html: "<strong>{NAME}</strong>: You can book <em>{REMAINING} {REMAINING, plural, one{slot} other{slots}}</em> for free. You have already used {USED} {USED, plural, one{credit} other{credits}} for your current subscription."
no_credits: "You don't have any credits yet. Some subscriptions may allow you to book some slots free."
#public profil of a member
members_show:
members_list: "Members list"