-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/admin create index page temp workabout #1065
Merged
adriangohjw
merged 18 commits into
main
from
feat/admin-create-index-page-temp-workabout
Feb 3, 2025
Merged
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5c33007
add AdminCreateIndexPageButton
adriangohjw 96829a2
add AdminCreateIndexPageButton to layout
adriangohjw 449839b
add query to check for index page
adriangohjw 55d98b8
add query to create new index page
adriangohjw 990d8db
extract logic + refactoring
adriangohjw 3486bf4
add unit test
adriangohjw 0e2cc5b
fix - button invalidation
adriangohjw 8cceb7e
add tooltip
adriangohjw fe48f04
pass in siteId and parentId into button + fix test + improve type
adriangohjw 153721d
remove need to check for null values
adriangohjw cb3eab4
change from 500 error to 404
adriangohjw 6fe4ec6
Merge branch 'main' of https://github.com/opengovsg/isomer into feat/…
adriangohjw f8a14bb
update default content for collection
adriangohjw 8fd3184
remove the need for fullpermalink in blob
adriangohjw 2f50412
replace with useIsUserIsomerAdmin
adriangohjw c2d6c15
Merge branch 'main' of https://github.com/opengovsg/isomer into feat/…
adriangohjw 9ebd61d
fix - remove duplicated import
adriangohjw 93345cf
Merge remote-tracking branch 'origin/HEAD' into feat/admin-create-ind…
adriangohjw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
apps/studio/src/features/dashboard/components/AdminCreateIndexPageButton.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,81 @@ | ||
import { Tooltip } from "@chakra-ui/react" | ||
import { Button, useToast } from "@opengovsg/design-system-react" | ||
import { BiLogoDevTo } from "react-icons/bi" | ||
|
||
import { BRIEF_TOAST_SETTINGS } from "~/constants/toast" | ||
import { useIsUserIsomerAdmin } from "~/hooks/useIsUserIsomerAdmin" | ||
import { trpc } from "~/utils/trpc" | ||
|
||
interface AdminCreateIndexPageButtonProps { | ||
siteId: number | ||
parentId: number | ||
} | ||
export const AdminCreateIndexPageButton = ({ | ||
siteId, | ||
parentId, | ||
}: AdminCreateIndexPageButtonProps) => { | ||
const toast = useToast() | ||
const utils = trpc.useUtils() | ||
const isUserIsomerAdmin = useIsUserIsomerAdmin() | ||
|
||
const { data: indexPage } = trpc.resource.getIndexPage.useQuery({ | ||
siteId, | ||
parentId: String(parentId), | ||
}) | ||
|
||
const hasIndexPage = !!indexPage | ||
|
||
const { mutate: createIndexPage, isLoading } = | ||
trpc.page.createIndexPage.useMutation({ | ||
onSuccess: async () => { | ||
// Invalidate only the necessary queries | ||
await Promise.all([ | ||
utils.resource.getChildrenOf.invalidate({ | ||
siteId: String(siteId), | ||
resourceId: String(parentId), | ||
}), | ||
utils.resource.listWithoutRoot.invalidate({ siteId: Number(siteId) }), | ||
utils.collection.list.invalidate({ siteId: Number(siteId) }), | ||
utils.resource.getIndexPage.invalidate({ | ||
siteId, | ||
parentId: String(parentId), | ||
}), | ||
]) | ||
toast({ | ||
status: "success", | ||
title: "Index page created successfully", | ||
...BRIEF_TOAST_SETTINGS, | ||
}) | ||
}, | ||
onError: (error) => { | ||
toast({ | ||
status: "error", | ||
title: "Failed to create index page", | ||
description: error.message, | ||
...BRIEF_TOAST_SETTINGS, | ||
}) | ||
}, | ||
}) | ||
|
||
if (!isUserIsomerAdmin) return null | ||
return ( | ||
<Tooltip | ||
label={ | ||
hasIndexPage ? "Index page already exists" : "For Isomer Admins only" | ||
} | ||
placement="top" | ||
> | ||
<Button | ||
variant="outline" | ||
size="md" | ||
isDisabled={isLoading || hasIndexPage} | ||
isLoading={isLoading} | ||
onClick={() => createIndexPage({ siteId, parentId: String(parentId) })} | ||
leftIcon={<BiLogoDevTo fontSize="1rem" />} | ||
aria-label="Create index page" | ||
> | ||
Add index page | ||
</Button> | ||
</Tooltip> | ||
) | ||
} |
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note - this mimics how on-call isoengineer currently add an index page manually