import { Button } from "@/src/components/ui/button"; import { Input } from "@/src/components/ui/input"; import { api } from "@/src/utils/api"; import type * as z from "zod/v4"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import { Form, FormControl, FormField, FormItem, FormMessage, } from "@/src/components/ui/form"; import { projectNameSchema } from "@/src/features/auth/lib/projectNameSchema"; import Header from "@/src/components/layouts/header"; import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture"; import { useHasOrganizationAccess } from "@/src/features/rbac/utils/checkOrganizationAccess"; import { useQueryOrganization } from "@/src/features/organizations/hooks"; import { Card } from "@/src/components/ui/card"; import { LockIcon } from "lucide-react"; import { useSession } from "next-auth/react"; export default function RenameOrganization() { const { update: updateSession } = useSession(); const capture = usePostHogClientCapture(); const organization = useQueryOrganization(); const hasAccess = useHasOrganizationAccess({ organizationId: organization?.id, scope: "organization:update", }); const orgName = organization && "name" in organization ? organization.name : ""; const form = useForm({ resolver: zodResolver(projectNameSchema), defaultValues: { name: "", }, }); const renameOrganization = api.organizations.update.useMutation({ onSuccess: () => { void updateSession(); }, onError: (error) => form.setError("name", { message: error.message }), }); function onSubmit(values: z.infer) { if (!organization || !hasAccess) return; capture("organization_settings:rename_form_submit"); renameOrganization .mutateAsync({ orgId: organization.id, name: values.name, }) .then(() => { form.reset(); }) .catch((error) => { console.error(error); }); } return (
{form.getValues().name !== "" ? (

Your Organization will be renamed from " {orgName} " to " {form.watch().name}".

) : (

Your Organization is currently named "{orgName} ".

)}
(
{!hasAccess && ( )}
)} /> {hasAccess && ( )}
); }