[WEB-2376] dev: workspace settings improvement & refactor. (#5519)

* [WEB-2376] dev: workspace settings improvement & refactor.

* chore: update `filterWorkspaceSettingLinks` to `shouldRenderSettingLink`.
This commit is contained in:
Prateek Shourya 2024-09-04 20:21:16 +05:30 committed by GitHub
parent eea6ceaec4
commit c78b2344b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 43 additions and 18 deletions

View file

@ -1,19 +1,34 @@
import { useParams, usePathname } from "next/navigation"; import { useParams, usePathname } from "next/navigation";
// constants
import { EUserWorkspaceRoles } from "@/constants/workspace";
// hooks // hooks
import { useUser } from "@/hooks/store";
import { useAppRouter } from "@/hooks/use-app-router"; import { useAppRouter } from "@/hooks/use-app-router";
// plane web constants // plane web constants
import { WORKSPACE_SETTINGS_LINKS } from "@/plane-web/constants/workspace"; import { WORKSPACE_SETTINGS_LINKS } from "@/plane-web/constants/workspace";
// plane web helpers
import { shouldRenderSettingLink } from "@/plane-web/helpers/workspace.helper";
export const MobileWorkspaceSettingsTabs = () => { export const MobileWorkspaceSettingsTabs = () => {
const router = useAppRouter(); const router = useAppRouter();
const { workspaceSlug } = useParams(); const { workspaceSlug } = useParams();
const pathname = usePathname(); const pathname = usePathname();
// mobx store
const {
membership: { currentWorkspaceRole },
} = useUser();
// derived values
const workspaceMemberInfo = currentWorkspaceRole || EUserWorkspaceRoles.GUEST;
return ( return (
<div className="flex-shrink-0 md:hidden sticky inset-0 flex overflow-x-auto bg-custom-background-100 z-10"> <div className="flex-shrink-0 md:hidden sticky inset-0 flex overflow-x-auto bg-custom-background-100 z-10">
{WORKSPACE_SETTINGS_LINKS.map((item, index) => ( {WORKSPACE_SETTINGS_LINKS.map(
(item, index) =>
shouldRenderSettingLink(item.key) &&
workspaceMemberInfo >= item.access && (
<div <div
className={`${ className={`${item.highlight(pathname, `/${workspaceSlug}`)
item.highlight(pathname, `/${workspaceSlug}`)
? "text-custom-primary-100 text-sm py-2 px-3 whitespace-nowrap flex flex-grow cursor-pointer justify-around border-b border-custom-primary-200" ? "text-custom-primary-100 text-sm py-2 px-3 whitespace-nowrap flex flex-grow cursor-pointer justify-around border-b border-custom-primary-200"
: "text-custom-text-200 flex flex-grow cursor-pointer justify-around border-b border-custom-border-200 text-sm py-2 px-3 whitespace-nowrap" : "text-custom-text-200 flex flex-grow cursor-pointer justify-around border-b border-custom-border-200 text-sm py-2 px-3 whitespace-nowrap"
}`} }`}
@ -22,7 +37,8 @@ export const MobileWorkspaceSettingsTabs = () => {
> >
{item.label} {item.label}
</div> </div>
))} )
)}
</div> </div>
); );
}; };

View file

@ -12,6 +12,8 @@ import { EUserWorkspaceRoles } from "@/constants/workspace";
import { useUser } from "@/hooks/store"; import { useUser } from "@/hooks/store";
// plane web constants // plane web constants
import { WORKSPACE_SETTINGS_LINKS } from "@/plane-web/constants/workspace"; import { WORKSPACE_SETTINGS_LINKS } from "@/plane-web/constants/workspace";
// plane web helpers
import { shouldRenderSettingLink } from "@/plane-web/helpers/workspace.helper";
export const WorkspaceSettingsSidebar = observer(() => { export const WorkspaceSettingsSidebar = observer(() => {
// router // router
@ -22,6 +24,7 @@ export const WorkspaceSettingsSidebar = observer(() => {
membership: { currentWorkspaceRole }, membership: { currentWorkspaceRole },
} = useUser(); } = useUser();
// derived values
const workspaceMemberInfo = currentWorkspaceRole || EUserWorkspaceRoles.GUEST; const workspaceMemberInfo = currentWorkspaceRole || EUserWorkspaceRoles.GUEST;
return ( return (
@ -31,6 +34,7 @@ export const WorkspaceSettingsSidebar = observer(() => {
<div className="flex w-full flex-col gap-1"> <div className="flex w-full flex-col gap-1">
{WORKSPACE_SETTINGS_LINKS.map( {WORKSPACE_SETTINGS_LINKS.map(
(link) => (link) =>
shouldRenderSettingLink(link.key) &&
workspaceMemberInfo >= link.access && ( workspaceMemberInfo >= link.access && (
<Link key={link.key} href={`/${workspaceSlug}${link.href}`}> <Link key={link.key} href={`/${workspaceSlug}${link.href}`}>
<SidebarNavItem <SidebarNavItem

View file

@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const shouldRenderSettingLink = (settingKey: string) => true;

View file

@ -11,6 +11,8 @@ import { useUser } from "@/hooks/store";
import { useAppRouter } from "@/hooks/use-app-router"; import { useAppRouter } from "@/hooks/use-app-router";
// plane wev constants // plane wev constants
import { WORKSPACE_SETTINGS_LINKS } from "@/plane-web/constants/workspace"; import { WORKSPACE_SETTINGS_LINKS } from "@/plane-web/constants/workspace";
// plane web helpers
import { shouldRenderSettingLink } from "@/plane-web/helpers/workspace.helper";
type Props = { type Props = {
closePalette: () => void; closePalette: () => void;
@ -38,7 +40,8 @@ export const CommandPaletteWorkspaceSettingsActions: React.FC<Props> = (props) =
<> <>
{WORKSPACE_SETTINGS_LINKS.map( {WORKSPACE_SETTINGS_LINKS.map(
(setting) => (setting) =>
workspaceMemberInfo >= setting.access && ( workspaceMemberInfo >= setting.access &&
shouldRenderSettingLink(setting.key) && (
<Command.Item <Command.Item
key={setting.key} key={setting.key}
onSelect={() => redirect(`/${workspaceSlug}${setting.href}`)} onSelect={() => redirect(`/${workspaceSlug}${setting.href}`)}

View file

@ -15,7 +15,6 @@ const initializeStore = () => {
return newRootStore; return newRootStore;
}; };
export const StoreProvider = ({ children }: { children: ReactElement }) => { export const store = initializeStore();
const store = initializeStore();
return <StoreContext.Provider value={store}>{children}</StoreContext.Provider>; export const StoreProvider = ({ children }: { children: ReactElement }) => <StoreContext.Provider value={store}>{children}</StoreContext.Provider>;
};

View file

@ -0,0 +1 @@
export * from "ce/helpers/workspace.helper";