Skip to content

Commit

Permalink
botonic-react: create webchat context folder (#2966)
Browse files Browse the repository at this point in the history
## Description

Create a folder with all files used in WebchatContext

## Testing

import act from `@testing-library/react`
  • Loading branch information
Iru89 authored Jan 22, 2025
1 parent ca8d86a commit 45121b6
Show file tree
Hide file tree
Showing 57 changed files with 247 additions and 1,205 deletions.
981 changes: 10 additions & 971 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/botonic-plugin-flow-builder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botonic/plugin-flow-builder",
"version": "0.31.0-alpha.4",
"version": "0.31.0-alpha.5",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"description": "Use Flow Builder to show your contents",
Expand All @@ -14,7 +14,7 @@
"lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
},
"dependencies": {
"@botonic/react": "0.31.0-alpha.4",
"@botonic/react": "0.31.0-alpha.5",
"axios": "^1.7.2",
"uuid": "^10.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botonic/react",
"version": "0.31.0-alpha.4",
"version": "0.31.0-alpha.5",
"license": "MIT",
"description": "Build Chatbots using React",
"main": "./lib/cjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-react/src/components/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import React, { useContext, useState } from 'react'
import styled from 'styled-components'

import { COLORS, WEBCHAT } from '../constants'
import { WebchatContext } from '../contexts'
import { resolveImage } from '../util/environment'
import { renderComponent } from '../util/react'
import { generateWebviewUrlWithParams } from '../util/webviews'
import { WebchatContext } from '../webchat/context'
import { ButtonsDisabler } from './buttons-disabler'
import { ButtonProps } from './index-types'

Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-react/src/components/carousel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import styled from 'styled-components'
import LeftArrow from '../assets/leftArrow.svg'
import RightArrow from '../assets/rightArrow.svg'
import { COLORS, WEBCHAT } from '../constants'
import { WebchatContext } from '../contexts'
import { resolveImage } from '../util/environment'
import { WebchatContext } from '../webchat/context'
import { ButtonsDisabler } from './buttons-disabler'
import { Message } from './message'

Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-react/src/components/document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import React, { useContext } from 'react'
import styled from 'styled-components'

import { ROLES, WEBCHAT } from '../constants'
import { WebchatContext } from '../contexts'
import { staticAsset } from '../util/environment'
import { WebchatContext } from '../webchat/context'
import { DocumentProps } from './index-types'
import { Message } from './message'

Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-react/src/components/handoff.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useContext, useState } from 'react'
import styled from 'styled-components'

import { COLORS } from '../constants'
import { WebchatContext } from '../contexts'
import { WebchatContext } from '../webchat/context'

