diff --git a/app/frontend/src/javascript/components/dashboard/reservations/credits-panel.tsx b/app/frontend/src/javascript/components/dashboard/reservations/credits-panel.tsx index a60d68e77..4f888c4e5 100644 --- a/app/frontend/src/javascript/components/dashboard/reservations/credits-panel.tsx +++ b/app/frontend/src/javascript/components/dashboard/reservations/credits-panel.tsx @@ -30,14 +30,7 @@ const CreditsPanel: React.FC = ({ 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 = ({ userId, onError, reservable
    {credits.map(c =>
  • - +
  • )} {credits.length === 0 && noCredits()}
diff --git a/app/frontend/src/javascript/models/credit.ts b/app/frontend/src/javascript/models/credit.ts index cc45fb937..5a2b54775 100644 --- a/app/frontend/src/javascript/models/credit.ts +++ b/app/frontend/src/javascript/models/credit.ts @@ -14,9 +14,5 @@ export interface Credit { id: number, name: string }, - used_credits?: [{ - id: number, - created_at: TDateISO, - hours_used: number - }] + hours_used?: number } diff --git a/app/views/api/credits/user_resource.json.jbuilder b/app/views/api/credits/user_resource.json.jbuilder index cc1e590a6..00aa695c7 100644 --- a/app/views/api/credits/user_resource.json.jbuilder +++ b/app/views/api/credits/user_resource.json.jbuilder @@ -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 diff --git a/config/locales/app.logged.en.yml b/config/locales/app.logged.en.yml index 95718babd..0922ef0a4 100644 --- a/config/locales/app.logged.en.yml +++ b/config/locales/app.logged.en.yml @@ -154,8 +154,8 @@ en: credits_panel: title_Space: "My space credits" title_Machine: "My machines credits" - reamaining_credits_html: "{NAME}: You can book {REMAINING} slots for free. You have already used {USED} credits." - no_credits: "No credits" + reamaining_credits_html: "{NAME}: You can book {REMAINING} {REMAINING, plural, one{slot} other{slots}} 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"