mirror of
https://github.com/StanGirard/quivr.git
synced 2024-09-11 13:15:41 +03:00
feat: prevent viewer to access people tab
This commit is contained in:
parent
9e8db2a844
commit
1c4332da1b
@ -24,8 +24,23 @@ export const PeopleTab = ({ brainId }: ShareBrainModalProps): JSX.Element => {
|
||||
addNewRoleAssignationRole,
|
||||
sendingInvitation,
|
||||
canAddNewRow,
|
||||
hasShareBrainRights,
|
||||
} = useShareBrain(brainId);
|
||||
|
||||
if (!hasShareBrainRights) {
|
||||
return (
|
||||
<div className="flex justify-center items-center mt-5">
|
||||
<div className="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative max-w-md">
|
||||
<strong className="font-bold mr-1">Oh no!</strong>
|
||||
<span className="block sm:inline">
|
||||
You {"don't"} have the necessary role to access this tab 🧠💡🥲.
|
||||
</span>
|
||||
<p>Please require access from the owner.</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<form
|
||||
|
@ -14,7 +14,7 @@ export const BrainUsers = ({ brainId }: BrainUsersProps): JSX.Element => {
|
||||
}
|
||||
|
||||
if (brainUsers.length === 0) {
|
||||
return <p className="text-gray-500">No brainUsers</p>;
|
||||
return <p className="text-gray-500">No user</p>;
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -7,7 +7,13 @@ import { useBrainApi } from "@/lib/api/brain/useBrainApi";
|
||||
import { useToast } from "@/lib/hooks";
|
||||
|
||||
import { generateBrainAssignation } from "../components/NavBar/components/NavItems/components/BrainsDropDown/components/BrainActions/components/ShareBrain/utils/generateBrainAssignation";
|
||||
import { BrainRoleAssignation } from "../components/NavBar/components/NavItems/components/BrainsDropDown/components/BrainActions/types";
|
||||
import {
|
||||
BrainRoleAssignation,
|
||||
BrainRoleType,
|
||||
} from "../components/NavBar/components/NavItems/components/BrainsDropDown/components/BrainActions/types";
|
||||
import { useBrainContext } from "../context/BrainProvider/hooks/useBrainContext";
|
||||
|
||||
const requiredAccessToShareBrain: BrainRoleType[] = ["Owner", "Editor"];
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
export const useShareBrain = (brainId: string) => {
|
||||
@ -23,6 +29,11 @@ export const useShareBrain = (brainId: string) => {
|
||||
const { publish } = useToast();
|
||||
const { addBrainSubscriptions } = useBrainApi();
|
||||
|
||||
const { allBrains } = useBrainContext();
|
||||
const hasShareBrainRights = requiredAccessToShareBrain.includes(
|
||||
allBrains.find((brain) => brain.id === brainId)?.role ?? "Viewer"
|
||||
);
|
||||
|
||||
const handleCopyInvitationLink = async () => {
|
||||
await navigator.clipboard.writeText(brainShareLink);
|
||||
publish({
|
||||
@ -119,5 +130,6 @@ export const useShareBrain = (brainId: string) => {
|
||||
setIsShareModalOpen,
|
||||
isShareModalOpen,
|
||||
canAddNewRow,
|
||||
hasShareBrainRights,
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user