Skip to content

Commit

Permalink
feat: evaluations call working
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeSlain committed Dec 13, 2024
1 parent 4b0e8d0 commit 7c5008c
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 113 deletions.
11 changes: 7 additions & 4 deletions src/api/useAddFeedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ export function useAddFeedback() {
interface AddFeedbackParams {
feedback: Feedback
streamId: number
reasons: string[]
}

const addFeedback = async ({ feedback, streamId, reasons }: AddFeedbackParams) => {
const addFeedback = async ({ feedback, streamId }: AddFeedbackParams) => {
console.log('addFeedback', feedback, streamId)
const authToken = localStorage.getItem('authToken')
const data = {
is_good: !feedback.isGood,
message: feedback.message,
reason:
reasons[0] === 'other' ? (reasons[1]?.length ? reasons[1] : null) : reasons[0],
positives: feedback.positives ? feedback.positives : [],
negatives: feedback.negatives ? feedback.negatives : [],
note: feedback.note,
is_confirmed: feedback.isConfirmed,
type: feedback.type,
}
const res = await fetch(`${feedbackUrl}/${streamId}`, {
method: 'POST',
Expand Down
6 changes: 3 additions & 3 deletions src/components/Feedbacks/Feedback.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InitialFeedback, type Feedback as FeedbackType } from '@types'
import { InitialChatFeedback, type Feedback as FeedbackType } from '@types'
import { useEffect, useState } from 'react'
import { GlobalColContainer } from '../Global/GlobalColContainer'
import { UserFeedbackInput } from './UserFeedbackInput'
Expand All @@ -11,10 +11,10 @@ import { UserSatisfactionButtons } from './UserSatisfactionButtons'
* false when giving feedback on a question that has been regenerated
*/
export function Feedback() {
const [feedback, setFeedback] = useState<FeedbackType>(InitialFeedback)
const [feedback, setFeedback] = useState<FeedbackType>(InitialChatFeedback)

useEffect(() => {
setFeedback(InitialFeedback)
setFeedback(InitialChatFeedback)
}, [])
return (
<GlobalColContainer>
Expand Down
38 changes: 0 additions & 38 deletions src/components/Feedbacks/UserExperience.tsx

This file was deleted.

14 changes: 12 additions & 2 deletions src/components/Feedbacks/UserFeedbackOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,17 @@ export function UserFeedbackOptions({
)
}

const ConfirmationButton = ({ reasons, otherReason, feedback, setFeedback }) => {
const ConfirmationButton = ({
reasons,
otherReason,
feedback,
setFeedback,
}: {
reasons: string[]
otherReason: string
feedback: FeedbackType
setFeedback: (feedback: FeedbackType) => void
}) => {
const streamId = useSelector((state: RootState) => state.user.lastStreamId)
const addFeedback = useAddFeedback()

Expand All @@ -65,7 +75,7 @@ const ConfirmationButton = ({ reasons, otherReason, feedback, setFeedback }) =>
...feedback,
message: otherReason,
})
addFeedback.mutate({ feedback, streamId, reasons })
addFeedback.mutate({ feedback, streamId })
setFeedback({
...feedback,
isConfirmed: true,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Feedbacks/UserSatisfactionButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InitialFeedback, type Feedback as FeedbackType } from '@types'
import { InitialChatFeedback, type Feedback as FeedbackType } from '@types'
import { GlobalRowContainer } from '../Global/GlobalRowContainer'
import { fr } from '@codegouvfr/react-dsfr'

Expand All @@ -15,7 +15,7 @@ export function UserSatisfactionButtons({
setFeedback: (feedback: FeedbackType) => void
}) {
const handleClick = (isGood: number) => {
if (isGood === feedback.isGood) setFeedback(InitialFeedback)
if (isGood === feedback.isGood) setFeedback(InitialChatFeedback)
else {
setFeedback({
...feedback,
Expand Down
Loading

0 comments on commit 7c5008c

Please sign in to comment.