Skip to content

Commit

Permalink
Merge branch 'dev' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeSlain committed Dec 3, 2024
2 parents 5a0c8e3 + f7255ca commit 6406ef6
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 3 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ jobs:
VITE_MODEL_MODE=${{ vars.VITE_MODEL_MODE }}
VITE_MODEL_TEMPERATURE=${{ vars.VITE_MODEL_TEMPERATURE }}
VITE_MATOMO_URL=${{ vars.VITE_MATOMO_URL }}
VITE_KEYCLOAK_AUTHORITY=${{ vars.VITE_KEYCLOAK_AUTHORITY }}
VITE_KEYCLOAK_CLIENT_ID=${{ vars.VITE_KEYCLOAK_CLIENT_ID }}
VITE_KEYCLOAK_REDIRECT_URL=${{ vars.VITE_KEYCLOAK_REDIRECT_URL }}
deploy-dev:
name: Deploy from ${{ github.ref_name }}/${{ github.sha }}
Expand Down
2 changes: 2 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export * from './useAddFeedback'
export * from './useGetChunk'
export * from './useGetChatArchiveById'
export * from './useGetInstitutions'
export * from './useGetEvaluationQuestions'
export * from './usePostEvaluations'
1 change: 1 addition & 0 deletions src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export const getSheetsUrl = `${apiBase}/get_sheets`
export const getChunksUrl = `${apiBase}/get_chunks`
export const getChunkUrl = `${apiBase}/get_chunk`
export const mfsOrganizationsUrl = `${apiBase}/organizations/mfs`
export const evaluationsUrl = `${apiBase}/evaluations`
30 changes: 30 additions & 0 deletions src/api/useGetEvaluationQuestions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { evaluationsUrl } from '@api'
import { useQuery } from '@tanstack/react-query'

export function useGetEvaluationQuestions() {
return useQuery({
queryKey: ['getEvaluationQuestions'],
queryFn: () => fetchEvaluations(),
enabled: true,
})
}

const fetchEvaluations = async (): Promise<string[]> => {
const authToken = localStorage.getItem('authToken')

const res = await fetch(`${evaluationsUrl}`, {
method: 'GET',
credentials: 'include',
headers: {
Authorization: `Bearer ${authToken}`,
'Content-Type': 'application/json',
},
})

if (!res.ok) {
console.error('error: response not ok', res)
throw new Error('Impossible de récupérer les archives', { cause: res })
}
const institutions = await res.json()
return institutions as string[]
}
34 changes: 34 additions & 0 deletions src/api/usePostEvaluations.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { evaluationsUrl } from '@api'
import { useMutation } from '@tanstack/react-query'

export function usePostEvaluations() {
return useMutation({
mutationKey: ['postEvaluations'],
mutationFn: (params) => postEvaluations(params),
})
}

function postEvaluations(params) {
const authToken = localStorage.getItem('authToken')

const data = {
question: params.question,
themes: params.themes,
operators: params.operators,
title: params.title,
rating: params.rating,
positiveFeedback: params.positiveFeedback,
negativeFeedback: params.negativeFeedback,
comments: params.comments,
}

return fetch(`${evaluationsUrl}/evaluations`, {
method: 'POST',
credentials: 'include',
headers: {
Authorization: `Bearer ${authToken}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
}
8 changes: 8 additions & 0 deletions src/pages/Evaluations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { TextWithSources } from 'components/Sources/TextWithSources'
import { EventSourcePolyfill } from 'event-source-polyfill'
import { useCallback, useEffect, useRef, useState } from 'react'
import { onCloseStream } from '../utils/eventsEmitter'
//import ShowError from 'components/Error/ShowError'

const questions = [
{
Expand Down Expand Up @@ -70,6 +71,13 @@ export default function Evaluations() {
}

function Questions({ setSelectedCardIndex }) {
// const { data: questionList, error, isLoading } = useGetEvaluationQuestions()
// if (error) {
// console.error(error)
// //@ts-expect-error
// return <ShowError message={error.message} errorNumber={error.status} />
// }

return (
<div className="grid grid-cols-2 gap-4">
{questions.map((question, index) => (
Expand Down

0 comments on commit 6406ef6

Please sign in to comment.