Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
350 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/botonic-react/src/components/message/feedback.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Oops, something went wrong.