fix: pages access (#754)

* fix: dashboard workspace activity mutation

* fix: page access operation
This commit is contained in:
Aaryan Khandelwal 2023-04-11 12:10:22 +05:30 committed by GitHub
parent f2c5bb5c03
commit 7aa0ace555
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 68 deletions

View File

@ -2,10 +2,11 @@ import React from "react";
import Link from "next/link"; import Link from "next/link";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import dynamic from "next/dynamic";
// hooks
import useUser from "hooks/use-user";
// ui // ui
import { CustomMenu, Loader, Tooltip } from "components/ui"; import { CustomMenu, Tooltip } from "components/ui";
// icons // icons
import { import {
LockClosedIcon, LockClosedIcon,
@ -29,15 +30,6 @@ type TSingleStatProps = {
partialUpdatePage: (page: IPage, formData: Partial<IPage>) => void; partialUpdatePage: (page: IPage, formData: Partial<IPage>) => void;
}; };
const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor"), {
ssr: false,
loading: () => (
<Loader className="p-4">
<Loader.Item height="100px" width="100%" />
</Loader>
),
});
export const SinglePageDetailedItem: React.FC<TSingleStatProps> = ({ export const SinglePageDetailedItem: React.FC<TSingleStatProps> = ({
page, page,
handleEditPage, handleEditPage,
@ -49,6 +41,8 @@ export const SinglePageDetailedItem: React.FC<TSingleStatProps> = ({
const router = useRouter(); const router = useRouter();
const { workspaceSlug, projectId } = router.query; const { workspaceSlug, projectId } = router.query;
const { user } = useUser();
return ( return (
<div className="relative first:rounded-t last:rounded-b border"> <div className="relative first:rounded-t last:rounded-b border">
<Link href={`/${workspaceSlug}/projects/${projectId}/pages/${page.id}`}> <Link href={`/${workspaceSlug}/projects/${projectId}/pages/${page.id}`}>
@ -106,6 +100,7 @@ export const SinglePageDetailedItem: React.FC<TSingleStatProps> = ({
<StarIcon className="h-4 w-4 " color="#858E96" /> <StarIcon className="h-4 w-4 " color="#858E96" />
</button> </button>
)} )}
{page.created_by === user?.id && (
<Tooltip <Tooltip
tooltipContent={`${ tooltipContent={`${
page.access page.access
@ -129,6 +124,7 @@ export const SinglePageDetailedItem: React.FC<TSingleStatProps> = ({
)} )}
</button> </button>
</Tooltip> </Tooltip>
)}
<CustomMenu verticalEllipsis> <CustomMenu verticalEllipsis>
<CustomMenu.MenuItem <CustomMenu.MenuItem
onClick={(e: any) => { onClick={(e: any) => {

View File

@ -3,6 +3,8 @@ import React from "react";
import Link from "next/link"; import Link from "next/link";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
// hooks
import useUser from "hooks/use-user";
// ui // ui
import { CustomMenu, Tooltip } from "components/ui"; import { CustomMenu, Tooltip } from "components/ui";
// icons // icons
@ -40,6 +42,8 @@ export const SinglePageListItem: React.FC<TSingleStatProps> = ({
const router = useRouter(); const router = useRouter();
const { workspaceSlug, projectId } = router.query; const { workspaceSlug, projectId } = router.query;
const { user } = useUser();
return ( return (
<li> <li>
<Link href={`/${workspaceSlug}/projects/${projectId}/pages/${page.id}`}> <Link href={`/${workspaceSlug}/projects/${projectId}/pages/${page.id}`}>
@ -103,6 +107,7 @@ export const SinglePageListItem: React.FC<TSingleStatProps> = ({
<StarIcon className="h-4 w-4 " color="#858e96" /> <StarIcon className="h-4 w-4 " color="#858e96" />
</button> </button>
)} )}
{page.created_by === user?.id && (
<Tooltip <Tooltip
tooltipContent={`${ tooltipContent={`${
page.access page.access
@ -126,6 +131,8 @@ export const SinglePageListItem: React.FC<TSingleStatProps> = ({
)} )}
</button> </button>
</Tooltip> </Tooltip>
)}
<CustomMenu width="auto" verticalEllipsis> <CustomMenu width="auto" verticalEllipsis>
<CustomMenu.MenuItem <CustomMenu.MenuItem
onClick={(e: any) => { onClick={(e: any) => {

View File

@ -77,8 +77,8 @@ export const WorkspaceSidebarDropdown = () => {
}) })
) )
.finally(() => { .finally(() => {
mutateUser();
router.push("/signin"); router.push("/signin");
mutateUser();
}); });
}; };

View File

@ -19,6 +19,7 @@ import pagesService from "services/pages.service";
import issuesService from "services/issues.service"; import issuesService from "services/issues.service";
// hooks // hooks
import useToast from "hooks/use-toast"; import useToast from "hooks/use-toast";
import useUser from "hooks/use-user";
// layouts // layouts
import { ProjectAuthorizationWrapper } from "layouts/auth-layout"; import { ProjectAuthorizationWrapper } from "layouts/auth-layout";
// components // components
@ -61,6 +62,8 @@ const SinglePage: NextPage = () => {
const { setToastAlert } = useToast(); const { setToastAlert } = useToast();
const { user } = useUser();
const { handleSubmit, reset, watch, setValue } = useForm<IPage>({ const { handleSubmit, reset, watch, setValue } = useForm<IPage>({
defaultValues: { name: "" }, defaultValues: { name: "" },
}); });
@ -411,6 +414,8 @@ const SinglePage: NextPage = () => {
)} )}
</Popover> </Popover>
</div> </div>
{pageDetails.created_by === user?.id && (
<>
{pageDetails.access ? ( {pageDetails.access ? (
<button onClick={() => partialUpdatePage({ access: 0 })} className="z-10"> <button onClick={() => partialUpdatePage({ access: 0 })} className="z-10">
<LockClosedIcon className="h-4 w-4" /> <LockClosedIcon className="h-4 w-4" />
@ -424,6 +429,8 @@ const SinglePage: NextPage = () => {
<LockOpenIcon className="h-4 w-4" /> <LockOpenIcon className="h-4 w-4" />
</button> </button>
)} )}
</>
)}
{pageDetails.is_favorite ? ( {pageDetails.is_favorite ? (
<button onClick={handleRemoveFromFavorites} className="z-10"> <button onClick={handleRemoveFromFavorites} className="z-10">
<StarIcon className="h-4 w-4 text-orange-400" fill="#f6ad55" /> <StarIcon className="h-4 w-4 text-orange-400" fill="#f6ad55" />