From 1e26703ad416460a49814c163fc2e7a288d9088c Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Wed, 21 Sep 2022 08:00:25 +0200 Subject: [PATCH] :bug: (usage) Fix storage limit check --- apps/builder/pages/api/stripe/subscription.ts | 4 ++++ apps/builder/pages/api/stripe/webhook.ts | 4 ++++ apps/viewer/assets/styles.css | 2 ++ apps/viewer/layouts/ErrorPage.tsx | 5 +---- apps/viewer/layouts/TypebotPage.tsx | 4 ++-- .../[typebotId]/blocks/[blockId]/storage/upload-url.ts | 2 +- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/apps/builder/pages/api/stripe/subscription.ts b/apps/builder/pages/api/stripe/subscription.ts index 2af21c4dd4..656a0aa854 100644 --- a/apps/builder/pages/api/stripe/subscription.ts +++ b/apps/builder/pages/api/stripe/subscription.ts @@ -174,6 +174,10 @@ const updateSubscription = async (req: NextApiRequest) => { plan, additionalChatsIndex: additionalChats, additionalStorageIndex: additionalStorage, + chatsLimitFirstEmailSentAt: null, + chatsLimitSecondEmailSentAt: null, + storageLimitFirstEmailSentAt: null, + storageLimitSecondEmailSentAt: null, }, }) } diff --git a/apps/builder/pages/api/stripe/webhook.ts b/apps/builder/pages/api/stripe/webhook.ts index 89dfaa561f..4e20167200 100644 --- a/apps/builder/pages/api/stripe/webhook.ts +++ b/apps/builder/pages/api/stripe/webhook.ts @@ -58,6 +58,10 @@ const webhookHandler = async (req: NextApiRequest, res: NextApiResponse) => { stripeId: session.customer as string, additionalChatsIndex: parseInt(additionalChats), additionalStorageIndex: parseInt(additionalStorage), + chatsLimitFirstEmailSentAt: null, + chatsLimitSecondEmailSentAt: null, + storageLimitFirstEmailSentAt: null, + storageLimitSecondEmailSentAt: null, }, }) return res.status(200).send({ message: 'workspace upgraded in DB' }) diff --git a/apps/viewer/assets/styles.css b/apps/viewer/assets/styles.css index 422135010c..d7233ffe62 100644 --- a/apps/viewer/assets/styles.css +++ b/apps/viewer/assets/styles.css @@ -1,4 +1,6 @@ body { margin: 0; overflow: hidden; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, + Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; } diff --git a/apps/viewer/layouts/ErrorPage.tsx b/apps/viewer/layouts/ErrorPage.tsx index 3a1e5bd68c..103f52338b 100644 --- a/apps/viewer/layouts/ErrorPage.tsx +++ b/apps/viewer/layouts/ErrorPage.tsx @@ -26,10 +26,7 @@ export const ErrorPage = ({ error }: { error: Error }) => { ) : ( - <> -

{error.name}

-

{error.message}

- +

{error.message}

)} ) diff --git a/apps/viewer/layouts/TypebotPage.tsx b/apps/viewer/layouts/TypebotPage.tsx index 6f11b9c2c9..43a99dfbc7 100644 --- a/apps/viewer/layouts/TypebotPage.tsx +++ b/apps/viewer/layouts/TypebotPage.tsx @@ -100,7 +100,7 @@ export const TypebotPage = ({ const handleNewAnswer = async ( answer: Answer & { uploadedFiles: boolean } ) => { - if (!resultId) return setError(new Error('Result was not created')) + if (!resultId) return setError(new Error('Error: result was not created')) const { error } = await upsertAnswer({ ...answer, resultId }) if (error) setError(error) if (chatStarted) return @@ -110,7 +110,7 @@ export const TypebotPage = ({ } const handleCompleted = async () => { - if (!resultId) return setError(new Error('Result was not created')) + if (!resultId) return setError(new Error('Error: result was not created')) const { error } = await updateResult(resultId, { isCompleted: true }) if (error) setError(error) } diff --git a/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/storage/upload-url.ts b/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/storage/upload-url.ts index 8b60b944d2..3f596ead1e 100644 --- a/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/storage/upload-url.ts +++ b/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/storage/upload-url.ts @@ -94,7 +94,7 @@ const checkStorageLimit = async (typebotId: string) => { if (!totalStorageUsed) return false const hasSentFirstEmail = workspace.storageLimitFirstEmailSentAt !== null const hasSentSecondEmail = workspace.storageLimitSecondEmailSentAt !== null - const storageLimit = getStorageLimit(typebot.workspace) + const storageLimit = getStorageLimit(typebot.workspace) * 1024 * 1024 * 1024 if ( totalStorageUsed >= storageLimit * LIMIT_EMAIL_TRIGGER_PERCENT && !hasSentFirstEmail &&