2021-12-06 15:48:50 +01:00
|
|
|
import { Button } from '@chakra-ui/react'
|
|
|
|
import { ChevronLeftIcon } from 'assets/icons'
|
|
|
|
import { NextChakraLink } from 'components/nextChakra/NextChakraLink'
|
2022-01-28 09:42:31 +01:00
|
|
|
import { useTypebotDnd } from 'contexts/TypebotDndContext'
|
|
|
|
import React, { useMemo } from 'react'
|
2021-12-06 15:48:50 +01:00
|
|
|
|
|
|
|
export const BackButton = ({ id }: { id: string | null }) => {
|
2022-01-28 09:42:31 +01:00
|
|
|
const { draggedTypebot, setMouseOverFolderId, mouseOverFolderId } =
|
|
|
|
useTypebotDnd()
|
|
|
|
|
|
|
|
const isTypebotOver = useMemo(
|
|
|
|
() => draggedTypebot && mouseOverFolderId === id,
|
|
|
|
[draggedTypebot, id, mouseOverFolderId]
|
|
|
|
)
|
|
|
|
|
|
|
|
const handleMouseEnter = () => setMouseOverFolderId(id)
|
|
|
|
const handleMouseLeave = () => setMouseOverFolderId(undefined)
|
2021-12-06 15:48:50 +01:00
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
as={NextChakraLink}
|
|
|
|
href={id ? `/typebots/folders/${id}` : '/typebots'}
|
|
|
|
leftIcon={<ChevronLeftIcon />}
|
|
|
|
variant={'outline'}
|
2022-01-28 09:42:31 +01:00
|
|
|
colorScheme={isTypebotOver ? 'blue' : 'gray'}
|
|
|
|
borderWidth={isTypebotOver ? '3px' : '1px'}
|
|
|
|
onMouseEnter={handleMouseEnter}
|
|
|
|
onMouseLeave={handleMouseLeave}
|
2021-12-06 15:48:50 +01:00
|
|
|
>
|
|
|
|
Back
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|