Files
cal.diy/packages/features/ee/organizations/pages/settings/admin/AdminOrgEditPage.tsx
T
Benny JooandKeith Williams 853f9bc436 perf: do not import from @calcom/ui barrel file (#20184)
* Icon and IconName

* Button and ButtonGroup

* UserAvatar

* AvatarGroup

* Avatar

* WizardLayout

* Dialogs

* EmptyScreen

* showToast and TextField

* Editor

* Skeleton

* Skeleton

* TopBanner and showToast

* Button again

* more

* perf: Remove app-store reference from @calcom/ui

* more

* Fixing types

* Icon

* Fixed casing

* dropdown

* more

* Select

* more

* Badge

* List

* more

* Divider

* more

* fix

* fix type check

* refactor

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix type check

* fix

* fix

* fix

* fix

* more

* more

* more

* more

* add index file to components/command

* fix

* fix

* fix

* fix imports

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix build errors

* fix build errors

* fix

---------

Co-authored-by: Keith Williams <[email protected]>
2025-03-19 19:00:55 -03:00

85 lines
2.5 KiB
TypeScript

"use client";
import type { Team } from "@prisma/client";
import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form";
import type { z } from "zod";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import type { orgSettingsSchema } from "@calcom/prisma/zod-utils";
import { trpc } from "@calcom/trpc/react";
import { Form } from "@calcom/ui/components/form";
import { TextField } from "@calcom/ui/components/form";
import { Button } from "@calcom/ui/components/button";
import { showToast } from "@calcom/ui/components/toast";
type FormValues = {
name: Team["name"];
slug: Team["slug"];
organizationSettings: z.infer<typeof orgSettingsSchema>;
};
export const OrgForm = ({
org,
}: {
org: FormValues & {
id: Team["id"];
};
}) => {
const { t } = useLocale();
const router = useRouter();
const utils = trpc.useUtils();
const mutation = trpc.viewer.organizations.adminUpdate.useMutation({
onSuccess: async () => {
await Promise.all([
utils.viewer.organizations.adminGetAll.invalidate(),
utils.viewer.organizations.adminGet.invalidate({
id: org.id,
}),
]);
showToast(t("org_has_been_processed"), "success");
router.replace(`/settings/admin/organizations`);
},
onError: (err) => {
showToast(err.message, "error");
},
});
const form = useForm<FormValues>({
defaultValues: org,
});
const onSubmit = (values: FormValues) => {
mutation.mutate({
id: org.id,
...values,
organizationSettings: {
...org.organizationSettings,
orgAutoAcceptEmail: values.organizationSettings?.orgAutoAcceptEmail,
},
});
};
return (
<Form form={form} className="space-y-4" handleSubmit={onSubmit}>
<TextField label="Name" placeholder="example" required {...form.register("name")} />
<TextField label="Slug" placeholder="example" required {...form.register("slug")} />
<p className="text-default mt-2 text-sm">
Changing the slug would delete the previous organization domain and DNS and setup new domain and DNS
for the organization.
</p>
<TextField
label="Domain for which invitations are auto-accepted"
placeholder="abc.com"
required
{...form.register("organizationSettings.orgAutoAcceptEmail")}
/>
<Button type="submit" color="primary" loading={mutation.isPending}>
{t("save")}
</Button>
</Form>
);
};
export default OrgForm;