Skip to content

Commit

Permalink
Fix/allow user edits for open review request (#1587)
Browse files Browse the repository at this point in the history
* Chore: add separate check for disabled write actions

* fix: update site header behaviour
  • Loading branch information
alexanderleegs authored Oct 16, 2023
1 parent 2464023 commit f6d12e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/layouts/layouts/SiteEditLayout/SiteEditHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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`
Expand Down Expand Up @@ -117,7 +116,7 @@ export const SiteEditHeader = (): JSX.Element => {
id="isomer-workspace-feature-tour-step-1"
leftIcon={<Icon as={BiCheckCircle} fontSize="1.25rem" />}
onClick={onReviewRequestModalOpen}
isDisabled={isWriteDisabled}
isDisabled={hasOpenReviewRequest}
>
Request a Review
</Button>
Expand Down
16 changes: 15 additions & 1 deletion src/utils/reviewRequests.ts
Original file line number Diff line number Diff line change
@@ -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
)
Expand All @@ -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
}

0 comments on commit f6d12e8

Please sign in to comment.