* feat: add endpoint to add attendees to existing bookings - Created POST /v2/bookings/:bookingUid/attendees endpoint - Added AddAttendeesInput_2024_08_13 for input validation - Added AddAttendeesOutput_2024_08_13 for response format - Created BookingAttendeesService_2024_08_13 for business logic - Created BookingAttendeesController_2024_08_13 for API endpoint - Added validation to check for duplicate attendee emails - Integrated with existing booking and event type repositories - Added validateAndTransformAddAttendeesInput method to InputBookingsService - Fixed pre-existing ESLint no-prototype-builtins warnings - Left placeholder for custom booking field validation logic Co-Authored-By: somay@cal.com <somaychauhan98@gmail.com> * refactor: move booking attendee operations to dedicated repository * refactor: move repository files into dedicated repositories directory * feat: validate guests field availability before adding attendees to booking * feat: migrate addAttendees API to use existing addGuests handler * refactor: remove unused validateAndTransformAddAttendeesInput method from InputBookingsService * refactor: rename attendees to guests in booking API endpoints and types * refactor: rename booking-attendees to booking-guests for consistency * WIP: add e2e tests for add booking guests endpoint * faet: improve guest booking tests * refactor: extract getHtml method in email templates * feat: add email toggle support for guest invites based on OAuth client settings * refactor: addGuests handler * feat: add SMS notifications when adding guests to existing bookings * refactor: rename add-attendees to add-guests for consistent terminology * refactor: added repository pattern in addGuests.handler * test: add attendee scheduled email spy to booking guests tests * fix: use event type team ID instead of user org ID for booking permission check * Update BookingEmailSmsHandler.ts * Remove comments * refactor: rename booking guests to booking attendees * refactor: rename guest-related methods to use attendees terminology for consistency * update api docs * refactor: restructure addGuests handler to top * refactor: update guest email format to use object structure in booking tests * docs: clarify API version header requirement for booking attendees endpoint * docs: add email notification details to booking attendees API documentation * refactor: rename booking attendees to guests for consistency * refactor: rename attendees to guests in booking API endpoints * feat: add email validation for guest invites * feat: improve error handling for guest booking failures --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
106 lines
3.7 KiB
TypeScript
106 lines
3.7 KiB
TypeScript
import type { Dispatch, SetStateAction } from "react";
|
|
import { useState } from "react";
|
|
import { z } from "zod";
|
|
|
|
import { Dialog } from "@calcom/features/components/controlled-dialog";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
import { MultiEmail } from "@calcom/ui/components/address";
|
|
import { Button } from "@calcom/ui/components/button";
|
|
import { DialogContent, DialogFooter, DialogHeader } from "@calcom/ui/components/dialog";
|
|
import { Icon } from "@calcom/ui/components/icon";
|
|
import { showToast } from "@calcom/ui/components/toast";
|
|
|
|
interface IAddGuestsDialog {
|
|
isOpenDialog: boolean;
|
|
setIsOpenDialog: Dispatch<SetStateAction<boolean>>;
|
|
bookingId: number;
|
|
}
|
|
|
|
export const AddGuestsDialog = (props: IAddGuestsDialog) => {
|
|
const { t } = useLocale();
|
|
const ZAddGuestsInputSchema = z.array(z.string().email()).refine((emails) => {
|
|
const uniqueEmails = new Set(emails);
|
|
return uniqueEmails.size === emails.length;
|
|
});
|
|
const { isOpenDialog, setIsOpenDialog, bookingId } = props;
|
|
const utils = trpc.useUtils();
|
|
const [multiEmailValue, setMultiEmailValue] = useState<string[]>([""]);
|
|
const [isInvalidEmail, setIsInvalidEmail] = useState(false);
|
|
|
|
const addGuestsMutation = trpc.viewer.bookings.addGuests.useMutation({
|
|
onSuccess: async () => {
|
|
showToast(t("guests_added"), "success");
|
|
setIsOpenDialog(false);
|
|
setMultiEmailValue([""]);
|
|
utils.viewer.bookings.invalidate();
|
|
},
|
|
onError: (err) => {
|
|
const message = `${err.data?.code}: ${t(err.message)}`;
|
|
showToast(message || t("unable_to_add_guests"), "error");
|
|
},
|
|
});
|
|
|
|
const handleAdd = () => {
|
|
if (multiEmailValue.length === 0) {
|
|
return;
|
|
}
|
|
const validationResult = ZAddGuestsInputSchema.safeParse(multiEmailValue);
|
|
if (validationResult.success) {
|
|
const guests = multiEmailValue.map((email) => ({ email }));
|
|
addGuestsMutation.mutate({ bookingId, guests });
|
|
} else {
|
|
setIsInvalidEmail(true);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Dialog open={isOpenDialog} onOpenChange={setIsOpenDialog}>
|
|
<DialogContent enableOverflow>
|
|
<div className="flex flex-row space-x-3">
|
|
<div className="bg-subtle flex h-10 w-10 flex-shrink-0 justify-center rounded-full">
|
|
<Icon name="user-plus" className="m-auto h-6 w-6" />
|
|
</div>
|
|
<div className="w-full pt-1">
|
|
<DialogHeader title={t("additional_guests")} />
|
|
<div className="bg-default">
|
|
<MultiEmail
|
|
label={t("add_emails")}
|
|
value={multiEmailValue}
|
|
readOnly={false}
|
|
setValue={setMultiEmailValue}
|
|
/>
|
|
</div>
|
|
|
|
{isInvalidEmail && (
|
|
<div className="my-4 flex text-sm text-red-700">
|
|
<div className="flex-shrink-0">
|
|
<Icon name="triangle-alert" className="h-5 w-5" />
|
|
</div>
|
|
<div className="ml-3">
|
|
<p className="font-medium">{t("emails_must_be_unique_valid")}</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
<DialogFooter showDivider className="mt-8">
|
|
<Button
|
|
onClick={() => {
|
|
setMultiEmailValue([""]);
|
|
setIsInvalidEmail(false);
|
|
setIsOpenDialog(false);
|
|
}}
|
|
type="button"
|
|
color="secondary">
|
|
{t("cancel")}
|
|
</Button>
|
|
<Button data-testid="add_members" loading={addGuestsMutation.isPending} onClick={handleAdd}>
|
|
{t("add")}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|