2023-07-11 10:43:49 +02:00
|
|
|
import { Flex, FormLabel, Stack, Switch, useDisclosure } from '@chakra-ui/react'
|
2023-03-15 08:35:16 +01:00
|
|
|
import { Background, GeneralTheme } from '@typebot.io/schemas'
|
2022-01-24 15:07:09 +01:00
|
|
|
import React from 'react'
|
|
|
|
import { BackgroundSelector } from './BackgroundSelector'
|
|
|
|
import { FontSelector } from './FontSelector'
|
2023-07-11 10:43:49 +02:00
|
|
|
import { LockTag } from '@/features/billing/components/LockTag'
|
|
|
|
import { Plan } from '@typebot.io/prisma'
|
|
|
|
import { isFreePlan } from '@/features/billing/helpers/isFreePlan'
|
|
|
|
import { useWorkspace } from '@/features/workspace/WorkspaceProvider'
|
|
|
|
import { ChangePlanModal } from '@/features/billing/components/ChangePlanModal'
|
2023-10-27 09:23:50 +02:00
|
|
|
import { useTranslate } from '@tolgee/react'
|
2022-01-24 15:07:09 +01:00
|
|
|
|
|
|
|
type Props = {
|
2023-07-11 10:43:49 +02:00
|
|
|
isBrandingEnabled: boolean
|
2022-01-25 18:19:37 +01:00
|
|
|
generalTheme: GeneralTheme
|
2022-01-24 15:07:09 +01:00
|
|
|
onGeneralThemeChange: (general: GeneralTheme) => void
|
2023-07-11 10:43:49 +02:00
|
|
|
onBrandingChange: (isBrandingEnabled: boolean) => void
|
2022-01-24 15:07:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const GeneralSettings = ({
|
2023-07-11 10:43:49 +02:00
|
|
|
isBrandingEnabled,
|
2022-01-24 15:07:09 +01:00
|
|
|
generalTheme,
|
|
|
|
onGeneralThemeChange,
|
2023-07-11 10:43:49 +02:00
|
|
|
onBrandingChange,
|
2022-01-24 15:07:09 +01:00
|
|
|
}: Props) => {
|
2023-10-27 09:23:50 +02:00
|
|
|
const { t } = useTranslate()
|
2023-07-11 10:43:49 +02:00
|
|
|
const { isOpen, onOpen, onClose } = useDisclosure()
|
|
|
|
const { workspace } = useWorkspace()
|
|
|
|
const isWorkspaceFreePlan = isFreePlan(workspace)
|
|
|
|
|
2022-01-24 15:07:09 +01:00
|
|
|
const handleSelectFont = (font: string) =>
|
|
|
|
onGeneralThemeChange({ ...generalTheme, font })
|
|
|
|
|
|
|
|
const handleBackgroundChange = (background: Background) =>
|
|
|
|
onGeneralThemeChange({ ...generalTheme, background })
|
|
|
|
|
2023-07-11 10:43:49 +02:00
|
|
|
const updateBranding = () => {
|
|
|
|
if (isBrandingEnabled && isWorkspaceFreePlan) return
|
|
|
|
onBrandingChange(!isBrandingEnabled)
|
|
|
|
}
|
|
|
|
|
2022-01-24 15:07:09 +01:00
|
|
|
return (
|
|
|
|
<Stack spacing={6}>
|
2023-07-11 10:43:49 +02:00
|
|
|
<ChangePlanModal
|
|
|
|
isOpen={isOpen}
|
|
|
|
onClose={onClose}
|
|
|
|
type={t('billing.limitMessage.brand')}
|
|
|
|
/>
|
|
|
|
<Flex
|
|
|
|
justifyContent="space-between"
|
|
|
|
align="center"
|
|
|
|
onClick={isWorkspaceFreePlan ? onOpen : undefined}
|
|
|
|
>
|
|
|
|
<FormLabel htmlFor="branding" mb="0" cursor="pointer">
|
|
|
|
Show Typebot brand{' '}
|
|
|
|
{isWorkspaceFreePlan && <LockTag plan={Plan.STARTER} />}
|
|
|
|
</FormLabel>
|
|
|
|
<Switch
|
|
|
|
id="branding"
|
|
|
|
isChecked={isBrandingEnabled}
|
|
|
|
onChange={updateBranding}
|
|
|
|
/>
|
|
|
|
</Flex>
|
2022-01-24 15:07:09 +01:00
|
|
|
<FontSelector
|
2022-01-25 18:19:37 +01:00
|
|
|
activeFont={generalTheme.font}
|
2022-01-24 15:07:09 +01:00
|
|
|
onSelectFont={handleSelectFont}
|
|
|
|
/>
|
|
|
|
<BackgroundSelector
|
2022-01-25 18:19:37 +01:00
|
|
|
background={generalTheme.background}
|
2022-01-24 15:07:09 +01:00
|
|
|
onBackgroundChange={handleBackgroundChange}
|
|
|
|
/>
|
|
|
|
</Stack>
|
|
|
|
)
|
|
|
|
}
|