Skip to content

Commit

Permalink
1-3122: refetch CR notifs on actions (#8767)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thomasheartman authored Nov 15, 2024
1 parent b3437b8 commit b4d1986
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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%',
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -130,6 +133,7 @@ export const ChangeRequestOverview: FC = () => {
setShowApplyScheduledDialog(false);
await refetchChangeRequest();
refetchChangeRequestOpen();
refetchActionableChangeRequests();
setToastData({
type: 'success',
title: 'Success',
Expand All @@ -152,6 +156,7 @@ export const ChangeRequestOverview: FC = () => {
setShowScheduleChangeDialog(false);
refetchChangeRequest();
refetchChangeRequestOpen();
refetchActionableChangeRequests();
setToastData({
type: 'success',
title: 'Success',
Expand Down Expand Up @@ -191,6 +196,7 @@ export const ChangeRequestOverview: FC = () => {
setShowCancelDialog(false);
await refetchChangeRequest();
refetchChangeRequestOpen();
refetchActionableChangeRequests();
setToastData({
type: 'success',
title: 'Success',
Expand Down Expand Up @@ -219,6 +225,7 @@ export const ChangeRequestOverview: FC = () => {
text: 'Changes rejected',
});
refetchChangeRequestOpen();
refetchActionableChangeRequests();
} catch (error: unknown) {
setToastApiError(formatUnknownError(error));
} finally {
Expand All @@ -233,6 +240,7 @@ export const ChangeRequestOverview: FC = () => {
state: 'Approved',
});
await refetchChangeRequest();
refetchActionableChangeRequests();
refetchChangeRequestOpen();
setToastData({
type: 'success',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -20,6 +21,7 @@ export const useActionableChangeRequests = (

return {
total: data?.total,
refetch: mutate,
};
};

Expand Down

0 comments on commit b4d1986

Please sign in to comment.