Skip to content

Commit

Permalink
Wired in Feedback buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
angusmccloud committed Dec 19, 2024
1 parent 591a54f commit a2d4f9e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app/containers/ConversationBubble/ConversationBubble.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@ import Tooltip from '@/app/components/Tooltip/Tooltip';
import ThumbUpIcon from '@mui/icons-material/ThumbUp';
import ThumbDownIcon from '@mui/icons-material/ThumbDown';
import ErrorIcon from '@mui/icons-material/Error';
import postFeedback from '@/app/services/postFeedback';

const ConversationBubble = ({ entry }) => {
const theme = useTheme();

const handleFeedback = async (type) => {
const success = await postFeedback(entry.requestId, type);
if (success) {
console.log('Feedback posted successfully');
} else {
console.log('Failed to post feedback');
}
};

return (
<Box
sx={{
Expand Down Expand Up @@ -45,17 +55,17 @@ const ConversationBubble = ({ entry }) => {
{(entry.askedBy === 'bot' && entry.requestId) && (
<Box sx={{ display: 'flex', justifyContent: 'flex-end', marginTop: 1 }}>
<Tooltip title="Included Spoilers">
<IconButton aria-label="Included Spoilers" color={'error'}>
<IconButton aria-label="Included Spoilers" color={'error'} onClick={() => handleFeedback('spoiler')}>
<ErrorIcon />
</IconButton>
</Tooltip>
<Tooltip title="Not Helpful">
<IconButton aria-label="Not Helpful" color={'error'}>
<IconButton aria-label="Not Helpful" color={'error'} onClick={() => handleFeedback('negative')}>
<ThumbDownIcon />
</IconButton>
</Tooltip>
<Tooltip title="Helpful">
<IconButton aria-label="Helpful" color={'success'}>
<IconButton aria-label="Helpful" color={'success'} onClick={() => handleFeedback('positive')}>
<ThumbUpIcon />
</IconButton>
</Tooltip>
Expand Down
22 changes: 22 additions & 0 deletions app/services/postFeedback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const axios = require('axios');

async function postFeedback(requestId, type) {
try {
const response = await axios.post('https://rapid-terribly-shrew.ngrok-free.app/feedback', {
request_id: requestId,
type: type,
feedback: '',
}, {
headers: {
"ngrok-skip-browser-warning": "skip"
},
crossDomain: true
});
return response.status === 200;
} catch (error) {
console.error('Failed to post feedback:', error);
return false;
}
}

module.exports = postFeedback;

0 comments on commit a2d4f9e

Please sign in to comment.