From f6d12e816d904b4024c19d0520dc654b0ba33376 Mon Sep 17 00:00:00 2001 From: Alexander Lee Date: Mon, 16 Oct 2023 13:49:04 +0800 Subject: [PATCH] Fix/allow user edits for open review request (#1587) * Chore: add separate check for disabled write actions * fix: update site header behaviour --- .../layouts/SiteEditLayout/SiteEditHeader.tsx | 7 +++---- src/utils/reviewRequests.ts | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/layouts/layouts/SiteEditLayout/SiteEditHeader.tsx b/src/layouts/layouts/SiteEditLayout/SiteEditHeader.tsx index 02f14f73c..95f6f9876 100644 --- a/src/layouts/layouts/SiteEditLayout/SiteEditHeader.tsx +++ b/src/layouts/layouts/SiteEditLayout/SiteEditHeader.tsx @@ -28,11 +28,10 @@ import { useDirtyFieldContext } from "contexts/DirtyFieldContext" import { useLoginContext } from "contexts/LoginContext" import { useStagingUrl } from "hooks/settingsHooks" -import { useGetReviewRequests } from "hooks/siteDashboardHooks" import { ReviewRequestModal } from "layouts/ReviewRequest" -import { isWriteActionsDisabled } from "utils/reviewRequests" +import { doesOpenReviewRequestExist } from "utils/reviewRequests" import { NavImage } from "assets" @@ -57,7 +56,7 @@ export const SiteEditHeader = (): JSX.Element => { const isGithubUser = !!userId const history = useHistory() - const isWriteDisabled = isWriteActionsDisabled(siteName) + const hasOpenReviewRequest = doesOpenReviewRequestExist(siteName) const onBackButtonClick = () => { const redirPath = isGithubUser ? "/sites" : `/sites/${siteName}/dashboard` @@ -117,7 +116,7 @@ export const SiteEditHeader = (): JSX.Element => { id="isomer-workspace-feature-tour-step-1" leftIcon={} onClick={onReviewRequestModalOpen} - isDisabled={isWriteDisabled} + isDisabled={hasOpenReviewRequest} > Request a Review diff --git a/src/utils/reviewRequests.ts b/src/utils/reviewRequests.ts index 9efcdf303..5b3ce02c3 100644 --- a/src/utils/reviewRequests.ts +++ b/src/utils/reviewRequests.ts @@ -1,6 +1,6 @@ import { useGetReviewRequests } from "hooks/siteDashboardHooks" -export const isWriteActionsDisabled = (siteName: string) => { +export const doesOpenReviewRequestExist = (siteName: string) => { const { data: reviewRequests, isLoading, isError } = useGetReviewRequests( siteName ) @@ -13,3 +13,17 @@ export const isWriteActionsDisabled = (siteName: string) => { return isLoading || isError || isReviewRequestPending } + +export const isWriteActionsDisabled = (siteName: string) => { + const { data: reviewRequests, isLoading, isError } = useGetReviewRequests( + siteName + ) + + // Note: if PR is in APPROVED status, it will auto-redirect to dashboard as no edits should happen + // But have added here to be explicit of the status checks + const isReviewRequestPending = reviewRequests?.some( + (request) => request.status === "APPROVED" + ) + + return isLoading || isError || isReviewRequestPending +}