2022-02-14 16:41:39 +01:00
|
|
|
import { Button, ButtonProps, useDisclosure } from '@chakra-ui/react'
|
2022-06-01 12:09:45 +02:00
|
|
|
import { useWorkspace } from 'contexts/WorkspaceContext'
|
|
|
|
import { Plan } from 'db'
|
2022-02-14 16:41:39 +01:00
|
|
|
import React from 'react'
|
2022-06-01 12:09:45 +02:00
|
|
|
import { isNotDefined } from 'utils'
|
2022-04-05 14:55:19 +02:00
|
|
|
import { UpgradeModal } from '../modals/UpgradeModal'
|
|
|
|
import { LimitReached } from '../modals/UpgradeModal/UpgradeModal'
|
2022-02-14 16:41:39 +01:00
|
|
|
|
2022-06-01 12:09:45 +02:00
|
|
|
type Props = { plan?: Plan; type?: LimitReached } & ButtonProps
|
2022-02-14 16:41:39 +01:00
|
|
|
|
2022-06-01 12:09:45 +02:00
|
|
|
export const UpgradeButton = ({ type, plan = Plan.PRO, ...props }: Props) => {
|
2022-02-14 16:41:39 +01:00
|
|
|
const { isOpen, onOpen, onClose } = useDisclosure()
|
2022-06-01 12:09:45 +02:00
|
|
|
const { workspace } = useWorkspace()
|
2022-02-14 16:41:39 +01:00
|
|
|
return (
|
2022-06-01 12:09:45 +02:00
|
|
|
<Button
|
|
|
|
colorScheme="blue"
|
|
|
|
{...props}
|
|
|
|
isLoading={isNotDefined(workspace)}
|
|
|
|
onClick={onOpen}
|
|
|
|
>
|
2022-02-18 14:57:10 +01:00
|
|
|
{props.children ?? 'Upgrade'}
|
2022-06-01 12:09:45 +02:00
|
|
|
<UpgradeModal isOpen={isOpen} onClose={onClose} type={type} plan={plan} />
|
2022-02-14 16:41:39 +01:00
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|