2023-11-21 10:16:41 +00:00
|
|
|
import { Command } from "cmdk";
|
2024-01-19 10:35:52 +00:00
|
|
|
// hooks
|
2024-01-08 13:50:42 +00:00
|
|
|
import Link from "next/link";
|
2024-03-06 13:09:14 +00:00
|
|
|
import { useRouter } from "next/router";
|
2024-01-19 10:35:52 +00:00
|
|
|
// constants
|
2024-03-19 14:38:35 +00:00
|
|
|
import { EUserWorkspaceRoles, WORKSPACE_SETTINGS_LINKS } from "@/constants/workspace";
|
|
|
|
import { useUser } from "@/hooks/store";
|
2023-11-21 10:16:41 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
closePalette: () => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const CommandPaletteWorkspaceSettingsActions: React.FC<Props> = (props) => {
|
|
|
|
const { closePalette } = props;
|
2024-01-19 10:35:52 +00:00
|
|
|
// router
|
2023-11-21 10:16:41 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
2024-01-19 10:35:52 +00:00
|
|
|
// mobx store
|
|
|
|
const {
|
|
|
|
membership: { currentWorkspaceRole },
|
|
|
|
} = useUser();
|
|
|
|
// derived values
|
|
|
|
const workspaceMemberInfo = currentWorkspaceRole || EUserWorkspaceRoles.GUEST;
|
|
|
|
|
|
|
|
const redirect = (path: string) => {
|
|
|
|
closePalette();
|
|
|
|
router.push(path);
|
|
|
|
};
|
2023-11-21 10:16:41 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-01-19 10:35:52 +00:00
|
|
|
{WORKSPACE_SETTINGS_LINKS.map(
|
|
|
|
(setting) =>
|
|
|
|
workspaceMemberInfo >= setting.access && (
|
|
|
|
<Command.Item
|
|
|
|
key={setting.key}
|
|
|
|
onSelect={() => redirect(`/${workspaceSlug}${setting.href}`)}
|
|
|
|
className="focus:outline-none"
|
|
|
|
>
|
|
|
|
<Link href={`/${workspaceSlug}${setting.href}`}>
|
|
|
|
<div className="flex items-center gap-2 text-custom-text-200">
|
|
|
|
<setting.Icon className="h-4 w-4 text-custom-text-200" />
|
|
|
|
{setting.label}
|
|
|
|
</div>
|
|
|
|
</Link>
|
|
|
|
</Command.Item>
|
|
|
|
)
|
|
|
|
)}
|
2023-11-21 10:16:41 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|