From 56770e3b6c372337754ea1c2962b0e3db2d89169 Mon Sep 17 00:00:00 2001
From: Matthew <92887765+mjanderson1227@users.noreply.github.com>
Date: Thu, 26 Dec 2024 14:20:28 -0600
Subject: [PATCH 1/4] Created a new action for editing navigation items
---
apps/web/src/actions/admin/modify-nav-item.ts | 29 ++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/apps/web/src/actions/admin/modify-nav-item.ts b/apps/web/src/actions/admin/modify-nav-item.ts
index 5dc3a48e..740aacb7 100644
--- a/apps/web/src/actions/admin/modify-nav-item.ts
+++ b/apps/web/src/actions/admin/modify-nav-item.ts
@@ -7,7 +7,12 @@ import { revalidatePath } from "next/cache";
const metadataSchema = z.object({
name: z.string().min(1),
- url: z.string(),
+ url: z.string().min(1),
+});
+
+const editMetadataSchema = metadataSchema.extend({
+ existingName: z.string().min(1),
+ enabled: z.boolean(),
});
// Maybe a better way to do this for revalidation? Who knows.
@@ -26,6 +31,28 @@ export const setItem = adminAction
return { success: true };
});
+export const editItem = adminAction
+ .schema(editMetadataSchema)
+ .action(async ({ parsedInput: { name, url, existingName } }) => {
+ const pipe = kv.pipeline();
+
+ if (existingName != name) {
+ pipe.srem("config:navitemslist", encodeURIComponent(existingName));
+ }
+
+ pipe.sadd("config:navitemslist", encodeURIComponent(name));
+ pipe.hset(`config:navitems:${encodeURIComponent(name)}`, {
+ url,
+ name,
+ enabled: true,
+ });
+
+ await pipe.exec();
+
+ revalidatePath(navAdminPage);
+ return { success: true };
+ });
+
export const removeItem = adminAction
.schema(z.string())
.action(async ({ parsedInput: name, ctx: { user, userId } }) => {
From 1ba817e19215646f550daf7ab7ef7e844c8c686d Mon Sep 17 00:00:00 2001
From: Matthew <92887765+mjanderson1227@users.noreply.github.com>
Date: Thu, 26 Dec 2024 14:21:42 -0600
Subject: [PATCH 2/4] Adds ability to edit navigation items from the admin
dashboard
---
.../src/app/admin/toggles/landing/page.tsx | 4 +-
.../admin/toggles/NavItemsManager.tsx | 110 +++++++++++++++++-
2 files changed, 107 insertions(+), 7 deletions(-)
diff --git a/apps/web/src/app/admin/toggles/landing/page.tsx b/apps/web/src/app/admin/toggles/landing/page.tsx
index 3cc22a64..7d47f644 100644
--- a/apps/web/src/app/admin/toggles/landing/page.tsx
+++ b/apps/web/src/app/admin/toggles/landing/page.tsx
@@ -1,6 +1,6 @@
import {
NavItemsManager,
- NavItemDialog,
+ AddNavItemDialog,
} from "@/components/admin/toggles/NavItemsManager";
import { getAllNavItems } from "@/lib/utils/server/redis";
@@ -13,7 +13,7 @@ export default async function Page() {
Navbar Items
{
toast.success("NavItem deleted successfully!");
},
+ onError: () => {
+ toast.error("Error deleting NavItem");
+ },
});
return (
@@ -79,10 +83,12 @@ export function NavItemsManager({ navItems }: NavItemsManagerProps) {
name={item.name}
/>
-
-
+
+