Skip to content
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

fix: pages access #754

Merged
merged 7 commits into from
Apr 11, 2023
62 changes: 29 additions & 33 deletions apps/app/components/pages/single-page-detailed-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React from "react";

import Link from "next/link";
import { useRouter } from "next/router";
import dynamic from "next/dynamic";

// hooks
import useUser from "hooks/use-user";
// ui
import { CustomMenu, Loader, Tooltip } from "components/ui";
import { CustomMenu, Tooltip } from "components/ui";
// icons
import {
LockClosedIcon,
Expand All @@ -29,15 +30,6 @@ type TSingleStatProps = {
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> = ({
page,
handleEditPage,
Expand All @@ -49,6 +41,8 @@ export const SinglePageDetailedItem: React.FC<TSingleStatProps> = ({
const router = useRouter();
const { workspaceSlug, projectId } = router.query;

const { user } = useUser();

return (
<div className="relative first:rounded-t last:rounded-b border">
<Link href={`/${workspaceSlug}/projects/${projectId}/pages/${page.id}`}>
Expand Down Expand Up @@ -106,29 +100,31 @@ export const SinglePageDetailedItem: React.FC<TSingleStatProps> = ({
<StarIcon className="h-4 w-4 " color="#858E96" />
</button>
)}
<Tooltip
tooltipContent={`${
page.access
? "This page is only visible to you."
: "This page can be viewed by anyone in the project."
}`}
theme="dark"
>
<button
type="button"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
partialUpdatePage(page, { access: page.access ? 0 : 1 });
}}
{page.created_by === user?.id && (
<Tooltip
tooltipContent={`${
page.access
? "This page is only visible to you."
: "This page can be viewed by anyone in the project."
}`}
theme="dark"
>
{page.access ? (
<LockClosedIcon className="h-4 w-4" color="#858e96" />
) : (
<LockOpenIcon className="h-4 w-4" color="#858e96" />
)}
</button>
</Tooltip>
<button
type="button"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
partialUpdatePage(page, { access: page.access ? 0 : 1 });
}}
>
{page.access ? (
<LockClosedIcon className="h-4 w-4" color="#858e96" />
) : (
<LockOpenIcon className="h-4 w-4" color="#858e96" />
)}
</button>
</Tooltip>
)}
<CustomMenu verticalEllipsis>
<CustomMenu.MenuItem
onClick={(e: any) => {
Expand Down
51 changes: 29 additions & 22 deletions apps/app/components/pages/single-page-list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React from "react";
import Link from "next/link";
import { useRouter } from "next/router";

// hooks
import useUser from "hooks/use-user";
// ui
import { CustomMenu, Tooltip } from "components/ui";
// icons
Expand Down Expand Up @@ -40,6 +42,8 @@ export const SinglePageListItem: React.FC<TSingleStatProps> = ({
const router = useRouter();
const { workspaceSlug, projectId } = router.query;

const { user } = useUser();

return (
<li>
<Link href={`/${workspaceSlug}/projects/${projectId}/pages/${page.id}`}>
Expand Down Expand Up @@ -103,29 +107,32 @@ export const SinglePageListItem: React.FC<TSingleStatProps> = ({
<StarIcon className="h-4 w-4 " color="#858e96" />
</button>
)}
<Tooltip
tooltipContent={`${
page.access
? "This page is only visible to you."
: "This page can be viewed by anyone in the project."
}`}
theme="dark"
>
<button
type="button"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
partialUpdatePage(page, { access: page.access ? 0 : 1 });
}}
{page.created_by === user?.id && (
<Tooltip
tooltipContent={`${
page.access
? "This page is only visible to you."
: "This page can be viewed by anyone in the project."
}`}
theme="dark"
>
{page.access ? (
<LockClosedIcon className="h-4 w-4" color="#858e96" />
) : (
<LockOpenIcon className="h-4 w-4" color="#858e96" />
)}
</button>
</Tooltip>
<button
type="button"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
partialUpdatePage(page, { access: page.access ? 0 : 1 });
}}
>
{page.access ? (
<LockClosedIcon className="h-4 w-4" color="#858e96" />
) : (
<LockOpenIcon className="h-4 w-4" color="#858e96" />
)}
</button>
</Tooltip>
)}

<CustomMenu width="auto" verticalEllipsis>
<CustomMenu.MenuItem
onClick={(e: any) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/app/components/workspace/sidebar-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export const WorkspaceSidebarDropdown = () => {
})
)
.finally(() => {
mutateUser();
router.push("/signin");
mutateUser();
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import pagesService from "services/pages.service";
import issuesService from "services/issues.service";
// hooks
import useToast from "hooks/use-toast";
import useUser from "hooks/use-user";
// layouts
import { ProjectAuthorizationWrapper } from "layouts/auth-layout";
// components
Expand Down Expand Up @@ -61,6 +62,8 @@ const SinglePage: NextPage = () => {

const { setToastAlert } = useToast();

const { user } = useUser();

const { handleSubmit, reset, watch, setValue } = useForm<IPage>({
defaultValues: { name: "" },
});
Expand Down Expand Up @@ -411,18 +414,22 @@ const SinglePage: NextPage = () => {
)}
</Popover>
</div>
{pageDetails.access ? (
<button onClick={() => partialUpdatePage({ access: 0 })} className="z-10">
<LockClosedIcon className="h-4 w-4" />
</button>
) : (
<button
onClick={() => partialUpdatePage({ access: 1 })}
type="button"
className="z-10"
>
<LockOpenIcon className="h-4 w-4" />
</button>
{pageDetails.created_by === user?.id && (
<>
{pageDetails.access ? (
<button onClick={() => partialUpdatePage({ access: 0 })} className="z-10">
<LockClosedIcon className="h-4 w-4" />
</button>
) : (
<button
onClick={() => partialUpdatePage({ access: 1 })}
type="button"
className="z-10"
>
<LockOpenIcon className="h-4 w-4" />
</button>
)}
</>
)}
{pageDetails.is_favorite ? (
<button onClick={handleRemoveFromFavorites} className="z-10">
Expand Down