Skip to content

Commit

Permalink
use credit cost for premium addons if it is set to more than 1
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelljkotler committed Nov 29, 2023
1 parent 45157eb commit 77dd08b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/addons/dispatch/Premium.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
$: isIndividualOrg =
typeof user?.organization !== "string" && user?.organization?.individual;
$: isPremium = addon?.parameters?.categories?.includes("premium") ?? false;
const { amount, unit } = addon?.parameters?.cost ?? {};
$: prettyCost = amount && unit ? handlePlural(amount, unit) : null;
const { amount, unit, cost } = addon?.parameters?.cost ?? {};
function toggleSpendingLimit(
event: Event & { currentTarget: HTMLInputElement },
Expand Down Expand Up @@ -151,9 +150,11 @@
<legend>{$_("addonDispatchDialog.premium")}</legend>
<div class="row">
<div class="column">
{#if prettyCost}
{#if amount}
<h3 class="prettyCost">
{prettyCost} per credit
{$_("addonDispatchDialog.cost", {
values: { amount: amount, unit: unit, cost: cost || 1},
})}
</h3>
{/if}
<!-- TODO: Support spend limit (#343)
Expand Down
8 changes: 8 additions & 0 deletions src/addons/dispatch/stories/Premium.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,11 @@
user: { ...user, organization: { ...groupOrg, monthly_credits: 0 } },
}}
/>
<Story
name="Azure"
args={{ addon: addons[8], user: { ...user, organization: individualOrg } }}
/>
<Story
name="GPT"
args={{ addon: addons[9], user: { ...user, organization: individualOrg } }}
/>
7 changes: 4 additions & 3 deletions src/addons/fixtures/addons.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
"documents": ["selected"],
"cost": {
"amount": 150,
"unit": "character"
"unit": "characters"
},
"categories": ["ai", "premium", "file"],
"properties": {
Expand Down Expand Up @@ -601,8 +601,9 @@
"title": "Diakopoulos GPT-3 Example: Classifying Comments Based on Subject",
"documents": ["query", "selected"],
"cost": {
"unit": "token",
"amount": 150
"unit": "document",
"amount": 1,
"cost": 14
},
"categories": ["ai", "premium"],
"properties": {
Expand Down
4 changes: 3 additions & 1 deletion src/langs/json/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@
"runSuccess": "Add-on is now running",
"selectionHelp": "From the main list, select individual documents or run a search for the documents you want, for example “+project:mueller-docs-200005”.",
"selectionLearnMore": "Learn more about how Add-Ons work",
"cost": "{amount} {unit} per {cost, plural, one {credit} other {# credits}}",
"premiumUpgrade": {
"message": "This Premium Add-On uses AI to perform advanced analysis. Upgrade to a {plan} account to utilize this and other powerful Add-Ons.",
"callToAction": "Upgrade Plan",
Expand Down Expand Up @@ -828,5 +829,6 @@
"p3": "Want more fascinating documents, open data and original reporting to your inbox? Subscribe to MuckRock's newsletter:",
"p4": "DocumentCloud is part of a suite of transparency tools from the MuckRock Foundation, a 501c3 registered non-profit. This archive is open to the public and advertisement free thanks to support from readers like you — you can <a href=\"https://www.muckrock.com/about/\">learn more about our work</a> or <a href=\"https://www.muckrock.com/donate/\">make a donation</a>.",
"subscribe": "Subscribe"
}
},
"premium": {}
}

0 comments on commit 77dd08b

Please sign in to comment.