Skip to content

Commit

Permalink
Rework subscriptions display in Profile (#6089)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementPasteau committed Dec 15, 2023
1 parent 32a3a09 commit a1826d3
Show file tree
Hide file tree
Showing 26 changed files with 2,573 additions and 228 deletions.
16 changes: 6 additions & 10 deletions newIDE/app/src/ExportAndShare/ShareDialog/ExportLauncher.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
displayProjectErrorsBox,
getProjectPropertiesErrors,
} from '../../Utils/ProjectErrorsChecker';
import { type CurrentUsage } from '../../Utils/GDevelopServices/Usage';
import { type Quota } from '../../Utils/GDevelopServices/Usage';
import BuildsWatcher from '../Builds/BuildsWatcher';
import BuildStepsProgress, {
type BuildStep,
Expand Down Expand Up @@ -410,18 +410,14 @@ export default class ExportLauncher extends Component<Props, State> {
isSavingProject,
} = this.props;
if (!project) return null;
const getBuildCurrentUsage = (
authenticatedUser: AuthenticatedUser
): ?CurrentUsage =>
const getBuildQuota = (authenticatedUser: AuthenticatedUser): ?Quota =>
authenticatedUser.limits && exportPipeline.onlineBuildType
? authenticatedUser.limits.limits[exportPipeline.onlineBuildType]
? authenticatedUser.limits.quotas[exportPipeline.onlineBuildType]
: null;

const canLaunchBuild = (authenticatedUser: AuthenticatedUser) => {
const currentUsage: ?CurrentUsage = getBuildCurrentUsage(
authenticatedUser
);
if (currentUsage && currentUsage.limitReached) return false;
const quota: ?Quota = getBuildQuota(authenticatedUser);
if (quota && quota.limitReached) return false;

return exportPipeline.canLaunchBuild(exportState, errored, exportStep);
};
Expand Down Expand Up @@ -511,7 +507,7 @@ export default class ExportLauncher extends Component<Props, State> {
authenticatedUser.authenticated && (
<CurrentUsageDisplayer
subscription={authenticatedUser.subscription}
currentUsage={getBuildCurrentUsage(authenticatedUser)}
quota={getBuildQuota(authenticatedUser)}
onChangeSubscription={this.props.onChangeSubscription}
/>
)}
Expand Down
4 changes: 3 additions & 1 deletion newIDE/app/src/GameDashboard/LeaderboardAdmin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,9 @@ export const LeaderboardAdmin = ({
<MaxLeaderboardCountAlertMessage
onUpgrade={() =>
openSubscriptionDialog({
reason: 'Leaderboard count per game limit reached',
analyticsMetadata: {
reason: 'Leaderboard count per game limit reached',
},
})
}
onClose={() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ const BuildSection = ({
limits={limits}
onUpgrade={() =>
openSubscriptionDialog({
reason: 'Cloud Project limit reached',
analyticsMetadata: {
reason: 'Cloud Project limit reached',
},
})
}
/>
Expand Down
20 changes: 10 additions & 10 deletions newIDE/app/src/Profile/CurrentUsageDisplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Trans } from '@lingui/macro';
import * as React from 'react';
import {
hasValidSubscriptionPlan,
type CurrentUsage,
type Quota,
type Subscription,
} from '../Utils/GDevelopServices/Usage';
import PlaceholderLoader from '../UI/PlaceholderLoader';
Expand All @@ -15,30 +15,30 @@ import { ColumnStackLayout } from '../UI/Layout';

type Props = {|
subscription: ?Subscription,
currentUsage: ?CurrentUsage,
quota: ?Quota,
onChangeSubscription: () => void,
|};

const CurrentUsageDisplayer = ({
subscription,
currentUsage,
quota,
onChangeSubscription,
}: Props) => {
if (!currentUsage) return <PlaceholderLoader />;
if (!quota) return <PlaceholderLoader />;
const hasSubscription = hasValidSubscriptionPlan(subscription);
const loadedButHasNoSubscription =
subscription && !hasValidSubscriptionPlan(subscription);
const remainingBuilds = Math.max(currentUsage.max - currentUsage.current, 0);
const remainingBuilds = Math.max(quota.max - quota.current, 0);
const remainingMultipleMessage = (
<Trans>
You have {remainingBuilds} builds remaining (You have used{' '}
{currentUsage.current}/{currentUsage.max} in the last 24h).
You have {remainingBuilds} builds remaining (You have used {quota.current}
/{quota.max} in the last 24h).
</Trans>
);
const remainingSingleMessage = (
<Trans>
You have {remainingBuilds} build remaining (You have used{' '}
{currentUsage.current}/{currentUsage.max} in the last 24h).
You have {remainingBuilds} build remaining (You have used {quota.current}/
{quota.max} in the last 24h).
</Trans>
);

Expand All @@ -51,7 +51,7 @@ const CurrentUsageDisplayer = ({
: remainingMultipleMessage}
</Text>
</AlertMessage>
{hasSubscription && currentUsage.limitReached && (
{hasSubscription && quota.limitReached && (
<GetSubscriptionCard subscriptionDialogOpeningReason="Build limit reached">
<Text>
<Trans>
Expand Down
4 changes: 3 additions & 1 deletion newIDE/app/src/Profile/Subscription/GetSubscriptionCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ const GetSubscriptionCard = (props: Props) => {
href="#"
onClick={() => {
openSubscriptionDialog({
reason: props.subscriptionDialogOpeningReason,
analyticsMetadata: {
reason: props.subscriptionDialogOpeningReason,
},
});
}}
>
Expand Down
Loading

0 comments on commit a1826d3

Please sign in to comment.