2023-03-15 08:35:16 +01:00
|
|
|
import { DashboardFolder, WorkspaceRole } from '@typebot.io/prisma'
|
2021-12-06 15:48:50 +01:00
|
|
|
import {
|
|
|
|
Flex,
|
|
|
|
Heading,
|
|
|
|
HStack,
|
2022-01-28 09:42:31 +01:00
|
|
|
Portal,
|
2021-12-06 15:48:50 +01:00
|
|
|
Skeleton,
|
|
|
|
Stack,
|
2022-01-28 09:42:31 +01:00
|
|
|
useEventListener,
|
2021-12-06 15:48:50 +01:00
|
|
|
Wrap,
|
|
|
|
} from '@chakra-ui/react'
|
2022-11-15 09:35:48 +01:00
|
|
|
import { useTypebotDnd } from '../TypebotDndProvider'
|
2024-03-26 19:25:54 +01:00
|
|
|
import React, { useEffect, useState } from 'react'
|
2022-11-15 09:35:48 +01:00
|
|
|
import { BackButton } from './BackButton'
|
2023-03-15 11:51:30 +01:00
|
|
|
import { useWorkspace } from '@/features/workspace/WorkspaceProvider'
|
2022-11-15 09:35:48 +01:00
|
|
|
import { useToast } from '@/hooks/useToast'
|
|
|
|
import { CreateBotButton } from './CreateBotButton'
|
|
|
|
import { CreateFolderButton } from './CreateFolderButton'
|
2024-03-26 19:25:54 +01:00
|
|
|
import FolderButton, { ButtonSkeleton } from './FolderButton'
|
|
|
|
import TypebotButton from './TypebotButton'
|
2022-11-15 09:35:48 +01:00
|
|
|
import { TypebotCardOverlay } from './TypebotButtonOverlay'
|
2023-03-15 11:51:30 +01:00
|
|
|
import { useTypebots } from '@/features/dashboard/hooks/useTypebots'
|
|
|
|
import { TypebotInDashboard } from '@/features/dashboard/types'
|
2023-08-17 09:39:11 +02:00
|
|
|
import { trpc } from '@/lib/trpc'
|
2024-03-26 19:25:54 +01:00
|
|
|
import { NodePosition } from '@/features/graph/providers/GraphDndProvider'
|
2021-12-06 15:48:50 +01:00
|
|
|
|
|
|
|
type Props = { folder: DashboardFolder | null }
|
|
|
|
|
|
|
|
export const FolderContent = ({ folder }: Props) => {
|
2022-06-18 09:06:46 +02:00
|
|
|
const { workspace, currentRole } = useWorkspace()
|
2021-12-06 15:48:50 +01:00
|
|
|
const [isCreatingFolder, setIsCreatingFolder] = useState(false)
|
2022-01-28 09:42:31 +01:00
|
|
|
const {
|
|
|
|
setDraggedTypebot,
|
|
|
|
draggedTypebot,
|
|
|
|
mouseOverFolderId,
|
|
|
|
setMouseOverFolderId,
|
|
|
|
} = useTypebotDnd()
|
|
|
|
const [draggablePosition, setDraggablePosition] = useState({ x: 0, y: 0 })
|
2024-03-26 19:25:54 +01:00
|
|
|
const [mousePositionInElement, setMousePositionInElement] = useState({
|
2022-01-28 09:42:31 +01:00
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
})
|
|
|
|
|
2022-06-02 07:54:48 +02:00
|
|
|
const { showToast } = useToast()
|
2022-05-14 11:53:03 -07:00
|
|
|
|
2021-12-06 15:48:50 +01:00
|
|
|
const {
|
: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
|
|
|
data: { folders } = {},
|
2021-12-06 15:48:50 +01:00
|
|
|
isLoading: isFolderLoading,
|
: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
|
|
|
refetch: refetchFolders,
|
|
|
|
} = trpc.folders.listFolders.useQuery(
|
|
|
|
{
|
|
|
|
workspaceId: workspace?.id as string,
|
|
|
|
parentFolderId: folder?.id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
enabled: !!workspace,
|
|
|
|
onError: (error) => {
|
|
|
|
showToast({
|
|
|
|
description: error.message,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
const { mutate: createFolder } = trpc.folders.createFolder.useMutation({
|
2021-12-06 15:48:50 +01:00
|
|
|
onError: (error) => {
|
: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
|
|
|
showToast({ description: error.message })
|
|
|
|
},
|
|
|
|
onSuccess: () => {
|
|
|
|
refetchFolders()
|
2021-12-06 15:48:50 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-08-17 09:39:11 +02:00
|
|
|
const { mutate: updateTypebot } = trpc.typebot.updateTypebot.useMutation({
|
|
|
|
onError: (error) => {
|
|
|
|
showToast({ description: error.message })
|
|
|
|
},
|
|
|
|
onSuccess: () => {
|
|
|
|
refetchTypebots()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2021-12-06 15:48:50 +01:00
|
|
|
const {
|
|
|
|
typebots,
|
|
|
|
isLoading: isTypebotLoading,
|
2022-11-30 13:57:28 +01:00
|
|
|
refetch: refetchTypebots,
|
2021-12-06 15:48:50 +01:00
|
|
|
} = useTypebots({
|
2022-05-13 15:22:44 -07:00
|
|
|
workspaceId: workspace?.id,
|
2022-11-30 13:57:28 +01:00
|
|
|
folderId: folder === null ? 'root' : folder.id,
|
2021-12-06 15:48:50 +01:00
|
|
|
onError: (error) => {
|
2022-06-02 07:54:48 +02:00
|
|
|
showToast({
|
|
|
|
description: error.message,
|
|
|
|
})
|
2021-12-06 15:48:50 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
const moveTypebotToFolder = async (typebotId: string, folderId: string) => {
|
|
|
|
if (!typebots) return
|
2023-08-17 09:39:11 +02:00
|
|
|
updateTypebot({
|
|
|
|
typebotId,
|
|
|
|
typebot: {
|
|
|
|
folderId: folderId === 'root' ? null : folderId,
|
|
|
|
},
|
2021-12-06 15:48:50 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
: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 handleCreateFolder = () => {
|
2022-05-13 15:22:44 -07:00
|
|
|
if (!folders || !workspace) return
|
2021-12-06 15:48:50 +01:00
|
|
|
setIsCreatingFolder(true)
|
: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
|
|
|
createFolder({
|
|
|
|
workspaceId: workspace.id,
|
|
|
|
parentFolderId: folder?.id,
|
2021-12-06 15:48:50 +01:00
|
|
|
})
|
|
|
|
setIsCreatingFolder(false)
|
|
|
|
}
|
|
|
|
|
2022-01-28 09:42:31 +01:00
|
|
|
const handleMouseUp = async () => {
|
|
|
|
if (mouseOverFolderId !== undefined && draggedTypebot)
|
|
|
|
await moveTypebotToFolder(draggedTypebot.id, mouseOverFolderId ?? 'root')
|
|
|
|
setMouseOverFolderId(undefined)
|
|
|
|
setDraggedTypebot(undefined)
|
|
|
|
}
|
|
|
|
useEventListener('mouseup', handleMouseUp)
|
|
|
|
|
2024-03-26 19:25:54 +01:00
|
|
|
const handleTypebotDrag =
|
|
|
|
(typebot: TypebotInDashboard) =>
|
|
|
|
({ absolute, relative }: NodePosition) => {
|
|
|
|
if (draggedTypebot) return
|
|
|
|
setMousePositionInElement(relative)
|
|
|
|
setDraggablePosition({
|
|
|
|
x: absolute.x - relative.x,
|
|
|
|
y: absolute.y - relative.y,
|
|
|
|
})
|
|
|
|
setDraggedTypebot(typebot)
|
2022-02-21 11:46:56 +01:00
|
|
|
}
|
2022-01-28 09:42:31 +01:00
|
|
|
|
|
|
|
const handleMouseMove = (e: MouseEvent) => {
|
2024-03-26 19:25:54 +01:00
|
|
|
if (!draggedTypebot) return
|
|
|
|
const { clientX, clientY } = e
|
2022-01-28 09:42:31 +01:00
|
|
|
setDraggablePosition({
|
2024-03-26 19:25:54 +01:00
|
|
|
x: clientX - mousePositionInElement.x,
|
|
|
|
y: clientY - mousePositionInElement.y,
|
2022-01-28 09:42:31 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
useEventListener('mousemove', handleMouseMove)
|
|
|
|
|
2024-03-26 19:25:54 +01:00
|
|
|
useEffect(() => {
|
|
|
|
if (!draggablePosition || !draggedTypebot) return
|
|
|
|
const { innerHeight } = window
|
|
|
|
const scrollSpeed = 10
|
|
|
|
const scrollMargin = 50
|
|
|
|
const clientY = draggablePosition.y + mousePositionInElement.y
|
|
|
|
const scrollY =
|
|
|
|
clientY < scrollMargin
|
|
|
|
? -scrollSpeed
|
|
|
|
: clientY > innerHeight - scrollMargin
|
|
|
|
? scrollSpeed
|
|
|
|
: 0
|
|
|
|
window.scrollBy(0, scrollY)
|
|
|
|
const interval = setInterval(() => {
|
|
|
|
window.scrollBy(0, scrollY)
|
|
|
|
}, 5)
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
clearInterval(interval)
|
|
|
|
}
|
|
|
|
}, [draggablePosition, draggedTypebot, mousePositionInElement])
|
|
|
|
|
2021-12-06 15:48:50 +01:00
|
|
|
return (
|
2022-02-07 07:13:16 +01:00
|
|
|
<Flex w="full" flex="1" justify="center">
|
: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
|
|
|
<Stack w="1000px" spacing={6} pt="4">
|
2022-01-28 09:42:31 +01:00
|
|
|
<Skeleton isLoaded={folder?.name !== undefined}>
|
|
|
|
<Heading as="h1">{folder?.name}</Heading>
|
|
|
|
</Skeleton>
|
|
|
|
<Stack>
|
|
|
|
<HStack>
|
|
|
|
{folder && <BackButton id={folder.parentFolderId} />}
|
2022-06-18 09:06:46 +02:00
|
|
|
{currentRole !== WorkspaceRole.GUEST && (
|
|
|
|
<CreateFolderButton
|
|
|
|
onClick={handleCreateFolder}
|
|
|
|
isLoading={isCreatingFolder || isFolderLoading}
|
|
|
|
/>
|
|
|
|
)}
|
2022-01-28 09:42:31 +01:00
|
|
|
</HStack>
|
|
|
|
<Wrap spacing={4}>
|
2022-06-18 09:06:46 +02:00
|
|
|
{currentRole !== WorkspaceRole.GUEST && (
|
|
|
|
<CreateBotButton
|
|
|
|
folderId={folder?.id}
|
|
|
|
isLoading={isTypebotLoading}
|
|
|
|
/>
|
|
|
|
)}
|
2022-01-28 09:42:31 +01:00
|
|
|
{isFolderLoading && <ButtonSkeleton />}
|
|
|
|
{folders &&
|
2024-03-07 14:10:03 +01:00
|
|
|
folders.map((folder, index) => (
|
2022-01-28 09:42:31 +01:00
|
|
|
<FolderButton
|
2024-03-26 19:27:21 +01:00
|
|
|
key={folder.id}
|
2024-03-07 14:10:03 +01:00
|
|
|
index={index}
|
2022-01-28 09:42:31 +01:00
|
|
|
folder={folder}
|
: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
|
|
|
onFolderDeleted={refetchFolders}
|
|
|
|
onFolderRenamed={() => refetchFolders()}
|
2022-01-28 09:42:31 +01:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
{isTypebotLoading && <ButtonSkeleton />}
|
|
|
|
{typebots &&
|
|
|
|
typebots.map((typebot) => (
|
|
|
|
<TypebotButton
|
2024-03-26 19:27:21 +01:00
|
|
|
key={typebot.id}
|
2022-01-28 09:42:31 +01:00
|
|
|
typebot={typebot}
|
2024-03-26 19:25:54 +01:00
|
|
|
draggedTypebot={draggedTypebot}
|
: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
|
|
|
onTypebotUpdated={refetchTypebots}
|
2024-03-26 19:25:54 +01:00
|
|
|
onDrag={handleTypebotDrag(typebot)}
|
2022-01-28 09:42:31 +01:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Wrap>
|
2021-12-06 15:48:50 +01:00
|
|
|
</Stack>
|
2022-01-28 09:42:31 +01:00
|
|
|
</Stack>
|
|
|
|
{draggedTypebot && (
|
|
|
|
<Portal>
|
|
|
|
<TypebotCardOverlay
|
|
|
|
typebot={draggedTypebot}
|
|
|
|
onMouseUp={handleMouseUp}
|
|
|
|
pos="fixed"
|
|
|
|
top="0"
|
|
|
|
left="0"
|
|
|
|
style={{
|
|
|
|
transform: `translate(${draggablePosition.x}px, ${draggablePosition.y}px) rotate(-2deg)`,
|
|
|
|
}}
|
2024-03-26 19:25:54 +01:00
|
|
|
transformOrigin="0 0 0"
|
2022-01-28 09:42:31 +01:00
|
|
|
/>
|
|
|
|
</Portal>
|
|
|
|
)}
|
2021-12-06 15:48:50 +01:00
|
|
|
</Flex>
|
|
|
|
)
|
|
|
|
}
|