From 3841fb06ebe1e09250362cc6cb401fdca12eef7f Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Wed, 30 Jun 2021 11:16:40 -0400 Subject: [PATCH] fix(ui): do not display negative remaining quota (#1859) * fix(ui): do not display negative remaining quota * fix: correct remaining quota count on API side --- server/entity/User.ts | 6 +++-- .../RequestModal/QuotaDisplay/index.tsx | 12 ++++------ src/components/UserProfile/index.tsx | 22 +++++++------------ 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/server/entity/User.ts b/server/entity/User.ts index ed6fc4a6b..766ef76f0 100644 --- a/server/entity/User.ts +++ b/server/entity/User.ts @@ -307,7 +307,7 @@ export class User { limit: movieQuotaLimit, used: movieQuotaUsed, remaining: movieQuotaLimit - ? movieQuotaLimit - movieQuotaUsed + ? Math.max(0, movieQuotaLimit - movieQuotaUsed) : undefined, restricted: movieQuotaLimit && movieQuotaLimit - movieQuotaUsed <= 0 @@ -318,7 +318,9 @@ export class User { days: tvQuotaDays, limit: tvQuotaLimit, used: tvQuotaUsed, - remaining: tvQuotaLimit ? tvQuotaLimit - tvQuotaUsed : undefined, + remaining: tvQuotaLimit + ? Math.max(0, tvQuotaLimit - tvQuotaUsed) + : undefined, restricted: tvQuotaLimit && tvQuotaLimit - tvQuotaUsed <= 0 ? true : false, }, diff --git a/src/components/RequestModal/QuotaDisplay/index.tsx b/src/components/RequestModal/QuotaDisplay/index.tsx index 223540d5d..a044f954f 100644 --- a/src/components/RequestModal/QuotaDisplay/index.tsx +++ b/src/components/RequestModal/QuotaDisplay/index.tsx @@ -59,18 +59,14 @@ const QuotaDisplay: React.FC = ({
= ({ {overLimit !== undefined ? intl.formatMessage(messages.notenoughseasonrequests) : intl.formatMessage(messages.requestsremaining, { - remaining: Math.max(0, remaining ?? quota?.remaining ?? 0), + remaining: remaining ?? quota?.remaining ?? 0, type: intl.formatMessage( mediaType === 'movie' ? messages.movie : messages.season ), diff --git a/src/components/UserProfile/index.tsx b/src/components/UserProfile/index.tsx index 80131ae49..926455330 100644 --- a/src/components/UserProfile/index.tsx +++ b/src/components/UserProfile/index.tsx @@ -134,13 +134,10 @@ const UserProfile: React.FC = () => { {quota.movie.limit ? ( <> { {quota.tv.limit ? ( <>