From 4f81496d686afd33f72cf4a936b17328843627ea Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Wed, 13 Dec 2023 11:49:25 -0500 Subject: [PATCH] Makes uploadOptions responsive to user premium status --- src/api/fixtures/orgAndUser.fixtures.js | 28 +++ src/common/UploadOptions.svelte | 162 ++++++++++++------ .../stories/UploadOptions.stories.svelte | 27 ++- src/langs/json/en.json | 5 +- src/manager/orgsAndUsers.js | 15 +- src/pages/app/accounts/stories/mockData.ts | 20 +++ 6 files changed, 194 insertions(+), 63 deletions(-) diff --git a/src/api/fixtures/orgAndUser.fixtures.js b/src/api/fixtures/orgAndUser.fixtures.js index 80e3db25e..387c24afe 100644 --- a/src/api/fixtures/orgAndUser.fixtures.js +++ b/src/api/fixtures/orgAndUser.fixtures.js @@ -205,3 +205,31 @@ export const organization = { monthly_credit_allowance: 5000, plan: "Organization", }; + +export const proOrg = { + id: 4, + avatar_url: + "https://cdn.muckrock.com/media/account_images/allan-headshot-2016.jpg", + individual: true, + name: "lasser.allan", + slug: "lasserallan", + monthly_credits: 2500, + purchased_credits: 3000, + credit_reset_date: "2023-11-28", + monthly_credit_allowance: 2500, + plan: "Professional", +}; + +export const freeOrg = { + id: 4, + avatar_url: + "https://cdn.muckrock.com/media/account_images/allan-headshot-2016.jpg", + individual: true, + name: "lasser.allan", + slug: "lasserallan", + monthly_credits: 0, + purchased_credits: 0, + credit_reset_date: "2023-11-28", + monthly_credit_allowance: 0, + plan: "Free", +}; diff --git a/src/common/UploadOptions.svelte b/src/common/UploadOptions.svelte index 8a1f00237..73b494feb 100644 --- a/src/common/UploadOptions.svelte +++ b/src/common/UploadOptions.svelte @@ -9,10 +9,16 @@ import type { Org, User } from "../pages/app/accounts/types.js"; import { getMe, getOrganization } from "../api/orgAndUser.js"; import { onMount } from "svelte"; + import { + getUpgradeURL, + isOrgAdmin, + isPremiumOrg, + } from "../manager/orgsAndUsers.js"; + import PremiumBadge from "../premium-credits/PremiumBadge.svelte"; export let language = defaultLanguage; export let forceOcr = false; - export let ocrEngine = "tess4"; + export let ocrEngine: "tess4" | "textract" = "tess4"; export let revisionControl = false; let languageName = defaultLanguageName(languages); @@ -23,25 +29,31 @@ async function getUser() { try { user = await getMe(); - const activeOrg = user?.organization; + } catch (e) { + user = null; + console.error("Error setting User: ", JSON.stringify(e, null, 2)); + } + try { + let activeOrg = user?.organization; if (typeof activeOrg === "string") { - org = await getOrganization(activeOrg); + org = (await getOrganization(activeOrg)) as Org; } else { org = activeOrg; } } catch (e) { - user = null; + org = null; + console.error("Error setting Org: ", JSON.stringify(e, null, 2)); } } - $: hasTextract = user?.feature_level > 0; $: selectLanguages = ocrEngine === "textract" ? textractLanguages : languages; + $: hasTextract = isPremiumOrg(org); // value, name, disabled - type OCREngine = [string, string, boolean]; + type OCREngine = [value: string, name: string, isPremium: boolean]; const ocrEngines: OCREngine[] = [ ["tess4", "Tesseract", false], - ["textract", "Textract", !hasTextract], + ["textract", "Textract", true], ]; function defaultLanguageName(languages) { @@ -59,42 +71,55 @@ }); -
- - {#each ocrEngines as [value, name, disabled]} - - {/each} - - - +{#await getUserPromise then} +
+ + {#each ocrEngines as [value, name, isPremium]} + + {/each} + + + +
+ +
+

{@html $_("uploadOptions.tesseract")}

- {@html $_("uploadOptions.textract")} + {@html $_("uploadOptions.textract")} + {#if !isPremiumOrg(org)} + {#if isOrgAdmin(user)} + {@html $_("uploadOptions.premiumToutAdmin", { + values: { upgradeUrl: getUpgradeURL(org) }, + })} + {:else} + {@html $_("uploadOptions.premiumToutMember")} + {/if} + {/if}

-

{@html $_("uploadOptions.premiumTout")}

- {:else} - {#await getUserPromise then} + {#if isPremiumOrg(org) && ocrEngine == "textract"}

{$_("uploadOptions.creditHelpText", { values: { @@ -103,21 +128,46 @@ }, })}

- {/await} - {/if} + {/if} +
- - -
-
- -

{$_("uploadOptions.revisionControlHelp")}

-

{@html $_("uploadOptions.premiumTout")}

+ +
+
+
+
+ +

+ {$_("uploadOptions.revisionControlHelp")} +

+
+ +
+ {#if !isPremiumOrg(org)} +

+ {#if isOrgAdmin(user)} + {@html $_("uploadOptions.premiumToutAdmin", { + values: { upgradeUrl: getUpgradeURL(org) }, + })} + {:else} + {@html $_("uploadOptions.premiumToutMember")} + {/if} +

+ {/if} +
-
+{/await}