const Container = styled.div`
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-react/src/components/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import React, { useContext, useState } from 'react'
import styled from 'styled-components'

import { ROLES, WEBCHAT } from '../constants'
import { WebchatContext } from '../contexts'
import { staticAsset } from '../util/environment'
import { WebchatContext } from '../webchat/context'
import { ImageProps } from './index-types'
import { Message } from './message'

Expand Down
3 changes: 2 additions & 1 deletion packages/botonic-react/src/components/message/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import React, { useContext, useEffect, useState } from 'react'
import { v7 as uuidv7 } from 'uuid'

import { COLORS, WEBCHAT } from '../../constants'
import { RequestContext, WebchatContext } from '../../contexts'
import { RequestContext } from '../../contexts'
import { SENDERS } from '../../index-types'
import { Fade } from '../../shared/styles'
import { isDev } from '../../util/environment'
import { ConditionalWrapper, renderComponent } from '../../util/react'
import { WebchatContext } from '../../webchat/context'
import { Button } from '../button'
import { ButtonsDisabler } from '../buttons-disabler'
import { getMarkdownStyle, renderLinks, renderMarkdown } from '../markdown'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { v7 as uuidv7 } from 'uuid'

import ThumbsDown from '../../assets/thumbs-down.svg'
import ThumbsUp from '../../assets/thumbs-up.svg'
import { WebchatContext } from '../../contexts'
import { ActionRequest } from '../../index-types'
import { resolveImage } from '../../util'
import { WebchatContext } from '../../webchat/context'
import { EventAction, FeedbackOption } from '../../webchat/tracking'
import { FeedbackButton, FeedbackMessageContainer } from './styles'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useContext } from 'react'

import { WebchatContext } from '../../contexts'
import { SENDERS } from '../../index-types'
import { WebchatContext } from '../../webchat/context'
import { MessageFeedback } from './message-feedback'
import { MessageFooterContainer } from './styles'
import { MessageTimestamp, resolveMessageTimestamps } from './timestamps'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useContext } from 'react'

import { WEBCHAT } from '../../constants'
import { WebchatContext } from '../../contexts'
import { SENDERS } from '../../index-types'
import { resolveImage } from '../../util/environment'
import { WebchatContext } from '../../webchat/context'
import { BotMessageImageContainer } from './styles'

interface MessageImageProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useContext } from 'react'

import { WEBCHAT } from '../../constants'
import { WebchatContext } from '../../contexts'
import { SENDERS } from '../../index-types'
import { resolveImage } from '../../util'
import { WebchatContext } from '../../webchat/context'
import { TimestampContainer, TimestampText } from './styles'

export const resolveMessageTimestamps = (
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-react/src/components/reply.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React, { useContext } from 'react'
import styled from 'styled-components'

import { COLORS, WEBCHAT } from '../constants'
import { WebchatContext } from '../contexts'
import { renderComponent } from '../util/react'
import { WebchatContext } from '../webchat/context'
import { ReplyProps } from './index-types'

const StyledButton = styled.button`
Expand Down
4 changes: 2 additions & 2 deletions packages/botonic-react/src/components/webchat-settings.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { INPUT } from '@botonic/core'
import React, { useContext } from 'react'

import { WebchatContext } from '../contexts'
import { renderComponent } from '../util/react'
import { stringifyWithRegexs } from '../util/regexs'
import { WebchatSettingsProps } from '.'
import { WebchatContext } from '../webchat/context'
import { WebchatSettingsProps } from './index-types'

