Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Iru89 committed Apr 22, 2024
1 parent c5f3601 commit 60fd460
Show file tree
Hide file tree
Showing 16 changed files with 350 additions and 24 deletions.
164 changes: 159 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -46,6 +46,7 @@ export async function createNodeFromKnowledgeBase(
],
buttons_style: undefined,
buttons: [],
withfeedback: true,
},
flow_id: 'randomUUID', // TODO: Add flow_id consequentially with HtBaseNode changes
id: uuid(),
Expand Down
Expand Up @@ -13,6 +13,7 @@ export class FlowText extends ContentFieldsBase {
public code = ''
public buttons: FlowButton[] = []
public buttonStyle = HtButtonStyle.BUTTON
public withfeedback?: boolean

static fromHubtypeCMS(
cmsText: HtTextNode,
Expand All @@ -26,6 +27,7 @@ export class FlowText extends ContentFieldsBase {
newText.buttons = cmsText.content.buttons.map(button =>
FlowButton.fromHubtypeCMS(button, locale, cmsApi)
)
newText.withfeedback = cmsText.content.withfeedback
return newText
}

Expand Down Expand Up @@ -57,7 +59,7 @@ export class FlowText extends ContentFieldsBase {
toBotonic(id: string, request: ActionRequest): JSX.Element {
const replacedText = FlowText.replaceVariables(this.text, request)
return (
<Text key={id}>
<Text key={id} withfeedback={this.withfeedback}>
{replacedText}
{this.buttons.map((button, buttonIndex) =>
button.renderButton(buttonIndex, this.buttonStyle)
Expand Down
Expand Up @@ -5,6 +5,7 @@ import { HtButtonStyle, HtNodeWithContentType } from './node-types'
export interface HtTextNode extends HtBaseNode {
type: HtNodeWithContentType.TEXT
content: {
withfeedback?: boolean
text: HtTextLocale[]
buttons_style?: HtButtonStyle
buttons: HtButton[]
Expand Down
3 changes: 3 additions & 0 deletions packages/botonic-react/src/assets/thumbs-down.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/botonic-react/src/assets/thumbs-up.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/botonic-react/src/components/index-types.ts
Expand Up @@ -29,6 +29,7 @@ export interface MessageProps {
export interface TextProps extends MessageProps {
// converts markdown syntax to HTML
markdown?: boolean
withfeedback?: boolean
}

export interface Webview {
Expand Down
58 changes: 58 additions & 0 deletions packages/botonic-react/src/components/message/feedback.tsx
@@ -0,0 +1,58 @@
import React, { useEffect, useState } from 'react'

import ThumbsDown from '../../assets/thumbs-down.svg'
import ThumbsUp from '../../assets/thumbs-up.svg'
import { resolveImage } from '../../util'
import { getBotonicApp } from '../../webchat'
import { FeedbackButton, FeedbackContainer } from './styles'

interface FeedbackProps {
messageId: string
}

interface FeedbackState {
up: boolean
down: boolean
}

export const Feedback = ({ messageId }: FeedbackProps) => {
const [show, setShow] = useState(true)
const [disabled, setDisabled] = useState<FeedbackState>({
up: false,
down: false,
})

useEffect(() => {
if (disabled.up || disabled.down) {
setTimeout(() => {
setShow(false)
}, 1000)
}
}, [disabled])

const handleClick = (isPositive: boolean) => {
const botonicApp = getBotonicApp()
const payloadJson = JSON.stringify({ messageId, isPositive })
if (isPositive) {
setDisabled({ up: false, down: true })
botonicApp.addUserPayload(`messageFeedback|${payloadJson}`)
} else {
setDisabled({ up: true, down: false })
botonicApp.addUserPayload(`messageFeedback|${payloadJson}`)
}
}

return show ? (
<FeedbackContainer>
<FeedbackButton disabled={disabled.up} onClick={() => handleClick(true)}>
<img src={resolveImage(ThumbsUp)} />
</FeedbackButton>
<FeedbackButton
disabled={disabled.down}
onClick={() => handleClick(false)}
>
<img src={resolveImage(ThumbsDown)} />
</FeedbackButton>
</FeedbackContainer>
) : null
}

0 comments on commit 60fd460

Please sign in to comment.