mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-19 08:05:20 +00:00
credits UI refill (#814)
This commit is contained in:
1 parent
4c1d1007a2
commit
77614e06d9
8 files changed
+308
-62
No files matched your search
@@ -8,6 +8,7 @@ import {
|
||||
faImage,
|
||||
faPenNib,
|
||||
faGem,
|
||||
faCoinFront,
|
||||
} from "@fortawesome/pro-solid-svg-icons";
|
||||
import {
|
||||
faWindowRestore,
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
faDash,
|
||||
} from "@fortawesome/pro-regular-svg-icons";
|
||||
import { Button } from "@storyteller/ui-button";
|
||||
import { PopoverMenu } from "@storyteller/ui-popover";
|
||||
import { AuthButtons } from "./AuthButtons";
|
||||
import { SceneTitleInput } from "./SceneTitleInput";
|
||||
import { Activity } from "~/pages/PageEnigma/comps/GenerateModals/Activity";
|
||||
@@ -52,8 +54,10 @@ import { useEditStore } from "../../../pages/PageEdit/stores/EditState";
|
||||
import { BaseSelectorImage } from "../../../pages/PageEdit/BaseImageSelector";
|
||||
import { ProviderSetupModal } from "@storyteller/provider-setup-modal";
|
||||
import { ProviderBillingModal } from "@storyteller/provider-billing-modal";
|
||||
import { usePricingModalStore } from "@storyteller/ui-pricing-modal";
|
||||
// import { ProgressCircle } from "@storyteller/ui-progress"; // Uncomment this for Credits indicator - BFlat
|
||||
import {
|
||||
usePricingModalStore,
|
||||
useCreditsModalStore,
|
||||
} from "@storyteller/ui-pricing-modal";
|
||||
|
||||
interface Props {
|
||||
pageName: string;
|
||||
@@ -119,16 +123,6 @@ export const TopBar = ({ pageName, loginSignUpPressed }: Props) => {
|
||||
const [settingsSection, setSettingsSection] =
|
||||
useState<SettingsSection>("general");
|
||||
|
||||
// Credit state (replace with real data fetch)
|
||||
const [credits, setCredits] = useState({
|
||||
used: 800,
|
||||
total: 1000,
|
||||
});
|
||||
|
||||
const creditsRemaining = credits.total - credits.used;
|
||||
const creditsRemainingPercentage = (creditsRemaining / credits.total) * 100;
|
||||
const isLowCredit = creditsRemainingPercentage < 20; // Less than 20% credits remaining
|
||||
|
||||
const { isDesktop, isMaximized, minimize, toggleMaximize, close } =
|
||||
useTauriWindowControls();
|
||||
const platform = useTauriPlatform();
|
||||
@@ -225,6 +219,7 @@ export const TopBar = ({ pageName, loginSignUpPressed }: Props) => {
|
||||
const pageTitle = getPageTitle();
|
||||
|
||||
const { toggleModal } = usePricingModalStore();
|
||||
const { toggleModal: toggleCreditsModal } = useCreditsModalStore();
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -294,27 +289,72 @@ export const TopBar = ({ pageName, loginSignUpPressed }: Props) => {
|
||||
|
||||
<div className="flex justify-end gap-2" data-tauri-drag-region>
|
||||
<div className="no-drag flex items-center gap-1.5">
|
||||
{/* Uncomment this for Credits indicator - BFlat */}
|
||||
{/* <Tooltip
|
||||
content={`${creditsRemaining}/${credits.total} credits remaining`}
|
||||
<PopoverMenu
|
||||
position="bottom"
|
||||
delay={300}
|
||||
>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="h-[30px] px-2 ps-1.5"
|
||||
onClick={handleOpenBillingSettings}
|
||||
>
|
||||
<ProgressCircle
|
||||
value={creditsRemainingPercentage}
|
||||
isLow={isLowCredit}
|
||||
size="small"
|
||||
align="center"
|
||||
triggerIcon={
|
||||
<FontAwesomeIcon
|
||||
icon={faCoinFront}
|
||||
className="text-primary"
|
||||
/>
|
||||
}
|
||||
triggerLabel={
|
||||
<span className="whitespace-nowrap text-sm font-medium">
|
||||
{creditsRemaining} Credits
|
||||
180 Credits
|
||||
</span>
|
||||
</Button>
|
||||
</Tooltip> */}
|
||||
}
|
||||
buttonClassName="h-[30px] px-2 ps-1.5 bg-transparent hover:bg-white/10"
|
||||
panelClassName="mt-3"
|
||||
>
|
||||
{(close) => (
|
||||
<div className="w-72 p-2.5 text-white">
|
||||
<div className="mb-2 flex items-center justify-between">
|
||||
<span className="flex items-center gap-1.5 text-sm font-medium text-white/80">
|
||||
Your credit balance
|
||||
</span>
|
||||
<button
|
||||
className="text-sm font-medium text-primary-300 transition-all hover:text-primary-200"
|
||||
onClick={() => {
|
||||
close();
|
||||
toggleCreditsModal();
|
||||
}}
|
||||
>
|
||||
Buy credits
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-4xl font-bold">
|
||||
<FontAwesomeIcon
|
||||
icon={faCoinFront}
|
||||
className="text-2xl text-primary"
|
||||
/>
|
||||
180
|
||||
</div>
|
||||
<div className="mt-3 flex gap-2">
|
||||
<Button
|
||||
variant="action"
|
||||
className="h-9 grow bg-white/15 hover:bg-white/20"
|
||||
onClick={() => {
|
||||
close();
|
||||
handleOpenBillingSettings();
|
||||
}}
|
||||
>
|
||||
See details
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
className="h-9 grow"
|
||||
onClick={() => {
|
||||
close();
|
||||
toggleModal();
|
||||
}}
|
||||
icon={faGem}
|
||||
>
|
||||
Upgrade
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</PopoverMenu>
|
||||
|
||||
<Button
|
||||
variant="primary"
|
||||
@@ -322,7 +362,7 @@ export const TopBar = ({ pageName, loginSignUpPressed }: Props) => {
|
||||
onClick={toggleModal}
|
||||
className="h-[38px] shadow-md shadow-primary-500/50 transition-all duration-300 hover:shadow-md hover:shadow-primary-500/75"
|
||||
>
|
||||
Upgrade Now
|
||||
Upgrade
|
||||
</Button>
|
||||
|
||||
<Tooltip content="Settings" position="bottom" delay={300}>
|
||||
|
||||
@@ -23,7 +23,11 @@ import { InstallSounds } from "~/pages/PageEnigma/InstallSounds";
|
||||
import { PageEditor } from "~/pages/PageEnigma/PageEditor";
|
||||
import { GalleryDragComponent } from "@storyteller/ui-gallery-modal";
|
||||
import { LoadingDots } from "@storyteller/ui-loading";
|
||||
import { PricingModal } from "@storyteller/ui-pricing-modal";
|
||||
import {
|
||||
PricingModal,
|
||||
CreditsModal,
|
||||
useCreditsModalStore,
|
||||
} from "@storyteller/ui-pricing-modal";
|
||||
import {
|
||||
isActionReminderOpen,
|
||||
actionReminderProps,
|
||||
@@ -41,6 +45,10 @@ export const PageEnigma = ({ sceneToken }: { sceneToken?: string }) => {
|
||||
useBackgroundLoadingMedia();
|
||||
useQueueHandler();
|
||||
|
||||
// Credits modal state (must be before any early returns)
|
||||
const { isOpen: isCreditsOpen, closeModal: closeCreditsModal } =
|
||||
useCreditsModalStore();
|
||||
|
||||
const [validGpu, setValidGpu] = useState("unknown");
|
||||
|
||||
useEffect(() => {
|
||||
@@ -144,6 +152,7 @@ export const PageEnigma = ({ sceneToken }: { sceneToken?: string }) => {
|
||||
)}
|
||||
|
||||
<PricingModal />
|
||||
<CreditsModal isOpen={isCreditsOpen} onClose={closeCreditsModal} />
|
||||
</EngineProvider>
|
||||
);
|
||||
};
|
||||
@@ -1,3 +1,5 @@
|
||||
export * from "./lib/pricing-modal";
|
||||
export * from "./lib/pricing-config";
|
||||
export * from "./lib/pricing-modal-store";
|
||||
export * from "./lib/credits-modal";
|
||||
export * from "./lib/credits-modal-store";
|
||||
@@ -0,0 +1,15 @@
|
||||
import { create } from "zustand";
|
||||
|
||||
interface CreditsModalState {
|
||||
isOpen: boolean;
|
||||
openModal: () => void;
|
||||
closeModal: () => void;
|
||||
toggleModal: () => void;
|
||||
}
|
||||
|
||||
export const useCreditsModalStore = create<CreditsModalState>((set) => ({
|
||||
isOpen: false,
|
||||
openModal: () => set({ isOpen: true }),
|
||||
closeModal: () => set({ isOpen: false }),
|
||||
toggleModal: () => set((state) => ({ isOpen: !state.isOpen })),
|
||||
}));
|
||||
@@ -0,0 +1,162 @@
|
||||
import { Modal } from "@storyteller/ui-modal";
|
||||
import { Button } from "@storyteller/ui-button";
|
||||
import { faCoinFront as faCoinFrontLine } from "@fortawesome/pro-regular-svg-icons";
|
||||
import { faCoinFront } from "@fortawesome/pro-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
|
||||
interface CreditPack {
|
||||
id: string;
|
||||
total: number;
|
||||
base: number;
|
||||
bonus: number;
|
||||
priceUsd: number;
|
||||
badge?: string;
|
||||
priceId?: string;
|
||||
}
|
||||
|
||||
const creditPacks: CreditPack[] = [
|
||||
{ id: "c_005", total: 330, base: 330, bonus: 0, priceUsd: 5 },
|
||||
{ id: "c_010", total: 660, base: 660, bonus: 0, priceUsd: 10 },
|
||||
{ id: "c_020", total: 1320, base: 1320, bonus: 0, priceUsd: 20 },
|
||||
{
|
||||
id: "c_050",
|
||||
total: 3500,
|
||||
base: 3300,
|
||||
bonus: 200,
|
||||
priceUsd: 50,
|
||||
},
|
||||
{
|
||||
id: "c_100",
|
||||
total: 7500,
|
||||
base: 6600,
|
||||
bonus: 900,
|
||||
priceUsd: 100,
|
||||
},
|
||||
{
|
||||
id: "c_200",
|
||||
total: 16000,
|
||||
base: 13200,
|
||||
bonus: 2800,
|
||||
priceUsd: 200,
|
||||
},
|
||||
{
|
||||
id: "c_600",
|
||||
total: 48000,
|
||||
base: 39600,
|
||||
bonus: 8400,
|
||||
priceUsd: 600,
|
||||
},
|
||||
{
|
||||
id: "c_1200",
|
||||
total: 96000,
|
||||
base: 79200,
|
||||
bonus: 16800,
|
||||
priceUsd: 1200,
|
||||
},
|
||||
];
|
||||
|
||||
interface CreditsModalProps {
|
||||
isOpen?: boolean;
|
||||
onClose?: () => void;
|
||||
onPurchase?: (pack: CreditPack) => void;
|
||||
}
|
||||
|
||||
function CoinIcon() {
|
||||
return (
|
||||
<FontAwesomeIcon
|
||||
icon={faCoinFrontLine}
|
||||
className=" absolute text-[100px] right-[20px] top-[70px] text-primary/5"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function CreditsModal({
|
||||
isOpen = false,
|
||||
onClose,
|
||||
onPurchase,
|
||||
}: CreditsModalProps) {
|
||||
const handlePurchase = async (pack: CreditPack) => {
|
||||
if (onPurchase) {
|
||||
onPurchase(pack);
|
||||
return;
|
||||
}
|
||||
|
||||
// Hook up Stripe/checkout here
|
||||
// Example: redirect to checkout with pack.priceId
|
||||
// await stripe.redirectToCheckout({ lineItems: [{ price: pack.priceId, quantity: 1 }], mode: 'payment', ... })
|
||||
// For now, just log
|
||||
// eslint-disable-next-line no-console
|
||||
console.log("Purchasing credits pack", pack);
|
||||
};
|
||||
|
||||
const cardBase =
|
||||
"relative rounded-xl border p-6 h-full flex flex-col justify-between bg-[#1F1F1F] border-white/10 hover:border-white/20 transition-all";
|
||||
|
||||
return (
|
||||
<Modal
|
||||
isOpen={isOpen}
|
||||
onClose={onClose ?? (() => {})}
|
||||
className="rounded-xl bg-[#1A1A1A] max-h-[90vh] max-w-screen-2xl overflow-y-auto flex flex-col"
|
||||
allowBackgroundInteraction={false}
|
||||
showClose={true}
|
||||
closeOnOutsideClick={true}
|
||||
resizable={false}
|
||||
backdropClassName="bg-black/80"
|
||||
>
|
||||
<div className="p-16 py-24 flex-1 overflow-y-auto min-h-0">
|
||||
<div className="text-center mb-10">
|
||||
<h1 className="text-5xl font-bold text-white mb-4">Buy credits</h1>
|
||||
<p className="text-gray-400 text-lg">
|
||||
Choose a one-time credits package. No subscription required.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-8">
|
||||
{creditPacks.map((pack) => (
|
||||
<div key={pack.id} className={cardBase}>
|
||||
{pack.badge && (
|
||||
<div className="absolute -top-3 right-4 bg-white text-black px-3 py-1 rounded-full text-xs font-semibold shadow-xl">
|
||||
{pack.badge}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<CoinIcon />
|
||||
|
||||
<div>
|
||||
<div className="text-white text-5xl font-bold tracking-tight flex items-center gap-2.5">
|
||||
<FontAwesomeIcon
|
||||
icon={faCoinFront}
|
||||
className="text-primary text-3xl"
|
||||
/>
|
||||
{pack.total.toLocaleString()}
|
||||
</div>
|
||||
{pack.bonus > 0 && (
|
||||
<div className="text-gray-400 text-sm mt-2">
|
||||
Total: {pack.base.toLocaleString()} {" + "}
|
||||
<span className="text-[#faca5a]">
|
||||
{pack.bonus.toLocaleString()} Bonus
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between pt-6">
|
||||
<div className="text-white text-xl font-semibold">
|
||||
${pack.priceUsd}
|
||||
</div>
|
||||
<Button
|
||||
onClick={() => handlePurchase(pack)}
|
||||
className="bg-white text-black hover:bg-white/90 px-5 h-10 rounded-xl"
|
||||
>
|
||||
Purchase
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
export default CreditsModal;
|
||||
@@ -161,7 +161,7 @@ export function PricingModal({
|
||||
isOpen={isOpen}
|
||||
onClose={closeModal}
|
||||
className="rounded-xl bg-[#1A1A1A] max-h-[90vh] max-w-screen-2xl overflow-y-auto flex flex-col"
|
||||
allowBackgroundInteraction={true}
|
||||
allowBackgroundInteraction={false}
|
||||
showClose={true}
|
||||
closeOnOutsideClick={true}
|
||||
resizable={false}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Button } from "@storyteller/ui-button";
|
||||
import { Label } from "@storyteller/ui-label";
|
||||
import { Progress } from "@storyteller/ui-progress";
|
||||
import {
|
||||
faCircleDollar,
|
||||
faCoinFront,
|
||||
faInfoCircle,
|
||||
faStar,
|
||||
} from "@fortawesome/pro-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { usePricingModalStore } from "@storyteller/ui-pricing-modal";
|
||||
import { useCreditsModalStore } from "@storyteller/ui-pricing-modal";
|
||||
|
||||
interface BillingSettingsPaneProps {}
|
||||
|
||||
@@ -45,45 +46,34 @@ export const BillingSettingsPane = (args: BillingSettingsPaneProps) => {
|
||||
fetchBillingData();
|
||||
}, []);
|
||||
|
||||
const creditPercentage =
|
||||
(billingInfo.credits.remaining / billingInfo.credits.total) * 100;
|
||||
const isLowCredit = creditPercentage < 20; // If used more than 80% of credits, consider it low
|
||||
const { toggleModal } = usePricingModalStore();
|
||||
const { toggleModal: toggleCreditsModal } = useCreditsModalStore();
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="space-y-4">
|
||||
<div className="flex flex-col">
|
||||
<Label htmlFor="credits" className="flex items-center gap-2">
|
||||
<FontAwesomeIcon icon={faCircleDollar} />
|
||||
Monthly credits left
|
||||
</Label>
|
||||
<div className="flex items-center gap-2">
|
||||
<Progress
|
||||
value={creditPercentage}
|
||||
isLow={isLowCredit}
|
||||
className="h-2 w-full"
|
||||
/>
|
||||
<span className="text-sm text-muted-foreground font-medium">
|
||||
{billingInfo.credits.remaining}/{billingInfo.credits.total}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr className="border-white/10" />
|
||||
|
||||
<div className="space-y-1">
|
||||
<div className="space-y-2">
|
||||
<Label>Current Plan</Label>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<FontAwesomeIcon icon={faStar} className="text-purple/70" />
|
||||
<div className="flex items-center gap-2 text-xl font-semibold ">
|
||||
<FontAwesomeIcon
|
||||
icon={faStar}
|
||||
className="text-[#C03FFF] text-lg"
|
||||
/>
|
||||
{billingInfo.plan}
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="secondary" className="h-[30px]">
|
||||
Cancel plan
|
||||
</Button>
|
||||
<Button variant="primary" className="h-[30px]">
|
||||
Change plan
|
||||
<Button
|
||||
variant="primary"
|
||||
className="h-[30px]"
|
||||
onClick={() => {
|
||||
toggleModal();
|
||||
}}
|
||||
>
|
||||
Upgrade plan
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -94,6 +84,34 @@ export const BillingSettingsPane = (args: BillingSettingsPaneProps) => {
|
||||
Next {billingInfo.nextPayment.amount} payment due{" "}
|
||||
{billingInfo.nextPayment.date}
|
||||
</div>
|
||||
|
||||
<hr className="border-white/10" />
|
||||
|
||||
<div className="flex flex-col">
|
||||
<Label htmlFor="credits" className="flex items-center gap-2">
|
||||
Your credit balance
|
||||
</Label>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<FontAwesomeIcon
|
||||
icon={faCoinFront}
|
||||
className="text-primary text-lg"
|
||||
/>
|
||||
<span className="text-2xl font-bold">
|
||||
{billingInfo.credits.remaining}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
variant="primary"
|
||||
className="h-[30px]"
|
||||
onClick={() => toggleCreditsModal()}
|
||||
>
|
||||
Buy credits
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -52,7 +52,7 @@ export const SettingsModal = ({
|
||||
const sections = [
|
||||
{ id: "general" as const, label: "General", icon: faCog },
|
||||
{ id: "accounts" as const, label: "Accounts", icon: faUser },
|
||||
// { id: "billing" as const, label: "Plan & Credits", icon: faCreditCard }, // Uncomment this for billing - BFlat
|
||||
{ id: "billing" as const, label: "Plan & Credits", icon: faCreditCard },
|
||||
{
|
||||
id: "provider_priority" as const,
|
||||
label: "Provider Priority",
|
||||
|
||||
Reference in new issue
Block a user