From adf1fe9b7dc0b52c37e183cbc109d79f2fb0d0fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Wed, 30 Oct 2024 23:38:04 +0100 Subject: [PATCH] pl-fe: Add interaction requests mutations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- .../statuses/use-interaction-requests.ts | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/pl-fe/src/api/hooks/statuses/use-interaction-requests.ts b/packages/pl-fe/src/api/hooks/statuses/use-interaction-requests.ts index b77264808..379b7ea54 100644 --- a/packages/pl-fe/src/api/hooks/statuses/use-interaction-requests.ts +++ b/packages/pl-fe/src/api/hooks/statuses/use-interaction-requests.ts @@ -1,4 +1,4 @@ -import { type InfiniteData, useInfiniteQuery } from '@tanstack/react-query'; +import { type InfiniteData, useInfiniteQuery, useMutation } from '@tanstack/react-query'; import { importEntities } from 'pl-fe/actions/importer'; import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch'; @@ -47,4 +47,29 @@ const useInteractionRequests = (select?: (data: InfiniteData useInteractionRequests(data => data.pages.map(({ items }) => items).flat().length); -export { useInteractionRequests, useInteractionRequestsCount }; +const useAuthorizeInteractionRequestMutation = () => { + const client = useClient(); + const { refetch } = useInteractionRequests(); + + return useMutation({ + mutationFn: (requestId: string) => client.interactionRequests.authorizeInteractionRequest(requestId), + onSettled: () => refetch(), + }); +}; + +const useRejectInteractionRequestMutation = () => { + const client = useClient(); + const { refetch } = useInteractionRequests(); + + return useMutation({ + mutationFn: (requestId: string) => client.interactionRequests.rejectInteractionRequest(requestId), + onSettled: () => refetch(), + }); +}; + +export { + useInteractionRequests, + useInteractionRequestsCount, + useAuthorizeInteractionRequestMutation, + useRejectInteractionRequestMutation, +};