export const WebchatSettings = ({
theme,
Expand Down
77 changes: 1 addition & 76 deletions packages/botonic-react/src/contexts.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Input as CoreInput, Session as CoreSession } from '@botonic/core'
import { createContext } from 'react'

import { ActionRequest, WebchatContextProps } from './index-types'
import { webchatInitialState } from './webchat/hooks'
import { ActionRequest } from './index-types'

export const RequestContext = createContext<
Partial<ActionRequest> & {
Expand Down Expand Up @@ -36,77 +35,3 @@ export const WebviewRequestContext = createContext<{
params: {} as Record<string, any>,
session: {} as Partial<CoreSession>,
})

export const WebchatContext = createContext<WebchatContextProps>({
addMessage: () => {
return
},
getThemeProperty: () => {
return
}, // used to retrieve a specific property of the theme defined by the developer in his 'webchat/index.js'
openWebview: () => {
return
},
resolveCase: () => {
return
},
resetUnreadMessages: () => {
return
},
setIsInputFocused: () => {
return
},
setLastMessageVisible: () => {
return
},
sendAttachment: async () => {
return
},
sendInput: async () => {
return
},
sendPayload: async () => {
return
},
sendText: async () => {
return
},
theme: {},
toggleCoverComponent: () => {
return
},
toggleWebchat: () => {
return
},
toggleEmojiPicker: () => {
return
},
togglePersistentMenu: () => {
return
},
updateLatestInput: () => {
return
},
updateMessage: () => {
return
},
updateReplies: () => {
return
},
updateUser: () => {
return
},
updateWebchatDevSettings: () => {
return
},
webchatState: webchatInitialState,
trackEvent: async () => {
return
},
webchatRef: { current: null },
chatAreaRef: { current: null },
inputPanelRef: { current: null },
headerRef: { current: null },
scrollableMessagesListRef: { current: null },
repliesRef: { current: null },
})
40 changes: 1 addition & 39 deletions packages/botonic-react/src/index-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from '@botonic/core'
import React from 'react'

import { Reply } from './components'
import {
BlockInputOption,
ButtonProps,
Expand All @@ -20,11 +19,9 @@ import {
ReplyProps,
ThemeProps,
WebchatSettingsProps,
Webview,
} from './components/index-types'
import { CloseWebviewOptions } from './contexts'
import { UseWebchat } from './webchat/hooks/use-webchat'
import { WebchatState } from './webchat/index-types'
import { UseWebchat } from './webchat/context/use-webchat'
import { WebchatApp } from './webchat-app'

/**
Expand Down Expand Up @@ -214,38 +211,3 @@ interface UpdateMessageInfoEvent {
message: MessageInfo
isError?: boolean
}

// ClientInput: type for sendInput and updateLatestInput function without message_id and bot_interaction_id because backend set this values
export type ClientInput = Omit<CoreInput, 'message_id' | 'bot_interaction_id'>

export interface WebchatContextProps {
addMessage: (message: WebchatMessage) => void
getThemeProperty: (property: string, defaultValue?: any) => any
openWebview: (webviewComponent: Webview, params?: any) => void
resetUnreadMessages: () => void
resolveCase: () => void
sendAttachment: (attachment: File) => Promise<void>
sendInput: (input: ClientInput) => Promise<void>
sendPayload: (payload: string) => Promise<void>
sendText: (text: string, payload?: string) => Promise<void>
setIsInputFocused: (isInputFocused: boolean) => void
setLastMessageVisible: (isLastMessageVisible: boolean) => void
theme: ThemeProps // TODO: Review if theme is needed and used from WebchatContext
toggleWebchat: (toggle: boolean) => void
toggleEmojiPicker: (toggle: boolean) => void
togglePersistentMenu: (toggle: boolean) => void
toggleCoverComponent: (toggle: boolean) => void
updateLatestInput: (input: ClientInput) => void
updateMessage: (message: WebchatMessage) => void
updateReplies: (replies: (typeof Reply)[]) => void
updateUser: (user: Partial<CoreSessionUser>) => void
updateWebchatDevSettings: (settings: WebchatSettingsProps) => void
trackEvent?: TrackEventFunction
webchatState: WebchatState
webchatRef: React.MutableRefObject<HTMLDivElement | null> // Rename this to webchatContainerRef
chatAreaRef: React.MutableRefObject<HTMLDivElement | null>
inputPanelRef: React.MutableRefObject<HTMLDivElement | null>
headerRef: React.MutableRefObject<HTMLDivElement | null>
scrollableMessagesListRef: React.MutableRefObject<HTMLDivElement | null>
repliesRef: React.MutableRefObject<HTMLDivElement | null>
}
6 changes: 1 addition & 5 deletions packages/botonic-react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export { BotonicInputTester, BotonicOutputTester } from './botonic-tester'
export * from './components'
export {
RequestContext,
WebchatContext,
WebviewRequestContext,
} from './contexts'
export { RequestContext, WebviewRequestContext } from './contexts'
export { DevApp } from './dev-app'
export * from './index-types'
export { msgsToBotonic, msgToBotonic } from './msg-to-botonic'
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-react/src/webchat/chat-area/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useContext, useEffect, useState } from 'react'

import { WebchatContext } from '../../contexts'
import { BotonicContainerId } from '../constants'
import { WebchatContext } from '../context'
import { useWebchatDimensions } from '../hooks'
import { WebchatMessageList } from '../message-list'
import { WebchatReplies } from '../replies'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useContext } from 'react'

import { WEBCHAT } from '../../constants'
import { WebchatContext } from '../../contexts'
import { Scale } from '../../shared/styles'
import { ConditionalWrapper } from '../../util/react'
import { WebchatContext } from '../context'

export const ConditionalAnimation = props => {
const { getThemeProperty } = useContext(WebchatContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components'

import { Button } from '../../components/button'
import { ROLES, WEBCHAT } from '../../constants'
import { WebchatContext } from '../../contexts'
import { WebchatContext } from '../context'
import { useComponentVisible } from '../hooks'

const ButtonsContainer = styled.div`
Expand Down
Loading

0 comments on commit 45121b6

Please sign in to comment.