Skip to content

Commit

Permalink
Upgrade tier
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Jan 20, 2025
1 parent 7d5d0e9 commit 23b0bd7
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 46 deletions.
2 changes: 1 addition & 1 deletion apps/web/src/lib/tiers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const TIERS_MAX_KEYS = {
0: 100,
1: 10000,
1: 1000,
2: 20000,
3: 30000,
4: 50000,
Expand Down
15 changes: 10 additions & 5 deletions apps/web/src/trpc/routers/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,19 @@ export const jobsRouter = createTRPCRouter({
TIERS_MAX_KEYS[org.tier as keyof typeof TIERS_MAX_KEYS];

if (nextTotalKeys >= currentKeysLimit) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "You have reached the maximum number of keys",
cause: {
return {
meta: {
plan: org.plan,
tier: org.tier,
organizationId: org.id,
},
error: {
code: "LIMIT_REACHED",
message: "You have reached the maximum number of keys",
currentKeysLimit,
nextTotalKeys,
},
});
};
}

const options = isFreeUser
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/yaml/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ user:
cancel: Cancelar
errors:
not_found: Página no encontrada
server_error: Ocurrió un error en el servidor
server_error: Se produjo un error en el servidor
validation:
required: Este campo es obligatorio
email: Por favor, introduce una dirección de correo electrónico válida
Expand Down
4 changes: 2 additions & 2 deletions examples/yaml/locales/fr.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
welcome: Bienvenue dans notre application !
goodbye: Merci d'utiliser notre application. À la prochaine !
goodbye: Merci d'utiliser notre application. À bientôt !
nav:
home: Accueil
about: À propos
Expand All @@ -18,7 +18,7 @@ errors:
validation:
required: Ce champ est obligatoire
email: Veuillez entrer une adresse e-mail valide
password: Le mot de passe doit comporter au moins 8 caractères
password: Le mot de passe doit contenir au moins 8 caractères
form:
email: Adresse e-mail
password: Mot de passe
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"clean": "git clean -xdf node_modules",
"clean:workspaces": "turbo clean",
"dev": "turbo dev --parallel",
"test": "vitest",
"format": "biome format --write .",
"lint": "turbo lint && manypkg check",
"typecheck": "turbo typecheck"
Expand All @@ -19,10 +18,9 @@
"@biomejs/biome": "^1.9.4",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.11",
"@types/bun": "^1.1.16",
"@types/node": "^22.10.6",
"@types/bun": "^1.1.17",
"@types/node": "^22.10.7",
"turbo": "2.3.3",
"typescript": "^5.7.3",
"vitest": "^2.1.8"
"typescript": "^5.7.3"
}
}
90 changes: 58 additions & 32 deletions packages/cli/src/commands/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import type { Config } from "@/types.js";
import { client } from "@/utils/api.js";
import { loadConfig } from "@/utils/config.ts";
import { getDiff } from "@/utils/diff.js";
import { loadEnv } from "@/utils/env.ts";
import { getGitInfo } from "@/utils/git.ts";
import { getAPIKey } from "@/utils/session.ts";
import { confirm, note, outro, select, spinner } from "@clack/prompts";
import { auth, runs } from "@trigger.dev/sdk/v3";
import { TRPCClientError } from "@trpc/client";
import { TRPCError } from "@trpc/server";
import chalk from "chalk";
import glob from "fast-glob";
import open from "open";
import { z } from "zod";

const { BASE_URL } = loadEnv();

const argsSchema = z.array(z.string()).transform((args) => {
const forceIndex = args.indexOf("--force");

Expand Down Expand Up @@ -145,6 +147,7 @@ export async function translateCommand(args: string[] = []) {
);
}
}

continue;
}
}
Expand Down Expand Up @@ -178,11 +181,8 @@ export async function translateCommand(args: string[] = []) {
}

let result: TranslationResult;
// let meta: { isFreeUser: boolean };
// let run: any;

// try {
const { run, meta } = await client.jobs.startJob.mutate({
const { error, run, meta } = await client.jobs.startJob.mutate({
apiKey: apiKey,
projectId,
sourceFormat: type,
Expand All @@ -195,34 +195,60 @@ export async function translateCommand(args: string[] = []) {
commitMessage: gitInfo?.commitMessage,
commitLink: gitInfo?.commitLink,
});
// } catch (error) {
// if (error instanceof TRPCClientError) {
// note(
// "Translation limit reached. Upgrade your plan to increase your limit.",
// "Error",
// );

// const shouldUpgrade = await select({
// message: "Would you like to upgrade your plan now?",
// options: [
// { label: "Upgrade plan", value: "upgrade" },
// { label: "Cancel", value: "cancel" },
// ],
// });

// // if (shouldUpgrade === "upgrade") {
// // // Open upgrade URL in browser
// // await open("https://languine.ai/pricing");
// // }

// process.exit(1);
// }
// }

if (!isSilent && meta.plan === "free") {

if (error?.code === "LIMIT_REACHED") {
s.stop();
note(
"Translation limit reached. Upgrade your plan to increase your limit.",
"Limit reached",
);

const shouldUpgrade = await select({
message: "Would you like to upgrade your plan now?",
options: [
{ label: "Upgrade plan", value: "upgrade" },
{ label: "Cancel", value: "cancel" },
],
});

if (shouldUpgrade === "upgrade") {
// Open upgrade URL in browser
if (meta?.plan === "free") {
await open(
`${BASE_URL}/${meta?.organizationId}/default/settings?tab=billing&referrer=cli`,
);
} else {
s.start("Upgrading plan...");

// Just upgrade the plan
await client.organization.updatePlan.mutate({
organizationId: meta?.organizationId,
tier: meta?.tier + 1,
});

s.stop(chalk.green("Plan upgraded successfully"));

note(
"Run `languine translate` again to continue.",
"What's next?",
);
}
}

process.exit(1);
}

if (!run) {
s.stop();
note("Translation job not found", "Error");
process.exit(1);
}

// If in queue, show a pro tip
if (!isSilent && meta?.plan === "free") {
if (!checkOnly) {
note(
"Upgrade to Pro for priority queue access at https://languine.ai/pricing",
"Upgrade to Pro for faster translations https://languine.ai/pricing",
"Pro tip",
);
}
Expand Down

0 comments on commit 23b0bd7

Please sign in to comment.