From 27cb6b742ac25a65bf0f843afe408ecb77e788a7 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Tue, 22 Nov 2022 14:59:38 +0100 Subject: [PATCH] fix cr banner (#2501) --- .../ChangeRequestOverview.tsx | 4 ++++ .../ReviewButton/ReviewButton.tsx | 4 ++++ .../useChangeRequestOpen/useChangeRequestOpen.ts | 16 ++++++---------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx b/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx index 709fb77df7..6fceea9ad8 100644 --- a/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx +++ b/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx @@ -21,6 +21,7 @@ import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser'; import AccessContext from 'contexts/AccessContext'; import { ChangeRequestComment } from './ChangeRequestComments/ChangeRequestComment'; import { AddCommentField } from './ChangeRequestComments/AddCommentField'; +import { useChangeRequestOpen } from 'hooks/api/getters/useChangeRequestOpen/useChangeRequestOpen'; const StyledAsideBox = styled(Box)(({ theme }) => ({ width: '30%', @@ -58,6 +59,8 @@ export const ChangeRequestOverview: FC = () => { id ); const { changeState, addComment } = useChangeRequestApi(); + const { refetch: refetchChangeRequestOpen } = + useChangeRequestOpen(projectId); const { setToastData, setToastApiError } = useToast(); if (!changeRequest) { @@ -70,6 +73,7 @@ export const ChangeRequestOverview: FC = () => { state: 'Applied', }); refetchChangeRequest(); + refetchChangeRequestOpen(); setToastData({ type: 'success', title: 'Success', diff --git a/frontend/src/component/changeRequest/ChangeRequestOverview/ReviewButton/ReviewButton.tsx b/frontend/src/component/changeRequest/ChangeRequestOverview/ReviewButton/ReviewButton.tsx index bced57aa2a..05aae4cb00 100644 --- a/frontend/src/component/changeRequest/ChangeRequestOverview/ReviewButton/ReviewButton.tsx +++ b/frontend/src/component/changeRequest/ChangeRequestOverview/ReviewButton/ReviewButton.tsx @@ -20,6 +20,7 @@ import { APPROVE_CHANGE_REQUEST } from 'component/providers/AccessProvider/permi import PermissionButton from 'component/common/PermissionButton/PermissionButton'; import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser'; import AccessContext from 'contexts/AccessContext'; +import { useChangeRequestOpen } from 'hooks/api/getters/useChangeRequestOpen/useChangeRequestOpen'; export const ReviewButton = () => { const { isAdmin } = useContext(AccessContext); @@ -27,6 +28,8 @@ export const ReviewButton = () => { const id = useRequiredPathParam('id'); const { user } = useAuthUser(); const { refetchChangeRequest, data } = useChangeRequest(projectId, id); + const { refetch: refetchChangeRequestOpen } = + useChangeRequestOpen(projectId); const { setToastApiError, setToastData } = useToast(); const { changeState } = useChangeRequestApi(); @@ -40,6 +43,7 @@ export const ReviewButton = () => { state: 'Approved', }); refetchChangeRequest(); + refetchChangeRequestOpen(); setToastData({ type: 'success', title: 'Success', diff --git a/frontend/src/hooks/api/getters/useChangeRequestOpen/useChangeRequestOpen.ts b/frontend/src/hooks/api/getters/useChangeRequestOpen/useChangeRequestOpen.ts index aee350585a..ebaadd68bd 100644 --- a/frontend/src/hooks/api/getters/useChangeRequestOpen/useChangeRequestOpen.ts +++ b/frontend/src/hooks/api/getters/useChangeRequestOpen/useChangeRequestOpen.ts @@ -1,5 +1,4 @@ import useSWR from 'swr'; -import { useMemo } from 'react'; import { formatApiPath } from 'utils/formatPath'; import handleErrorResponses from '../httpErrorResponseHandler'; import { IChangeRequest } from 'component/changeRequest/changeRequest.types'; @@ -18,13 +17,10 @@ export const useChangeRequestOpen = (project: string) => { isOss() ? () => Promise.resolve([]) : fetcher ); - return useMemo( - () => ({ - draft: data, - loading: !error && !data, - refetch: () => mutate(), - error, - }), - [data, error, mutate] - ); + return { + draft: data, + loading: !error && !data, + refetch: mutate, + error, + }; };