From b8a0d9a018afe337641c67fd7508b26c527738b5 Mon Sep 17 00:00:00 2001 From: Gobot1234 Date: Mon, 15 Apr 2024 21:44:31 +0100 Subject: [PATCH 1/2] fix: commands being broken --- .../src/components/command-menu/index.tsx | 117 ++++++------------ 1 file changed, 39 insertions(+), 78 deletions(-) diff --git a/apps/forge/src/components/command-menu/index.tsx b/apps/forge/src/components/command-menu/index.tsx index 204d08f..6eab5af 100644 --- a/apps/forge/src/components/command-menu/index.tsx +++ b/apps/forge/src/components/command-menu/index.tsx @@ -1,3 +1,4 @@ +import { useUser } from "@/lib/utils"; import { RootState } from "@/redux/store"; import { useNavigate } from "@tanstack/react-router"; import { @@ -11,13 +12,7 @@ import { CommandSeparator, CommandShortcut, } from "@ui/components/ui/command"; -import { - UserRoundSearch, - LayoutDashboard, - LogIn, - LogOut, - Settings, -} from "lucide-react"; +import { LayoutDashboard, LogIn, LogOut, Settings, UserRound, UserRoundSearch } from "lucide-react"; import React, { ReactElement } from "react"; import { useSelector } from "react-redux"; @@ -39,44 +34,16 @@ export default function CommandMenu() { return () => document.removeEventListener("keydown", down); }, [isMacOs]); - const SETTINGS_SHORTCUTS: Record any, string, ReactElement]> = - { - // p: [ - // () => navigate({ to: "/user/profile" }), - // "Profile", - // , - // ], - s: [ - () => navigate({ to: "/user/settings" }), - "Settings", - , - ], - }; + const SETTINGS_SHORTCUTS: Record any, string, ReactElement]> = { + p: [() => navigate({ to: "/user/profile" }), "Profile", ], + s: [() => navigate({ to: "/user/settings" }), "Settings", ], + }; - const USER_MANAGEMENT_SHORTCUTS: Record< - string, - [() => any, string, ReactElement] - > = { - d: [ - () => navigate({ to: "/signin/dashboard" }), - "Dashboard", - , - ], - u: [ - () => navigate({ to: "/users" }), - "Search users", - , - ], - i: [ - () => navigate({ to: "/signin/actions" }), - "Sign in", - , - ], - o: [ - () => navigate({ to: "/signin/actions" }), - "Sign out", - , - ], + const USER_MANAGEMENT_SHORTCUTS: Record any, string, ReactElement]> = { + d: [() => navigate({ to: "/signin/dashboard" }), "Dashboard", ], + u: [() => navigate({ to: "/users" }), "Search users", ], + i: [() => navigate({ to: "/signin/actions" }), "Sign in", ], + o: [() => navigate({ to: "/signin/actions" }), "Sign out", ], }; const SHORTCUTS = { ...SETTINGS_SHORTCUTS, ...USER_MANAGEMENT_SHORTCUTS }; @@ -84,14 +51,17 @@ export default function CommandMenu() { React.useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (isMacOs ? e.metaKey : e.ctrlKey) { - e.preventDefault(); - SHORTCUTS[e.key]?.[0](); + const shortcut = SHORTCUTS[e.key]; + if (shortcut !== undefined) { + e.preventDefault(); + shortcut[0](); + } } }; document.addEventListener("keydown", handleKeyDown); return () => document.removeEventListener("keydown", handleKeyDown); - }, [navigate, isMacOs]); + }, []); const groups = new Map(); @@ -99,44 +69,35 @@ export default function CommandMenu() { groups.set("Settings", SETTINGS_SHORTCUTS); } - // if (useSelector((state: RootState) => state.auth.is_authenticated)) { - // groups.set("User Management", USER_MANAGEMENT_SHORTCUTS); - // } + if (useUser()?.roles.some((role) => role.name === "Rep")) { + groups.set("User Management", USER_MANAGEMENT_SHORTCUTS); + } - // XXX this doesn't work for some reason return ( No results found. - {Object.entries(groups).flatMap( - ([name, shortcuts]: [string, typeof SHORTCUTS], index, array) => { - const group = ( - - {Object.entries(shortcuts).map( - ([key, [callback, name, icon]]) => { - return ( - - {icon} - {name} - - {metaKey} - {key.toUpperCase()} - - - ); - } - )} - - ); - // console.log(group); - - return index < array.length - 1 - ? [group, ] - : [group]; - } - )} + {[...groups].flatMap(([name, shortcuts]: [string, typeof SHORTCUTS], index, array) => { + const group = ( + + {Object.entries(shortcuts).map(([key, [callback, name, icon]]) => { + return ( + + {icon} + {name} + + {metaKey} + {key.toUpperCase()} + + + ); + })} + + ); + return index < array.length - 1 ? [group, ] : [group]; + })} From 641b2dee9530cfdbbc781d96cbb77bfcef59adfc Mon Sep 17 00:00:00 2001 From: Gobot1234 Date: Mon, 15 Apr 2024 21:44:49 +0100 Subject: [PATCH 2/2] feat: more 1pass autocomplete turnings off --- apps/forge/src/components/signin/actions/UCardInput/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/forge/src/components/signin/actions/UCardInput/index.tsx b/apps/forge/src/components/signin/actions/UCardInput/index.tsx index 4b695f1..620280a 100644 --- a/apps/forge/src/components/signin/actions/UCardInput/index.tsx +++ b/apps/forge/src/components/signin/actions/UCardInput/index.tsx @@ -52,6 +52,8 @@ const UCardInput: FlowStepComponent = ({ onPrimary }) => { onChange={(value) => handleOtpChange(value)} onComplete={() => handleOnSubmit()} ref={firstInputRef} + type="search" // I think this turns off 1password autocomplete which gets in the way of our actual auto-complete + autoComplete="off" // so does this >