2023-07-11 10:43:49 +02:00
|
|
|
import { Flex, FormLabel, Stack, Switch, useDisclosure } from '@chakra-ui/react'
|
2023-11-08 15:34:16 +01:00
|
|
|
import { Background, Theme } 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'
|
2023-11-09 15:12:48 +01:00
|
|
|
import { defaultTheme } from '@typebot.io/schemas/features/typebot/theme/constants'
|
:technologist: (folders) Add folder trpc endpoints (#1218)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Introduced folder management capabilities including creation,
deletion, update, listing, and retrieval within workspaces.
- Added telemetry tracking for client events, Typebot publish events,
and analytics page views.
- Enhanced settings to track client events under specific conditions.
- Implemented server-side logic for analytics tracking with PostHog
integration.
- Added API documentation for folder operations (create, delete, get,
list, update).
- **Refactor**
- Updated `onConfirm` function's return type in `ConfirmModal`.
- Simplified folder creation process in tests.
- Refactored logic for handling file upload blocks and parsing publish
events in Typebot publishing.
- Migrated handler functions to TRPC endpoints for folder operations.
- **Documentation**
- Introduced documentation for new folder and telemetry functionalities.
- **Chores**
- Added new schemas for folders and telemetry events, including event
tracking and folder structure.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-02-05 12:14:03 +01:00
|
|
|
import { trpc } from '@/lib/trpc'
|
|
|
|
import { env } from '@typebot.io/env'
|
|
|
|
import { useTypebot } from '@/features/editor/providers/TypebotProvider'
|
2022-01-24 15:07:09 +01:00
|
|
|
|
|
|
|
type Props = {
|
2023-07-11 10:43:49 +02:00
|
|
|
isBrandingEnabled: boolean
|
2023-11-08 15:34:16 +01:00
|
|
|
generalTheme: Theme['general']
|
|
|
|
onGeneralThemeChange: (general: Theme['general']) => 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()
|
:technologist: (folders) Add folder trpc endpoints (#1218)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Introduced folder management capabilities including creation,
deletion, update, listing, and retrieval within workspaces.
- Added telemetry tracking for client events, Typebot publish events,
and analytics page views.
- Enhanced settings to track client events under specific conditions.
- Implemented server-side logic for analytics tracking with PostHog
integration.
- Added API documentation for folder operations (create, delete, get,
list, update).
- **Refactor**
- Updated `onConfirm` function's return type in `ConfirmModal`.
- Simplified folder creation process in tests.
- Refactored logic for handling file upload blocks and parsing publish
events in Typebot publishing.
- Migrated handler functions to TRPC endpoints for folder operations.
- **Documentation**
- Introduced documentation for new folder and telemetry functionalities.
- **Chores**
- Added new schemas for folders and telemetry events, including event
tracking and folder structure.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-02-05 12:14:03 +01:00
|
|
|
const { typebot } = useTypebot()
|
2023-07-11 10:43:49 +02:00
|
|
|
const isWorkspaceFreePlan = isFreePlan(workspace)
|
|
|
|
|
:technologist: (folders) Add folder trpc endpoints (#1218)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Introduced folder management capabilities including creation,
deletion, update, listing, and retrieval within workspaces.
- Added telemetry tracking for client events, Typebot publish events,
and analytics page views.
- Enhanced settings to track client events under specific conditions.
- Implemented server-side logic for analytics tracking with PostHog
integration.
- Added API documentation for folder operations (create, delete, get,
list, update).
- **Refactor**
- Updated `onConfirm` function's return type in `ConfirmModal`.
- Simplified folder creation process in tests.
- Refactored logic for handling file upload blocks and parsing publish
events in Typebot publishing.
- Migrated handler functions to TRPC endpoints for folder operations.
- **Documentation**
- Introduced documentation for new folder and telemetry functionalities.
- **Chores**
- Added new schemas for folders and telemetry events, including event
tracking and folder structure.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-02-05 12:14:03 +01:00
|
|
|
const { mutate: trackClientEvents } =
|
|
|
|
trpc.telemetry.trackClientEvents.useMutation()
|
|
|
|
|
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
|
:technologist: (folders) Add folder trpc endpoints (#1218)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Introduced folder management capabilities including creation,
deletion, update, listing, and retrieval within workspaces.
- Added telemetry tracking for client events, Typebot publish events,
and analytics page views.
- Enhanced settings to track client events under specific conditions.
- Implemented server-side logic for analytics tracking with PostHog
integration.
- Added API documentation for folder operations (create, delete, get,
list, update).
- **Refactor**
- Updated `onConfirm` function's return type in `ConfirmModal`.
- Simplified folder creation process in tests.
- Refactored logic for handling file upload blocks and parsing publish
events in Typebot publishing.
- Migrated handler functions to TRPC endpoints for folder operations.
- **Documentation**
- Introduced documentation for new folder and telemetry functionalities.
- **Chores**
- Added new schemas for folders and telemetry events, including event
tracking and folder structure.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-02-05 12:14:03 +01:00
|
|
|
if (
|
|
|
|
env.NEXT_PUBLIC_POSTHOG_KEY &&
|
|
|
|
typebot &&
|
|
|
|
workspace &&
|
|
|
|
isBrandingEnabled
|
|
|
|
) {
|
|
|
|
trackClientEvents({
|
|
|
|
events: [
|
|
|
|
{
|
|
|
|
name: 'Branding removed',
|
|
|
|
typebotId: typebot.id,
|
|
|
|
workspaceId: workspace.id,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
}
|
2023-07-11 10:43:49 +02:00
|
|
|
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">
|
2023-12-29 08:02:14 -03:00
|
|
|
{t('theme.sideMenu.global.typebotBrand')}{' '}
|
2023-07-11 10:43:49 +02:00
|
|
|
{isWorkspaceFreePlan && <LockTag plan={Plan.STARTER} />}
|
|
|
|
</FormLabel>
|
|
|
|
<Switch
|
|
|
|
id="branding"
|
|
|
|
isChecked={isBrandingEnabled}
|
|
|
|
onChange={updateBranding}
|
|
|
|
/>
|
|
|
|
</Flex>
|
2022-01-24 15:07:09 +01:00
|
|
|
<FontSelector
|
2023-11-09 15:12:48 +01:00
|
|
|
activeFont={generalTheme?.font ?? defaultTheme.general.font}
|
2022-01-24 15:07:09 +01:00
|
|
|
onSelectFont={handleSelectFont}
|
|
|
|
/>
|
|
|
|
<BackgroundSelector
|
2023-11-09 15:12:48 +01:00
|
|
|
background={generalTheme?.background ?? defaultTheme.general.background}
|
2022-01-24 15:07:09 +01:00
|
|
|
onBackgroundChange={handleBackgroundChange}
|
|
|
|
/>
|
|
|
|
</Stack>
|
|
|
|
)
|
|
|
|
}
|