2022-09-24 08:58:23 +02:00
import { Flex , FormLabel , Stack , Switch , useDisclosure } from '@chakra-ui/react'
2022-10-01 08:36:49 +02:00
import { LockTag } from 'components/shared/LockTag'
2022-02-13 07:09:22 +01:00
import {
2022-09-24 08:58:23 +02:00
ChangePlanModal ,
LimitReached ,
} from 'components/shared/modals/ChangePlanModal'
2022-03-07 18:21:01 +01:00
import { SwitchWithLabel } from 'components/shared/SwitchWithLabel'
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-01-25 18:19:37 +01:00
import { GeneralSettings } from 'models'
import React from 'react'
2022-05-13 15:22:44 -07:00
import { isFreePlan } from 'services/workspace'
2022-06-29 10:03:55 +02:00
import { isDefined } from 'utils'
2022-01-25 18:19:37 +01:00
type Props = {
generalSettings : GeneralSettings
onGeneralSettingsChange : ( generalSettings : GeneralSettings ) = > void
}
export const GeneralSettingsForm = ( {
generalSettings ,
onGeneralSettingsChange ,
} : Props ) = > {
2022-02-13 07:09:22 +01:00
const { isOpen , onOpen , onClose } = useDisclosure ( )
2022-05-13 15:22:44 -07:00
const { workspace } = useWorkspace ( )
2022-09-24 08:58:23 +02:00
const isWorkspaceFreePlan = isFreePlan ( workspace )
2022-02-13 07:09:22 +01:00
const handleSwitchChange = ( ) = > {
2022-09-24 08:58:23 +02:00
if ( generalSettings ? . isBrandingEnabled && isWorkspaceFreePlan ) return
2022-01-25 18:19:37 +01:00
onGeneralSettingsChange ( {
2022-03-07 18:21:01 +01:00
. . . generalSettings ,
2022-01-25 18:19:37 +01:00
isBrandingEnabled : ! generalSettings ? . isBrandingEnabled ,
} )
2022-02-13 07:09:22 +01:00
}
2022-01-25 18:19:37 +01:00
2022-03-07 18:21:01 +01:00
const handleNewResultOnRefreshChange = (
isNewResultOnRefreshEnabled : boolean
) = >
onGeneralSettingsChange ( {
. . . generalSettings ,
isNewResultOnRefreshEnabled ,
} )
2022-03-10 12:05:34 +01:00
const handleInputPrefillChange = ( isInputPrefillEnabled : boolean ) = >
onGeneralSettingsChange ( {
. . . generalSettings ,
isInputPrefillEnabled ,
} )
2022-05-14 11:53:59 -07:00
const handleHideQueryParamsChange = ( isHideQueryParamsEnabled : boolean ) = >
onGeneralSettingsChange ( {
. . . generalSettings ,
isHideQueryParamsEnabled ,
} )
2022-01-25 18:19:37 +01:00
return (
< Stack spacing = { 6 } >
2022-09-24 08:58:23 +02:00
< ChangePlanModal
isOpen = { isOpen }
onClose = { onClose }
type = { LimitReached . BRAND }
/ >
2022-02-13 07:09:22 +01:00
< Flex
justifyContent = "space-between"
align = "center"
2022-09-24 08:58:23 +02:00
onClick = { isWorkspaceFreePlan ? onOpen : undefined }
2022-02-13 07:09:22 +01:00
>
2022-01-25 18:19:37 +01:00
< FormLabel htmlFor = "branding" mb = "0" >
2022-02-13 07:09:22 +01:00
Typebot . io branding { ' ' }
2022-10-01 08:36:49 +02:00
{ isWorkspaceFreePlan && < LockTag plan = { Plan . STARTER } / > }
2022-01-25 18:19:37 +01:00
< / FormLabel >
< Switch
id = "branding"
isChecked = { generalSettings . isBrandingEnabled }
onChange = { handleSwitchChange }
/ >
< / Flex >
2022-03-10 12:05:34 +01:00
< SwitchWithLabel
id = "prefill"
label = "Prefill input"
initialValue = { generalSettings . isInputPrefillEnabled ? ? true }
onCheckChange = { handleInputPrefillChange }
2022-06-29 10:03:55 +02:00
moreInfoContent = "Inputs are automatically pre-filled whenever their associated variable has a value"
2022-03-10 12:05:34 +01:00
/ >
2022-03-07 18:21:01 +01:00
< SwitchWithLabel
id = "new-result"
2022-06-29 10:03:55 +02:00
label = "Remember session"
2022-09-17 16:37:33 +02:00
initialValue = {
isDefined ( generalSettings . isNewResultOnRefreshEnabled )
? ! generalSettings . isNewResultOnRefreshEnabled
: true
}
2022-03-07 18:21:01 +01:00
onCheckChange = { handleNewResultOnRefreshChange }
2022-06-29 10:03:55 +02:00
moreInfoContent = "If the user refreshes the page, its existing results will be overwritten. Disable this if you want to create a new results every time the user refreshes the page."
2022-03-07 18:21:01 +01:00
/ >
2022-05-14 11:53:59 -07:00
< SwitchWithLabel
id = "query-params"
label = "Hide query params on bot start"
initialValue = { generalSettings . isHideQueryParamsEnabled ? ? true }
onCheckChange = { handleHideQueryParamsChange }
moreInfoContent = "If your URL contains query params, they will be automatically hidden when the bot starts."
/ >
2022-01-25 18:19:37 +01:00
< / Stack >
)
}