diff --git a/app/actions/create-pyng.ts b/app/actions/create-pyng.ts index 0a8104b..b78b243 100644 --- a/app/actions/create-pyng.ts +++ b/app/actions/create-pyng.ts @@ -81,7 +81,7 @@ For example, a user can set up "email <> when for < console.log("runId: ", runId); - const maxAttempts = 10; + const maxAttempts = 30; const pollInterval = 1000; for (let attempt = 0; attempt < maxAttempts; attempt++) { diff --git a/app/components/auth.tsx b/app/components/auth.tsx index 363c2cc..d02aa62 100644 --- a/app/components/auth.tsx +++ b/app/components/auth.tsx @@ -21,7 +21,7 @@ const UserProfile = ({ user }: { user: UserResource }) => { }; return ( -
+
User avatar diff --git a/app/components/create-pyng/create-pyng-form.tsx b/app/components/create-pyng/create-pyng-form.tsx index d3daa1b..792e53f 100644 --- a/app/components/create-pyng/create-pyng-form.tsx +++ b/app/components/create-pyng/create-pyng-form.tsx @@ -33,7 +33,6 @@ export default function CreatePyngForm({ const disabled = isSubmitting; const onSubmit: SubmitHandler = async (data) => { - console.log("clerkUserId inside", data); if (!clerkUserId) { toast.success(

@@ -57,6 +56,11 @@ export default function CreatePyngForm({ return; } + toast.success("Hold on, this could take 10 seconds.", { + icon: "⏳", + duration: 3500, + }); + const result = await createPyng(data); if (!result.success || result.error) { toast.error("Sorry, something went wrong. Please try again", { @@ -113,6 +117,10 @@ export default function CreatePyngForm({ rules={{ required: true, validate: (value) => { + if (!value) { + return "Required"; + } + const socialMediaBlocklist = [ "facebook.com", "x.com", diff --git a/app/components/header/header.tsx b/app/components/header/header.tsx index 529152d..103ae3c 100644 --- a/app/components/header/header.tsx +++ b/app/components/header/header.tsx @@ -52,7 +52,9 @@ export default function Header({ src, initialTheme }: HeaderProps) {

- +
+ +
diff --git a/app/components/header/usage.tsx b/app/components/header/usage.tsx index e9cb5bb..b1fe3de 100644 --- a/app/components/header/usage.tsx +++ b/app/components/header/usage.tsx @@ -21,15 +21,18 @@ export default function Usage({ return null; } + const [loading, setLoading] = useState(true); const [totalUsage, setTotalUsage] = useState(0); useEffect(() => { const getUsage = async () => { + setLoading(true); const totalUsage = await fetchUsage( stripeCustomerId, stripeSubscriptionId, ); setTotalUsage(totalUsage); + setLoading(false); }; getUsage(); @@ -38,10 +41,16 @@ export default function Usage({ return ( ); } diff --git a/app/components/popular-pyngs/card.tsx b/app/components/popular-pyngs/card.tsx index 70d7f7a..43c4a27 100644 --- a/app/components/popular-pyngs/card.tsx +++ b/app/components/popular-pyngs/card.tsx @@ -46,7 +46,7 @@ export default function PopularPyngsCard({
diff --git a/app/trigger/first-run.ts b/app/trigger/first-run.ts index dc7a5b2..5156eda 100644 --- a/app/trigger/first-run.ts +++ b/app/trigger/first-run.ts @@ -22,12 +22,16 @@ export const firstRun = task({ }, }); - await stripe.billing.meterEvents.create({ + console.log("Creating billing meter event..."); + + const meterEvent = await stripe.billing.meterEvents.create({ event_name: "pyng_run", payload: { stripe_customer_id: output.stripeCustomerId, }, }); + + console.log("Billing meter event created", meterEvent); }, run: async (payload: { pyngId: string; diff --git a/app/trigger/pyng.ts b/app/trigger/pyng.ts index d7d6f0c..1e85795 100644 --- a/app/trigger/pyng.ts +++ b/app/trigger/pyng.ts @@ -8,22 +8,29 @@ import { SYSTEM_PROMPT, USER_PROMPT } from "./prompts"; import scrape from "./scrape"; import stripe from "./stripe"; -type PyngTaskOutput = { - stripeCustomerId: string; -}; - export const pyngTask = schedules.task({ id: "pyng", - onSuccess: async (payload, output) => { - console.log("pyngTask onSuccess payload: ", payload); - console.log("pyngTask onSuccess output: ", output); - const { stripeCustomerId } = output as PyngTaskOutput; - await stripe.billing.meterEvents.create({ + onSuccess: async (payload) => { + const pyngId = payload.externalId; + if (!pyngId) { + throw new Error("externalId (which is the pyngId) is required"); + } + + // current pyng + const currentPyng = await prisma.pyng.findUniqueOrThrow({ + where: { + id: pyngId, + }, + }); + + console.log("Creating billing meter event..."); + const meterEvent = await stripe.billing.meterEvents.create({ event_name: "pyng_run", payload: { - stripe_customer_id: stripeCustomerId, + stripe_customer_id: currentPyng.stripeCustomerId, }, }); + console.log("Billing meter event created", meterEvent); }, run: async (payload) => { const pyngId = payload.externalId; @@ -119,9 +126,5 @@ export const pyngTask = schedules.task({ if (emailResponse.error) { throw new Error(emailResponse.error.message); } - - return { - stripeCustomerId: currentPyng.stripeCustomerId, - } as PyngTaskOutput; }, });