2
0

🐛 (usage) Fix storage limit check

This commit is contained in:
Baptiste Arnaud
2022-09-21 08:00:25 +02:00
committed by Baptiste Arnaud
parent 1063429275
commit 1e26703ad4
6 changed files with 14 additions and 7 deletions

View File

@@ -174,6 +174,10 @@ const updateSubscription = async (req: NextApiRequest) => {
plan, plan,
additionalChatsIndex: additionalChats, additionalChatsIndex: additionalChats,
additionalStorageIndex: additionalStorage, additionalStorageIndex: additionalStorage,
chatsLimitFirstEmailSentAt: null,
chatsLimitSecondEmailSentAt: null,
storageLimitFirstEmailSentAt: null,
storageLimitSecondEmailSentAt: null,
}, },
}) })
} }

View File

@@ -58,6 +58,10 @@ const webhookHandler = async (req: NextApiRequest, res: NextApiResponse) => {
stripeId: session.customer as string, stripeId: session.customer as string,
additionalChatsIndex: parseInt(additionalChats), additionalChatsIndex: parseInt(additionalChats),
additionalStorageIndex: parseInt(additionalStorage), additionalStorageIndex: parseInt(additionalStorage),
chatsLimitFirstEmailSentAt: null,
chatsLimitSecondEmailSentAt: null,
storageLimitFirstEmailSentAt: null,
storageLimitSecondEmailSentAt: null,
}, },
}) })
return res.status(200).send({ message: 'workspace upgraded in DB' }) return res.status(200).send({ message: 'workspace upgraded in DB' })

View File

@@ -1,4 +1,6 @@
body { body {
margin: 0; margin: 0;
overflow: hidden; overflow: hidden;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
} }

View File

@@ -26,10 +26,7 @@ export const ErrorPage = ({ error }: { error: Error }) => {
</h2> </h2>
</> </>
) : ( ) : (
<> <p style={{ fontSize: '24px' }}>{error.message}</p>
<h1 style={{ fontWeight: 'bold', fontSize: '30px' }}>{error.name}</h1>
<h2>{error.message}</h2>
</>
)} )}
</div> </div>
) )

View File

@@ -100,7 +100,7 @@ export const TypebotPage = ({
const handleNewAnswer = async ( const handleNewAnswer = async (
answer: Answer & { uploadedFiles: boolean } 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 }) const { error } = await upsertAnswer({ ...answer, resultId })
if (error) setError(error) if (error) setError(error)
if (chatStarted) return if (chatStarted) return
@@ -110,7 +110,7 @@ export const TypebotPage = ({
} }
const handleCompleted = async () => { 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 }) const { error } = await updateResult(resultId, { isCompleted: true })
if (error) setError(error) if (error) setError(error)
} }

View File

@@ -94,7 +94,7 @@ const checkStorageLimit = async (typebotId: string) => {
if (!totalStorageUsed) return false if (!totalStorageUsed) return false
const hasSentFirstEmail = workspace.storageLimitFirstEmailSentAt !== null const hasSentFirstEmail = workspace.storageLimitFirstEmailSentAt !== null
const hasSentSecondEmail = workspace.storageLimitSecondEmailSentAt !== null const hasSentSecondEmail = workspace.storageLimitSecondEmailSentAt !== null
const storageLimit = getStorageLimit(typebot.workspace) const storageLimit = getStorageLimit(typebot.workspace) * 1024 * 1024 * 1024
if ( if (
totalStorageUsed >= storageLimit * LIMIT_EMAIL_TRIGGER_PERCENT && totalStorageUsed >= storageLimit * LIMIT_EMAIL_TRIGGER_PERCENT &&
!hasSentFirstEmail && !hasSentFirstEmail &&