"use client"; import { useForm } from "react-hook-form"; import { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner"; import SectionBottomActions from "@calcom/features/settings/SectionBottomActions"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { RRResetInterval, RRTimestampBasis } from "@calcom/prisma/enums"; import type { RouterOutputs } from "@calcom/trpc/react"; import { trpc } from "@calcom/trpc/react"; import { Button } from "@calcom/ui/components/button"; import { Form } from "@calcom/ui/components/form"; import { showToast } from "@calcom/ui/components/toast"; import { revalidateTeamDataCache } from "@calcom/web/app/(booking-page-wrapper)/team/[slug]/[type]/actions"; import RoundRobinResetInterval from "./RoundRobinResetInterval"; import RoundRobinTimestampBasis from "./RoundRobinTimestampBasis"; interface RoundRobinSettingsProps { team: RouterOutputs["viewer"]["teams"]["get"]; } const RoundRobinSettings = ({ team }: RoundRobinSettingsProps) => { const { t } = useLocale(); const isAdmin = team && checkAdminOrOwner(team.membership.role); const rrResetInterval = team?.rrResetInterval ?? undefined; const utils = trpc.useUtils(); const initialResetInterval = rrResetInterval ?? RRResetInterval.MONTH; const initialTimestampBasis = team?.rrTimestampBasis ?? RRTimestampBasis.CREATED_AT; const form = useForm<{ rrResetInterval: RRResetInterval; rrTimestampBasis: RRTimestampBasis }>({ defaultValues: { rrResetInterval: initialResetInterval, rrTimestampBasis: initialTimestampBasis, }, }); const [watchedResetInterval, watchedTimestampBasis] = form.watch(["rrResetInterval", "rrTimestampBasis"]); const hasChanges = watchedResetInterval !== initialResetInterval || watchedTimestampBasis !== initialTimestampBasis; const mutation = trpc.viewer.teams.update.useMutation({ onError: (err) => { showToast(err.message, "error"); }, async onSuccess() { await utils.viewer.teams.get.invalidate(); if (team?.slug) { // Rounb robin reset interval / basis governs host selection logic on the booking page. revalidateTeamDataCache({ teamSlug: team.slug, orgSlug: team.parent?.slug ?? null, }); } showToast(t("round_robin_settings_updated_successfully"), "success"); }, }); if (!isAdmin) { return (
{t("only_owner_change")}
); } return (
{ mutation.mutate({ id: team.id, rrResetInterval: values.rrResetInterval, rrTimestampBasis: values.rrTimestampBasis, }); }}>
{" "}

{t("round_robin")}

{t("round_robin_settings_description")}

); }; export default RoundRobinSettings;