chore: app sidebar quick action permission validation added

This commit is contained in:
Anmol Singh Bhatia 2023-12-13 20:32:39 +05:30
parent 0f892d4670
commit 13d7832d35

View File

@ -10,6 +10,8 @@ import { CreateUpdateDraftIssueModal } from "components/issues";
import { useMobxStore } from "lib/mobx/store-provider"; import { useMobxStore } from "lib/mobx/store-provider";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { EProjectStore } from "store/command-palette.store"; import { EProjectStore } from "store/command-palette.store";
// constants
import { EUserWorkspaceRoles } from "constants/workspace";
export const WorkspaceSidebarQuickAction = observer(() => { export const WorkspaceSidebarQuickAction = observer(() => {
// states // states
@ -19,12 +21,15 @@ export const WorkspaceSidebarQuickAction = observer(() => {
theme: themeStore, theme: themeStore,
commandPalette: commandPaletteStore, commandPalette: commandPaletteStore,
trackEvent: { setTrackElement }, trackEvent: { setTrackElement },
user: { currentWorkspaceRole },
} = useMobxStore(); } = useMobxStore();
const { storedValue, clearValue } = useLocalStorage<any>("draftedIssue", JSON.stringify({})); const { storedValue, clearValue } = useLocalStorage<any>("draftedIssue", JSON.stringify({}));
const isSidebarCollapsed = themeStore.sidebarCollapsed; const isSidebarCollapsed = themeStore.sidebarCollapsed;
const isAuthorizedUser = !!currentWorkspaceRole && currentWorkspaceRole >= EUserWorkspaceRoles.MEMBER;
return ( return (
<> <>
<CreateUpdateDraftIssueModal <CreateUpdateDraftIssueModal
@ -42,6 +47,7 @@ export const WorkspaceSidebarQuickAction = observer(() => {
isSidebarCollapsed ? "flex-col gap-1" : "gap-2" isSidebarCollapsed ? "flex-col gap-1" : "gap-2"
}`} }`}
> >
{isAuthorizedUser && (
<div <div
className={`group relative flex w-full cursor-pointer items-center justify-between gap-1 rounded px-2 ${ className={`group relative flex w-full cursor-pointer items-center justify-between gap-1 rounded px-2 ${
isSidebarCollapsed isSidebarCollapsed
@ -65,7 +71,9 @@ export const WorkspaceSidebarQuickAction = observer(() => {
{storedValue && Object.keys(JSON.parse(storedValue)).length > 0 && ( {storedValue && Object.keys(JSON.parse(storedValue)).length > 0 && (
<> <>
<div className={`h-8 w-0.5 bg-custom-sidebar-background-80 ${isSidebarCollapsed ? "hidden" : "block"}`} /> <div
className={`h-8 w-0.5 bg-custom-sidebar-background-80 ${isSidebarCollapsed ? "hidden" : "block"}`}
/>
<button <button
type="button" type="button"
@ -94,9 +102,12 @@ export const WorkspaceSidebarQuickAction = observer(() => {
</> </>
)} )}
</div> </div>
)}
<button <button
className={`flex flex-shrink-0 items-center justify-center rounded p-2 outline-none ${ className={`flex flex-shrink-0 items-center rounded p-2 gap-2 outline-none ${
isAuthorizedUser ? "justify-center" : "w-full"
} ${
isSidebarCollapsed isSidebarCollapsed
? "hover:bg-custom-sidebar-background-80" ? "hover:bg-custom-sidebar-background-80"
: "border-[0.5px] border-custom-border-200 shadow-custom-sidebar-shadow-2xs" : "border-[0.5px] border-custom-border-200 shadow-custom-sidebar-shadow-2xs"
@ -104,6 +115,7 @@ export const WorkspaceSidebarQuickAction = observer(() => {
onClick={() => commandPaletteStore.toggleCommandPaletteModal(true)} onClick={() => commandPaletteStore.toggleCommandPaletteModal(true)}
> >
<Search className="h-4 w-4 text-custom-sidebar-text-300" /> <Search className="h-4 w-4 text-custom-sidebar-text-300" />
<span className="text-xs font-medium">Open command menu</span>
</button> </button>
</div> </div>
</> </>