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 } }) => {
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.dismiss();
toast.success("NavItem deleted successfully!");
},
+ onError: () => {
+ toast.dismiss();
+ toast.error("Error deleting NavItem");
+ },
});
return (
@@ -79,12 +85,16 @@ export function NavItemsManager({ navItems }: NavItemsManagerProps) {
name={item.name}
/>
-
-
+
+
+
+
+
+ );
+}
+
+interface EditNavItemDialogProps {
+ existingName: string;
+ existingUrl: string;
+ existingEnabled: boolean;
+}
+
+function EditNavItemDialog({
+ existingName,
+ existingUrl,
+ existingEnabled,
+}: EditNavItemDialogProps) {
+ const [name, setName] = useState(existingName);
+ const [url, setUrl] = useState(existingUrl);
+ const [open, setOpen] = useState(false);
+
+ const { execute, status: editStatus } = useAction(editItem, {
+ onSuccess: () => {
+ console.log("Success");
+ setOpen(false);
+ toast.success("NavItem edited successfully!");
+ },
+ onError: () => {
+ toast.error("Error editing NavItem");
+ },
+ });
+ const isLoading = editStatus === "executing";
+
+ return (
+