2022-09-24 08:58:23 +02:00
|
|
|
import { Button, HStack, useDisclosure, Text } from '@chakra-ui/react'
|
2022-02-12 10:23:58 +01:00
|
|
|
import { FolderPlusIcon } from 'assets/icons'
|
2022-09-17 16:37:33 +02:00
|
|
|
import {
|
|
|
|
LimitReached,
|
|
|
|
ChangePlanModal,
|
|
|
|
} from 'components/shared/modals/ChangePlanModal'
|
2022-09-24 08:58:23 +02:00
|
|
|
import { PlanTag } from 'components/shared/PlanTag'
|
2022-05-13 15:22:44 -07:00
|
|
|
import { useWorkspace } from 'contexts/WorkspaceContext'
|
2022-09-24 08:58:23 +02:00
|
|
|
import { Plan } from 'db'
|
2022-02-12 10:23:58 +01:00
|
|
|
import React from 'react'
|
2022-05-13 15:22:44 -07:00
|
|
|
import { isFreePlan } from 'services/workspace'
|
2022-02-12 10:23:58 +01:00
|
|
|
|
|
|
|
type Props = { isLoading: boolean; onClick: () => void }
|
|
|
|
|
|
|
|
export const CreateFolderButton = ({ isLoading, onClick }: Props) => {
|
2022-05-13 15:22:44 -07:00
|
|
|
const { workspace } = useWorkspace()
|
2022-02-12 10:23:58 +01:00
|
|
|
const { isOpen, onOpen, onClose } = useDisclosure()
|
|
|
|
|
|
|
|
const handleClick = () => {
|
2022-05-13 15:22:44 -07:00
|
|
|
if (isFreePlan(workspace)) return onOpen()
|
2022-02-12 10:23:58 +01:00
|
|
|
onClick()
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
leftIcon={<FolderPlusIcon />}
|
|
|
|
onClick={handleClick}
|
|
|
|
isLoading={isLoading}
|
|
|
|
>
|
|
|
|
<HStack>
|
|
|
|
<Text>Create a folder</Text>
|
2022-09-24 08:58:23 +02:00
|
|
|
{isFreePlan(workspace) && <PlanTag plan={Plan.STARTER} />}
|
2022-02-12 10:23:58 +01:00
|
|
|
</HStack>
|
2022-09-17 16:37:33 +02:00
|
|
|
<ChangePlanModal
|
2022-02-12 12:54:16 +01:00
|
|
|
isOpen={isOpen}
|
|
|
|
onClose={onClose}
|
|
|
|
type={LimitReached.FOLDER}
|
|
|
|
/>
|
2022-02-12 10:23:58 +01:00
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|