Files
cal.diy/packages/features/ee/teams/components/RoundRobinSettings.tsx
T
Carina WollendorferandCarinaWolli 6de715b884 feat: Round Robin timestamp basis (#21337)
* add rrTimeStampBasis to prisma schema

* add rr time stamp basis setting

* update migration

* add getLuckyUser logic

* add rrTimestampBasis to tests

* add load balancing warning message

* disable load balancing logic

* disable load balancing in event type settings

* add missing translations

* fix UI

* disable load balancing on all team event types

* don't show routing forms in router position

* use correct interval times

* fix variable naming

* fix event type update handler

* add test to booking.test.ts

* add test for getting interval times

* remove not needed prop

* fix label

* improve warning message

* fix removing maxLeadTreshold

* fix typo

* fix disabling maxLeadThreshold

* add back missing translation

* improve rr reset interval label

* fix rr_load_balancing_disabled text

* improve test

* fix description

* only use rrTimestampBasis in weights round robin

* fix dropdown width

---------

Co-authored-by: CarinaWolli <[email protected]>
2025-06-12 11:37:38 +01:00

89 lines
3.0 KiB
TypeScript

"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/client";
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 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 form = useForm<{ rrResetInterval: RRResetInterval; rrTimestampBasis: RRTimestampBasis }>({
defaultValues: {
rrResetInterval: rrResetInterval ?? RRResetInterval.MONTH,
rrTimestampBasis: team?.rrTimestampBasis ?? RRTimestampBasis.CREATED_AT,
},
});
const mutation = trpc.viewer.teams.update.useMutation({
onError: (err) => {
showToast(err.message, "error");
},
async onSuccess() {
await utils.viewer.teams.get.invalidate();
showToast(t("round_robin_settings_updated_successfully"), "success");
},
});
if (!isAdmin) {
return (
<div className="border-subtle rounded-md border p-5">
<span className="text-default text-sm">{t("only_owner_change")}</span>
</div>
);
}
return (
<Form
form={form}
handleSubmit={(values) => {
mutation.mutate({
id: team.id,
rrResetInterval: values.rrResetInterval,
rrTimestampBasis: values.rrTimestampBasis,
});
}}>
<div className="border-subtle mt-6 space-x-3 rounded-t-lg border border-b-0 px-4 py-6 pb-0 sm:px-6">
{" "}
<div>
<h4 className="text-emphasis text-sm font-semibold leading-5">{t("round_robin")}</h4>
<p className="text-default text-sm leading-tight">{t("round_robin_settings_description")}</p>
<div className="-mx-4 mt-4 sm:-mx-6">
<div className="border-subtle border-t px-6 py-6">
<RoundRobinResetInterval />
</div>
<div className="border-subtle border-t" />
<div className="border-subtle px-6 py-6">
<RoundRobinTimestampBasis />
</div>
</div>
</div>
</div>
<SectionBottomActions align="end">
<Button type="submit" color="primary" loading={mutation.isPending}>
{t("update")}
</Button>
</SectionBottomActions>
</Form>
);
};
export default RoundRobinSettings;