Skip to main content
Glama

Storyden

by Southclaws
Mozilla Public License 2.0
229
useRoleEdit.ts2.02 kB
import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import { useSWRConfig } from "swr"; import { z } from "zod"; import { handle } from "@/api/client"; import { getRoleListKey, roleDelete, roleUpdate, } from "@/api/openapi-client/roles"; import { Role } from "@/api/openapi-schema"; import { PermissionSchema } from "@/lib/permission/permission"; export type Props = { role: Role; onSave?: () => void; }; export const FormSchema = z.object({ name: z.string(), colour: z.string(), permissions: z.array(PermissionSchema), }); export type Form = z.infer<typeof FormSchema>; export function useRoleEditScreen({ role, onSave }: Props) { const { mutate } = useSWRConfig(); const form = useForm<Form>({ defaultValues: role, resolver: zodResolver(FormSchema), }); const revalidate = async () => { await mutate(getRoleListKey()); }; const handleSave = form.handleSubmit(async (data) => { await handle( async () => { await roleUpdate(role.id, data); onSave?.(); }, { promiseToast: { loading: "Saving...", success: "Saved!", }, async cleanup() { await revalidate(); }, }, ); }); async function handleDelete() { await handle( async () => { await roleDelete(role.id); }, { promiseToast: { loading: "Deleting...", success: "Deleted!", }, async cleanup() { await revalidate(); }, }, ); } async function handleReset() { await handle( async () => { await roleDelete(role.id); }, { promiseToast: { loading: "Resetting...", success: "Reset to defaults!", }, async cleanup() { await revalidate(); }, }, ); } return { form, handlers: { handleSave, handleDelete, handleReset, }, }; }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Southclaws/storyden'

If you have feedback or need assistance with the MCP directory API, please join our Discord server