-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### TL;DR This pull request introduces a publish endpoint and `PublishButton` component to the `AppNavbar` to enable page publishing. ### What changed? - Relocated `AppNavbar` to a new folder structure: `components/AppNavbar/AppNavbar.tsx`. - Added `PublishButton` component to `AppNavbar`. - Implemented publish functionality in `PublishButton.tsx` with page and site parameters from the navigation path. - Added a new API endpoint `publishPage` to handle the publishing logic and update the database accordingly. - Updated `page.router.ts` and `page.service.ts` with publish logic. Brief description of logic: 1. Check if there is a draft to be published, if yes, proceed 2. Fetch the page and the create a new version by incrementing the current version number 3. Use this newly created versionId to update the existing resource and set the draftBlobId to null Pending Todos: 1. Implement trigger of CodeBuild ### How to test? 1. Navigate to the admin dashboard. 2. Click the new `Publish` button. 3. Verify page publication success or failure messages. ### Why make this change? This feature allows users to publish pages directly from the navigation bar, improving the publishing workflow and user experience.
- Loading branch information
Showing
9 changed files
with
374 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
export const ResourceState = { | ||
Draft: "Draft", | ||
Published: "Published", | ||
} as const | ||
export type ResourceState = (typeof ResourceState)[keyof typeof ResourceState] | ||
Draft: "Draft", | ||
Published: "Published" | ||
} as const; | ||
export type ResourceState = (typeof ResourceState)[keyof typeof ResourceState]; | ||
export const ResourceType = { | ||
RootPage: "RootPage", | ||
Page: "Page", | ||
Folder: "Folder", | ||
Collection: "Collection", | ||
CollectionPage: "CollectionPage", | ||
} as const | ||
export type ResourceType = (typeof ResourceType)[keyof typeof ResourceType] | ||
RootPage: "RootPage", | ||
Page: "Page", | ||
Folder: "Folder", | ||
Collection: "Collection", | ||
CollectionPage: "CollectionPage" | ||
} as const; | ||
export type ResourceType = (typeof ResourceType)[keyof typeof ResourceType]; | ||
export const RoleType = { | ||
Admin: "Admin", | ||
Editor: "Editor", | ||
Publisher: "Publisher", | ||
} as const | ||
export type RoleType = (typeof RoleType)[keyof typeof RoleType] | ||
Admin: "Admin", | ||
Editor: "Editor", | ||
Publisher: "Publisher" | ||
} as const; | ||
export type RoleType = (typeof RoleType)[keyof typeof RoleType]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
apps/studio/src/features/editing-experience/components/PublishButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Skeleton } from "@chakra-ui/react" | ||
import { Button, useToast } from "@opengovsg/design-system-react" | ||
|
||
import { withSuspense } from "~/hocs/withSuspense" | ||
import { trpc } from "~/utils/trpc" | ||
|
||
interface PublishButtonProps { | ||
pageId: number | ||
siteId: number | ||
} | ||
|
||
const SuspendablePublishButton = ({ | ||
pageId, | ||
siteId, | ||
}: PublishButtonProps): JSX.Element => { | ||
const toast = useToast() | ||
const utils = trpc.useUtils() | ||
|
||
const [currPage] = trpc.page.readPage.useSuspenseQuery({ pageId, siteId }) | ||
|
||
const publishFailureMsg = | ||
"Failed to publish page. Please contact Isomer support." | ||
const publishSuccessMsg = "Page published successfully" | ||
|
||
const { mutate, isLoading } = trpc.page.publishPage.useMutation({ | ||
onSuccess: async () => { | ||
toast({ | ||
status: "success", | ||
title: publishSuccessMsg, | ||
}) | ||
await utils.page.readPage.invalidate({ pageId, siteId }) | ||
}, | ||
onError: async (error) => { | ||
console.error(`Error occurred when publishing page: ${error.message}`) | ||
toast({ | ||
status: "error", | ||
title: publishFailureMsg, | ||
}) | ||
await utils.page.readPage.invalidate({ pageId, siteId }) | ||
}, | ||
}) | ||
|
||
const handlePublish = () => { | ||
const coercedSiteId = Number(siteId) | ||
const coercedPageId = Number(pageId) | ||
if (coercedSiteId && coercedPageId) | ||
mutate({ pageId: coercedPageId, siteId: coercedSiteId }) | ||
} | ||
return ( | ||
<Button | ||
variant="solid" | ||
size="sm" | ||
onClick={handlePublish} | ||
isLoading={isLoading} | ||
isDisabled={!currPage.draftBlobId} | ||
> | ||
Publish | ||
</Button> | ||
) | ||
} | ||
|
||
const PublishButton = withSuspense( | ||
SuspendablePublishButton, | ||
<Skeleton width={"100%"} height={"100%"} />, | ||
) | ||
export default PublishButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.