Skip to content

Commit b7de654

Browse files
committed
Purchasing concurrency and quota emails working
1 parent d2c70f1 commit b7de654

File tree

4 files changed

+82
-16
lines changed

4 files changed

+82
-16
lines changed

apps/webapp/app/presenters/v3/ManageConcurrencyPresenter.server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ export class ManageConcurrencyPresenter extends BasePresenter {
117117
extraAllocatedConcurrency: extraAllocated,
118118
extraUnallocatedConcurrency: extraConcurrency - extraAllocated,
119119
maxQuota: currentPlan.v3Subscription.addOns?.concurrentRuns?.quota ?? 0,
120-
environments: sortEnvironments(projectEnvironments).reverse(),
120+
environments: sortEnvironments(projectEnvironments, [
121+
"PRODUCTION",
122+
"STAGING",
123+
"PREVIEW",
124+
"DEVELOPMENT",
125+
]),
121126
concurrencyPricing: plans.addOnPricing.concurrency,
122127
};
123128
}

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.concurrency/route.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,13 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
146146
return json(submission);
147147
}
148148

149-
return redirectWithSuccessMessage(redirectPath, request, "Concurrency updated successfully");
149+
return redirectWithSuccessMessage(
150+
`${redirectPath}?success=true`,
151+
request,
152+
submission.value.action === "purchase"
153+
? "Concurrency updated successfully"
154+
: "Requested extra concurrency, we'll get back to you soon."
155+
);
150156
};
151157

152158
export default function Page() {
@@ -283,13 +289,13 @@ function Upgradable({
283289
<EnvironmentCombo environment={environment} />
284290
</TableCell>
285291
<TableCell alignment="right">{environment.planConcurrencyLimit}</TableCell>
286-
<TableCell alignment="right" className="text-text-bright">
292+
<TableCell alignment="right">
287293
<div className="flex items-center justify-end">
288294
<Input
289295
type="number"
290-
variant="secondary-small"
296+
variant="outline/small"
291297
className="text-right"
292-
containerClassName="w-16 bg-transparent"
298+
containerClassName="w-16"
293299
fullWidth={false}
294300
defaultValue={Math.max(
295301
0,
@@ -381,7 +387,6 @@ function PurchaseConcurrencyModal({
381387

382388
const [amountValue, setAmountValue] = useState(0);
383389
const navigation = useNavigation();
384-
console.log(navigation);
385390
const isLoading = navigation.state !== "idle" && navigation.formMethod === "POST";
386391

387392
const maximum = maxQuota - extraConcurrency;
@@ -422,10 +427,13 @@ function PurchaseConcurrencyModal({
422427
</Fieldset>
423428
{isAboveMaxQuota ? (
424429
<div className="flex flex-col pb-3">
430+
<Paragraph variant="small" className="text-warning" spacing>
431+
Currently you can only have up to {maxQuota} extra concurrency. This request for{" "}
432+
{formatNumber(amountValue)} takes you to{" "}
433+
{formatNumber(extraConcurrency + amountValue)} extra concurrency.
434+
</Paragraph>
425435
<Paragraph variant="small" className="text-warning">
426-
Your Org’s total would be {formatNumber(extraConcurrency + amountValue)}{" "}
427-
concurrency. Send us a request to purchase {formatNumber(amountValue - maximum)}{" "}
428-
more, or reduce the amount to buy more today.
436+
Send a request below to lift your current limit. We'll get back to you soon.
429437
</Paragraph>
430438
</div>
431439
) : (
@@ -466,7 +474,7 @@ function PurchaseConcurrencyModal({
466474
type="submit"
467475
disabled={isLoading}
468476
>
469-
{`Send request for ${formatNumber(amountValue - maximum)}`}
477+
{`Send request for ${formatNumber(extraConcurrency + amountValue)}`}
470478
</Button>
471479
</>
472480
) : (

apps/webapp/app/utils/environmentSort.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ type SortType = {
1212
userName?: string | null;
1313
};
1414

15-
export function sortEnvironments<T extends SortType>(environments: T[]): T[] {
15+
export function sortEnvironments<T extends SortType>(
16+
environments: T[],
17+
sortOrder?: RuntimeEnvironmentType[]
18+
): T[] {
19+
const order = sortOrder ?? environmentSortOrder;
1620
return environments.sort((a, b) => {
17-
const aIndex = environmentSortOrder.indexOf(a.type);
18-
const bIndex = environmentSortOrder.indexOf(b.type);
21+
const aIndex = order.indexOf(a.type);
22+
const bIndex = order.indexOf(b.type);
1923

2024
const difference = aIndex - bIndex;
2125

apps/webapp/app/v3/services/setConcurrencyAddOn.server.ts

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { BaseService } from "./baseService.server";
33
import { tryCatch } from "@trigger.dev/core";
44
import { setConcurrencyAddOn } from "~/services/platform.v3.server";
55
import assertNever from "assert-never";
6+
import { sendToPlain } from "~/utils/plain.server";
7+
import { uiComponent } from "@team-plain/typescript-sdk";
68

79
type Input = {
810
userId: string;
@@ -80,11 +82,58 @@ export class SetConcurrencyAddOnService extends BaseService {
8082
}
8183
}
8284
case "quota-increase": {
85+
const user = await this._replica.user.findFirst({
86+
where: { id: userId },
87+
});
88+
89+
if (!user) {
90+
return {
91+
success: false,
92+
error: "No matching user found.",
93+
};
94+
}
95+
96+
const organization = await this._replica.organization.findFirst({
97+
select: {
98+
title: true,
99+
},
100+
where: { id: organizationId },
101+
});
102+
103+
const [error, result] = await tryCatch(
104+
sendToPlain({
105+
userId,
106+
email: user.email,
107+
name: user.name ?? user.displayName ?? user.email,
108+
title: `Concurrency quota request: ${totalExtraConcurrency}`,
109+
components: [
110+
uiComponent.text({
111+
text: `Org: ${organization?.title} (${organizationId})`,
112+
}),
113+
uiComponent.divider({ spacingSize: "M" }),
114+
uiComponent.text({
115+
text: `Total concurrency (set this): ${totalExtraConcurrency}`,
116+
}),
117+
uiComponent.text({
118+
text: `Current extra concurrency: ${currentConcurrency}`,
119+
}),
120+
uiComponent.text({
121+
text: `Amount requested: ${amount}`,
122+
}),
123+
],
124+
})
125+
);
126+
127+
if (error) {
128+
return {
129+
success: false,
130+
error: error.message,
131+
};
132+
}
133+
83134
return {
84-
success: false,
85-
error: "Quota increase is not supported yet.",
135+
success: true,
86136
};
87-
break;
88137
}
89138
default: {
90139
assertNever(action);

0 commit comments

Comments
 (0)