fix: Disable round robin reassignment if reroute is available (#19192)
* If booking is routed from form, disable round robin reassign * Pass `bookingFromRoutingForm` prop from `BookingListItem` * Add `ReassignType` enum * Refactor `isBookingReroutable`
This commit is contained in:
1 parent
75ff5f6fb1
commit
a775bec902
2 files changed
+36
-15
No files matched your search
@@ -145,6 +145,7 @@ function BookingListItem(booking: BookingItemProps) {
|
||||
const isRecurring = booking.recurringEventId !== null;
|
||||
const isTabRecurring = booking.listingStatus === "recurring";
|
||||
const isTabUnconfirmed = booking.listingStatus === "unconfirmed";
|
||||
const isBookingFromRoutingForm = isBookingReroutable(parsedBooking);
|
||||
|
||||
const paymentAppData = getPaymentAppData(booking.eventType);
|
||||
|
||||
@@ -237,7 +238,7 @@ function BookingListItem(booking: BookingItemProps) {
|
||||
},
|
||||
},
|
||||
]),
|
||||
...(isBookingReroutable(parsedBooking)
|
||||
...(isBookingFromRoutingForm
|
||||
? [
|
||||
{
|
||||
id: "reroute",
|
||||
@@ -444,6 +445,7 @@ function BookingListItem(booking: BookingItemProps) {
|
||||
setIsOpenDialog={setIsOpenReassignDialog}
|
||||
bookingId={booking.id}
|
||||
teamId={booking.eventType?.team?.id || 0}
|
||||
bookingFromRoutingForm={isBookingFromRoutingForm}
|
||||
/>
|
||||
)}
|
||||
<EditLocationDialog
|
||||
@@ -691,7 +693,7 @@ function BookingListItem(booking: BookingItemProps) {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{isBookingReroutable(parsedBooking) && (
|
||||
{isBookingFromRoutingForm && (
|
||||
<RerouteDialog
|
||||
isOpenDialog={rerouteDialogIsOpen}
|
||||
setIsOpenDialog={setRerouteDialogIsOpen}
|
||||
|
||||
@@ -27,21 +27,27 @@ import {
|
||||
TextAreaField,
|
||||
} from "@calcom/ui";
|
||||
|
||||
enum ReassignType {
|
||||
ROUND_ROBIN = "round_robin",
|
||||
TEAM_MEMBER = "team_member",
|
||||
}
|
||||
|
||||
type ReassignDialog = {
|
||||
isOpenDialog: boolean;
|
||||
setIsOpenDialog: Dispatch<SetStateAction<boolean>>;
|
||||
teamId: number;
|
||||
bookingId: number;
|
||||
bookingFromRoutingForm: boolean;
|
||||
};
|
||||
|
||||
type FormValues = {
|
||||
reassignType: "round_robin" | "team_member";
|
||||
reassignType: ReassignType.ROUND_ROBIN | ReassignType.TEAM_MEMBER;
|
||||
teamMemberId?: number;
|
||||
reassignReason?: string;
|
||||
};
|
||||
|
||||
const formSchema = z.object({
|
||||
reassignType: z.enum(["round_robin", "team_member"]),
|
||||
reassignType: z.nativeEnum(ReassignType),
|
||||
teamMemberId: z.number().optional(),
|
||||
reassignReason: z
|
||||
.string()
|
||||
@@ -57,7 +63,13 @@ interface TeamMemberOption {
|
||||
status: string;
|
||||
}
|
||||
|
||||
export const ReassignDialog = ({ isOpenDialog, setIsOpenDialog, teamId, bookingId }: ReassignDialog) => {
|
||||
export const ReassignDialog = ({
|
||||
isOpenDialog,
|
||||
setIsOpenDialog,
|
||||
teamId,
|
||||
bookingId,
|
||||
bookingFromRoutingForm,
|
||||
}: ReassignDialog) => {
|
||||
const { t } = useLocale();
|
||||
const utils = trpc.useUtils();
|
||||
const [animationParentRef] = useAutoAnimate<HTMLFormElement>({
|
||||
@@ -101,7 +113,7 @@ export const ReassignDialog = ({ isOpenDialog, setIsOpenDialog, teamId, bookingI
|
||||
const form = useForm<FormValues>({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: {
|
||||
reassignType: "round_robin",
|
||||
reassignType: bookingFromRoutingForm ? ReassignType.TEAM_MEMBER : ReassignType.ROUND_ROBIN,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -144,7 +156,7 @@ export const ReassignDialog = ({ isOpenDialog, setIsOpenDialog, teamId, bookingI
|
||||
});
|
||||
|
||||
const handleSubmit = (values: FormValues) => {
|
||||
if (values.reassignType === "round_robin") {
|
||||
if (values.reassignType === ReassignType.ROUND_ROBIN) {
|
||||
roundRobinReassignMutation.mutate({ teamId, bookingId });
|
||||
} else {
|
||||
if (values.teamMemberId) {
|
||||
@@ -176,23 +188,30 @@ export const ReassignDialog = ({ isOpenDialog, setIsOpenDialog, teamId, bookingI
|
||||
<Form form={form} handleSubmit={handleSubmit} ref={animationParentRef}>
|
||||
<RadioArea.Group
|
||||
onValueChange={(val) => {
|
||||
form.setValue("reassignType", val as "team_member" | "round_robin");
|
||||
form.setValue("reassignType", val as ReasonEnum);
|
||||
}}
|
||||
defaultValue={bookingFromRoutingForm ? ReassignType.TEAM_MEMBER : ReassignType.ROUND_ROBIN}
|
||||
className="mt-1 flex flex-col gap-4">
|
||||
{!bookingFromRoutingForm ? (
|
||||
<RadioArea.Item
|
||||
value={ReassignType.ROUND_ROBIN}
|
||||
className="w-full text-sm"
|
||||
classNames={{ container: "w-full" }}
|
||||
disabled={bookingFromRoutingForm}>
|
||||
<strong className="mb-1 block">{t("round_robin")}</strong>
|
||||
<p>{t("round_robin_reassign_description")}</p>
|
||||
</RadioArea.Item>
|
||||
) : null}
|
||||
<RadioArea.Item
|
||||
value="round_robin"
|
||||
className="w-full text-sm"
|
||||
value={ReassignType.TEAM_MEMBER}
|
||||
className="text-sm"
|
||||
classNames={{ container: "w-full" }}>
|
||||
<strong className="mb-1 block">{t("round_robin")}</strong>
|
||||
<p>{t("round_robin_reassign_description")}</p>
|
||||
</RadioArea.Item>
|
||||
<RadioArea.Item value="team_member" className="text-sm" classNames={{ container: "w-full" }}>
|
||||
<strong className="mb-1 block">{t("team_member_round_robin_reassign")}</strong>
|
||||
<p>{t("team_member_round_robin_reassign_description")}</p>
|
||||
</RadioArea.Item>
|
||||
</RadioArea.Group>
|
||||
|
||||
{watchedReassignType === "team_member" && (
|
||||
{watchedReassignType === ReassignType.TEAM_MEMBER && (
|
||||
<div className="mb-2">
|
||||
<Label className="text-emphasis mt-6">{t("select_team_member")}</Label>
|
||||
<div className="mt-2">
|
||||
|
||||
Reference in new issue
Block a user