feat(theme): ✨ Custom avatars
This commit is contained in:
@ -1,13 +1,15 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { useTypebot } from '../../contexts/TypebotContext'
|
||||
import { HostAvatar } from '../avatars/HostAvatar'
|
||||
import { Avatar } from '../avatars/Avatar'
|
||||
import { useFrame } from 'react-frame-component'
|
||||
import { CSSTransition, TransitionGroup } from 'react-transition-group'
|
||||
import { useHostAvatars } from '../../contexts/HostAvatarsContext'
|
||||
|
||||
export const AvatarSideContainer = () => {
|
||||
export const AvatarSideContainer = ({
|
||||
hostAvatarSrc,
|
||||
}: {
|
||||
hostAvatarSrc: string
|
||||
}) => {
|
||||
const { lastBubblesTopOffset } = useHostAvatars()
|
||||
const { typebot } = useTypebot()
|
||||
const { window, document } = useFrame()
|
||||
const [marginBottom, setMarginBottom] = useState(
|
||||
window.innerWidth < 400 ? 38 : 48
|
||||
@ -44,7 +46,7 @@ export const AvatarSideContainer = () => {
|
||||
transition: 'top 350ms ease-out',
|
||||
}}
|
||||
>
|
||||
<HostAvatar typebotName={typebot.name} />
|
||||
<Avatar avatarSrc={hostAvatarSrc} />
|
||||
</div>
|
||||
</CSSTransition>
|
||||
))}
|
||||
|
@ -15,6 +15,7 @@ import {
|
||||
import { executeLogic } from 'services/logic'
|
||||
import { executeIntegration } from 'services/integration'
|
||||
import { parseRetryStep, stepCanBeRetried } from 'services/inputs'
|
||||
import { parseVariables } from 'index'
|
||||
|
||||
type ChatBlockProps = {
|
||||
steps: PublicStep[]
|
||||
@ -108,7 +109,13 @@ export const ChatBlock = ({
|
||||
return (
|
||||
<div className="flex">
|
||||
<HostAvatarsContext>
|
||||
<AvatarSideContainer />
|
||||
{(typebot.theme.chat.hostAvatar?.isEnabled ?? true) && (
|
||||
<AvatarSideContainer
|
||||
hostAvatarSrc={parseVariables(typebot.variables)(
|
||||
typebot.theme.chat.hostAvatar?.url
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<div className="flex flex-col w-full">
|
||||
<TransitionGroup>
|
||||
{displayedSteps
|
||||
|
@ -9,6 +9,8 @@ import { DateForm } from './inputs/DateForm'
|
||||
import { ChoiceForm } from './inputs/ChoiceForm'
|
||||
import { HostBubble } from './bubbles/HostBubble'
|
||||
import { isInputValid } from 'services/inputs'
|
||||
import { useTypebot } from 'contexts/TypebotContext'
|
||||
import { parseVariables } from 'index'
|
||||
|
||||
export const ChatStep = ({
|
||||
step,
|
||||
@ -38,6 +40,7 @@ const InputChatStep = ({
|
||||
step: InputStep
|
||||
onSubmit: (value: string, isRetry: boolean) => void
|
||||
}) => {
|
||||
const { typebot } = useTypebot()
|
||||
const { addNewAvatarOffset } = useHostAvatars()
|
||||
const [answer, setAnswer] = useState<string>()
|
||||
|
||||
@ -52,7 +55,15 @@ const InputChatStep = ({
|
||||
}
|
||||
|
||||
if (answer) {
|
||||
return <GuestBubble message={answer} />
|
||||
return (
|
||||
<GuestBubble
|
||||
message={answer}
|
||||
showAvatar={typebot.theme.chat.guestAvatar?.isEnabled ?? false}
|
||||
avatarSrc={parseVariables(typebot.variables)(
|
||||
typebot.theme.chat.guestAvatar?.url
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
switch (step.type) {
|
||||
case InputStepType.TEXT:
|
||||
|
@ -1,11 +1,18 @@
|
||||
import { Avatar } from 'components/avatars/Avatar'
|
||||
import React from 'react'
|
||||
import { CSSTransition } from 'react-transition-group'
|
||||
|
||||
interface Props {
|
||||
message: string
|
||||
showAvatar: boolean
|
||||
avatarSrc: string
|
||||
}
|
||||
|
||||
export const GuestBubble = ({ message }: Props): JSX.Element => {
|
||||
export const GuestBubble = ({
|
||||
message,
|
||||
showAvatar,
|
||||
avatarSrc,
|
||||
}: Props): JSX.Element => {
|
||||
return (
|
||||
<CSSTransition classNames="bubble" timeout={1000}>
|
||||
<div className="flex justify-end mb-2 items-center">
|
||||
@ -16,6 +23,7 @@ export const GuestBubble = ({ message }: Props): JSX.Element => {
|
||||
>
|
||||
{message}
|
||||
</div>
|
||||
{showAvatar && <Avatar avatarSrc={avatarSrc} />}
|
||||
</div>
|
||||
</div>
|
||||
</CSSTransition>
|
||||
|
Reference in New Issue
Block a user