From 0c9dea6e56a5391706b3e5eab3db05399306a175 Mon Sep 17 00:00:00 2001 From: Joe Slain Date: Tue, 3 Dec 2024 14:43:57 +0100 Subject: [PATCH] feat: usePostEvaluations --- src/api/usePostEvaluations.tsx | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/api/usePostEvaluations.tsx diff --git a/src/api/usePostEvaluations.tsx b/src/api/usePostEvaluations.tsx new file mode 100644 index 0000000..de5cc8a --- /dev/null +++ b/src/api/usePostEvaluations.tsx @@ -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), + }) +}