1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

1-3122: refetch CR notifs on actions (#8767)

Refetch actionable change requests whenever you perform an action on a
change request. This ensures that the change request notifications are
up-to-date for you. Of course, it can still get out of sync if someone
else performs an action on the change request, but that's more of an
edge case.
This commit is contained in:
Thomas Heartman 2024-11-15 10:02:36 +01:00 committed by GitHub
parent b3437b8c34
commit b4d19862d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -33,6 +33,7 @@ import {
import { ScheduleChangeRequestDialog } from './ChangeRequestScheduledDialogs/ScheduleChangeRequestDialog';
import type { PlausibleChangeRequestState } from '../changeRequest.types';
import { useNavigate } from 'react-router-dom';
import { useActionableChangeRequests } from 'hooks/api/getters/useActionableChangeRequests/useActionableChangeRequests';
const StyledAsideBox = styled(Box)(({ theme }) => ({
width: '30%',
@ -89,6 +90,8 @@ export const ChangeRequestOverview: FC = () => {
const { user } = useAuthUser();
const { isAdmin } = useContext(AccessContext);
const [commentText, setCommentText] = useState('');
const { refetch: refetchActionableChangeRequests } =
useActionableChangeRequests(projectId);
const id = useRequiredPathParam('id');
const { data: changeRequest, refetchChangeRequest } = useChangeRequest(
@ -130,6 +133,7 @@ export const ChangeRequestOverview: FC = () => {
setShowApplyScheduledDialog(false);
await refetchChangeRequest();
refetchChangeRequestOpen();
refetchActionableChangeRequests();
setToastData({
type: 'success',
title: 'Success',
@ -152,6 +156,7 @@ export const ChangeRequestOverview: FC = () => {
setShowScheduleChangeDialog(false);
refetchChangeRequest();
refetchChangeRequestOpen();
refetchActionableChangeRequests();
setToastData({
type: 'success',
title: 'Success',
@ -191,6 +196,7 @@ export const ChangeRequestOverview: FC = () => {
setShowCancelDialog(false);
await refetchChangeRequest();
refetchChangeRequestOpen();
refetchActionableChangeRequests();
setToastData({
type: 'success',
title: 'Success',
@ -219,6 +225,7 @@ export const ChangeRequestOverview: FC = () => {
text: 'Changes rejected',
});
refetchChangeRequestOpen();
refetchActionableChangeRequests();
} catch (error: unknown) {
setToastApiError(formatUnknownError(error));
} finally {
@ -233,6 +240,7 @@ export const ChangeRequestOverview: FC = () => {
state: 'Approved',
});
await refetchChangeRequest();
refetchActionableChangeRequests();
refetchChangeRequestOpen();
setToastData({
type: 'success',

View File

@ -5,12 +5,13 @@ import { useEnterpriseSWR } from '../useEnterpriseSWR/useEnterpriseSWR';
interface IUseActionableChangeRequestsOutput {
total?: number;
refetch: () => void;
}
export const useActionableChangeRequests = (
projectId: string,
): IUseActionableChangeRequestsOutput => {
const { data } = useEnterpriseSWR<ActionableChangeRequestsSchema>(
const { data, mutate } = useEnterpriseSWR<ActionableChangeRequestsSchema>(
{ total: 0 },
formatApiPath(
`api/admin/projects/${projectId}/change-requests/actionable`,
@ -20,6 +21,7 @@ export const useActionableChangeRequests = (
return {
total: data?.total,
refetch: mutate,
};
};