🛂 (billing) Add isPastDue field in workspace (#1046)

Closes #1039

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
  - Workspaces now include additional status indicator: `isPastDue`.
- New pages for handling workspaces that are past due. Meaning, an
invoice is unpaid.

- **Bug Fixes**
- Fixed issues with workspace status checks and redirections for
suspended workspaces.

- **Refactor**
- Refactored workspace-related API functions to accommodate new status
fields.
- Improved permission checks for reading and writing typebots based on
workspace status.

- **Chores**
  - Database schema updated to include `isPastDue` field for workspaces.
- Implemented new webhook event handling for subscription and invoice
updates.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Baptiste Arnaud
2023-11-23 08:16:23 +01:00
committed by GitHub
parent 94886ca58e
commit ca79934ef5
27 changed files with 450 additions and 97 deletions

View File

@@ -6,7 +6,7 @@ import {
useMemo,
useState,
} from 'react'
import { byId, isNotDefined } from '@typebot.io/lib'
import { byId } from '@typebot.io/lib'
import { WorkspaceRole } from '@typebot.io/prisma'
import { useRouter } from 'next/router'
import { trpc } from '@/lib/trpc'
@@ -136,16 +136,20 @@ export const WorkspaceProvider = ({
])
useEffect(() => {
if (isNotDefined(workspace?.isSuspended)) return
if (workspace?.isSuspended && pathname !== '/suspended') push('/suspended')
}, [pathname, push, workspace?.isSuspended])
if (workspace?.isSuspended) {
if (pathname === '/suspended') return
push('/suspended')
return
}
if (workspace?.isPastDue) {
if (pathname === '/past-due') return
push('/past-due')
return
}
}, [pathname, push, workspace?.isPastDue, workspace?.isSuspended])
const switchWorkspace = (workspaceId: string) => {
setWorkspaceIdInLocalStorage(workspaceId)
if (pathname === '/suspended') {
window.location.href = '/typebots'
return
}
setWorkspaceId(workspaceId)
}