feat: add customReplyToEmail for EventTypeSettings atom (#23686)

* init: endpoint for fetching verified emails

* fix: enable custom reply to email in frontend

* init endpoint to add verified emails

* add verified emails option for platform in frontend

* fixup: move useGetVerifiedEmails hook to correct folder

* update atoms module

* fixup: teamId should be string

* add methond to fetch team member emails

* update logic to fetch and add emails

* fixup: append client id with email

* fixup: pass teamId for fetching verified emails

* fixup: simplify check for existing emails

* fix: cleanup comments

* fix: implement code rabbit feedback

* fix: add translations

* fixup: update transaltions

* fix: update logic for addVerifiedEmail

* add changesets

* fix: implement PR feedback
This commit is contained in:
Rajiv Sahal authored and GitHub committed 2025-09-09 16:52:28 +03:00
1 parent e86d6169ba
commit cfd1992733
16 files changed
+508 -47

No files matched your search

@@ -0,0 +1,64 @@
import { useMutation } from "@tanstack/react-query";
import { SUCCESS_STATUS } from "@calcom/platform-constants";
import type { ApiErrorResponse, ApiResponse } from "@calcom/platform-types";
import { useAtomsContext } from "../../hooks/useAtomsContext";
import { appendClientIdToEmail } from "../../lib/appendClientIdToEmail";
import http from "../../lib/http";
interface IUseAddVerifiedEmail {
onSuccess?: (res: ApiResponse) => void;
onError?: (err: ApiErrorResponse | Error) => void;
}
export const useAddVerifiedEmail = (
{ onSuccess, onError }: IUseAddVerifiedEmail = {
onSuccess: () => {
return;
},
onError: () => {
return;
},
}
) => {
const { clientId } = useAtomsContext();
const verifiedEmailEntry = useMutation<
ApiResponse<{
status: string;
data: {
emailVerified: boolean;
};
}>,
unknown,
{
email: string;
}
>({
mutationFn: (data) => {
const { email } = data;
const emailToSend = appendClientIdToEmail(email, clientId);
return http
.post(`/atoms/emails/verified-emails`, {
email: emailToSend,
})
.then((res) => {
return res.data;
});
},
onSuccess: (data) => {
if (data.status === SUCCESS_STATUS) {
onSuccess?.(data);
} else {
onError?.(data);
}
},
onError: (err) => {
onError?.(err as ApiErrorResponse);
},
});
return verifiedEmailEntry;
};
@@ -0,0 +1,27 @@
import { useQuery } from "@tanstack/react-query";
import { SUCCESS_STATUS } from "@calcom/platform-constants";
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
import { useAtomsContext } from "../../hooks/useAtomsContext";
import http from "../../lib/http";
export const QUERY_KEY = "use-get-verified-emails";
export const useGetVerifiedEmails = (teamId?: number) => {
const pathname = `/atoms/emails/verified-emails${!!teamId ? `?teamId=${teamId}` : ""}`;
const { isInit, accessToken } = useAtomsContext();
return useQuery({
queryKey: [QUERY_KEY, teamId],
queryFn: () => {
return http?.get<ApiResponse<string[]>>(pathname).then((res) => {
if (res.data.status === SUCCESS_STATUS) {
return (res.data as ApiSuccessResponse<string[]>).data;
}
throw new Error(res.data.error.message);
});
},
enabled: isInit && !!accessToken,
staleTime: 5000,
});
};
@@ -2,14 +2,18 @@ import type { EventAdvancedBaseProps } from "@calcom/features/eventtypes/compone
import { EventAdvancedTab } from "@calcom/features/eventtypes/components/tabs/advanced/EventAdvancedTab";
import { useConnectedCalendars } from "../../hooks/useConnectedCalendars";
import { useGetVerifiedEmails } from "../hooks/useGetVerifiedEmails";
const EventAdvancedPlatformWrapper = (props: EventAdvancedBaseProps) => {
const { isPending, data: connectedCalendarsQuery, error } = useConnectedCalendars({});
const { data: verifiedEmails } = useGetVerifiedEmails(props.team?.id);
return (
<EventAdvancedTab
{...props}
calendarsQuery={{ data: connectedCalendarsQuery, isPending, error }}
showBookerLayoutSelector={false}
verifiedEmails={verifiedEmails}
/>
);
};
@@ -0,0 +1,4 @@
export function appendClientIdToEmail(email: string, clientId: string): string {
const [localPart, domain] = email.split("@");
return `${localPart}+${clientId}@${domain}`;
}