-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add alert message in the FE when exceeded the API usage #4027
Changes from 4 commits
ace2cb9
c51dcc0
ebf5de9
3f2135f
839a468
d11bb99
f6eaef3
0394765
9c2058f
5b18484
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -34,6 +34,16 @@ export default class ErrorMessage extends PureComponent { | |||||||||||||||||||||||||||||||||||||
.join('<br/>'), | ||||||||||||||||||||||||||||||||||||||
}} | ||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||
) : this.props.exceeded ? ( | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't pollute generic components. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New component Created |
||||||||||||||||||||||||||||||||||||||
<> | ||||||||||||||||||||||||||||||||||||||
Your organisation has exceeded its API usage quota{' '} | ||||||||||||||||||||||||||||||||||||||
<b>{`(${error}).`}</b>{' '} | ||||||||||||||||||||||||||||||||||||||
{Utils.getPlanName(this.props.organisationPlan) === 'Free' ? ( | ||||||||||||||||||||||||||||||||||||||
<b>Please upgrade your plan to continue receiving service.</b> | ||||||||||||||||||||||||||||||||||||||
) : ( | ||||||||||||||||||||||||||||||||||||||
<b>Automated billing for the overages may apply.</b> | ||||||||||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||||||||||
</> | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bolding of the error amount looks weird because the end of the sentence extends into the next one. I recommend doing it like this:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||||||||||||||||||||||||||||||||
) : ( | ||||||||||||||||||||||||||||||||||||||
error | ||||||||||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,27 +8,33 @@ import { useGetOrganisationUsageQuery } from 'common/services/useOrganisationUsa | |
|
||
type OrganisationLimitType = { | ||
id: string | ||
organisationPlan: string | ||
} | ||
|
||
const OrganisationLimit: FC<OrganisationLimitType> = ({ id }) => { | ||
const { data: totalApiCalls } = useGetOrganisationUsageQuery( | ||
{ | ||
organisationId: id, | ||
}, | ||
{ skip: !id }, | ||
) | ||
const OrganisationLimit: FC<OrganisationLimitType> = ({ | ||
id, | ||
organisationPlan, | ||
}) => { | ||
let body = { organisationId: id } | ||
if (Utils.getPlanName(organisationPlan) !== 'free') { | ||
body = { ...body, ...{ period: 'current_billing_period' } } | ||
} | ||
|
||
const { data: totalApiCalls } = useGetOrganisationUsageQuery(body, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can’t this just go into the new component ? It may as well be just self contained / can be added anywhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not quite sure I understand your suggestion. Are you suggesting using this hook in the new QuotaExceededMessagecomponent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes or just move the QuotaExceededMessagecomponent to this, it doesn't look like it's necessary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
skip: !id, | ||
}) | ||
const { data: maxApiCalls } = useGetSubscriptionMetadataQuery({ id }) | ||
const maxApiCallsPercentage = Utils.calculateRemainingLimitsPercentage( | ||
totalApiCalls?.totals.total, | ||
maxApiCalls?.max_api_calls, | ||
70, | ||
).percentage | ||
|
||
const alertMaxApiCallsText = `You have used ${Format.shortenNumber( | ||
const errorMessageText = `${Format.shortenNumber( | ||
totalApiCalls?.totals.total, | ||
)}/${Format.shortenNumber( | ||
maxApiCalls?.max_api_calls, | ||
)} of your allowed requests.` | ||
)}/${Format.shortenNumber(maxApiCalls?.max_api_calls)}` | ||
|
||
const alertMaxApiCallsText = `You have used ${errorMessageText} of your allowed requests.` | ||
|
||
return ( | ||
<Row> | ||
|
@@ -43,9 +49,11 @@ const OrganisationLimit: FC<OrganisationLimitType> = ({ id }) => { | |
) : ( | ||
maxApiCallsPercentage >= 100 && ( | ||
<ErrorMessage | ||
error={alertMaxApiCallsText} | ||
error={errorMessageText} | ||
organisationPlan={organisationPlan} | ||
errorMessageClass={'announcement'} | ||
enabledButton | ||
exceeded | ||
/> | ||
) | ||
))} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type should be more specific
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done