Skip to content

Commit 8568cab

Browse files
fix: Handle error when no default calendar exists for a o365 account (calcom#26074)
* fix: Handle error when no default calendar exists for a o365 account * Update packages/app-store/office365calendar/api/callback.ts Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
1 parent 8d04a23 commit 8568cab

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

apps/web/components/apps/CalendarListContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function CalendarListContainer({
106106
const { error, setQuery: setError } = useRouterQuery("error");
107107

108108
useEffect(() => {
109-
if (error === "account_already_linked") {
109+
if (error === "account_already_linked" || error === "no_default_calendar") {
110110
showToast(t(error), "error", { id: error });
111111
setError(undefined);
112112
}

apps/web/modules/apps/[slug]/slug-view.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import App from "@components/apps/App";
1515
function SingleAppPage(props: AppDataProps) {
1616
const { error, setQuery: setError } = useRouterQuery("error");
1717
const { t } = useLocale();
18-
if (error === "account_already_linked") {
18+
if (error === "account_already_linked" || error === "no_default_calendar") {
1919
showToast(t(error), "error", { id: error });
2020
setError(undefined);
2121
}
@@ -66,7 +66,7 @@ function SingleAppPage(props: AppDataProps) {
6666
// privacy="https://zoom.us/privacy"
6767
body={
6868
<>
69-
{/* eslint-disable-next-line react/no-danger */}
69+
{ }
7070
<div dangerouslySetInnerHTML={{ __html: markdownToSafeHTML(source.content) }} />
7171
</>
7272
}

apps/web/public/static/locales/en/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,6 +2893,7 @@
28932893
"field_identifiers_as_variables": "Use field identifiers as variables for your custom event redirect",
28942894
"field_identifiers_as_variables_with_example": "Use field identifiers as variables for your custom event redirect (e.g. {{variable}})",
28952895
"account_already_linked": "Account is already linked",
2896+
"no_default_calendar": "No default calendar found for this account, unable to link",
28962897
"send_email": "Send email",
28972898
"cal_ai_phone_call_action": "Call attendee using Cal.ai Voice Agent",
28982899
"call_to_confirm_booking": "Call to confirm booking",

packages/app-store/office365calendar/api/callback.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
104104

105105
logger.info("Office365 Calendar: handleErrorsJson completed", {
106106
userId: req.session?.user?.id,
107-
calendarCount: calBody.value.length ?? 0,
107+
calendarCount: calBody.value?.length ?? 0,
108108
});
109109

110110
if (typeof responseBody === "string") {
111111
calBody = JSON.parse(responseBody) as { value: OfficeCalendar[] };
112112
}
113113

114-
const findDefaultCalendar = calBody.value.find((calendar) => calendar.isDefaultCalendar);
115-
114+
const findDefaultCalendar = (calBody.value ?? []).find((calendar) => calendar.isDefaultCalendar);
116115
if (findDefaultCalendar) {
117116
defaultCalendar = findDefaultCalendar;
118117
}
@@ -124,7 +123,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
124123
}
125124
}
126125

127-
if (defaultCalendar?.id && req.session?.user?.id) {
126+
if (!defaultCalendar?.id) {
127+
const errorMessage = "no_default_calendar";
128+
res.redirect(
129+
`${getSafeRedirectUrl(state?.onErrorReturnTo) ?? getInstalledAppPath({ variant: "calendar", slug: "office365-calendar" })}?error=${errorMessage}`
130+
);
131+
return;
132+
}
133+
134+
if (req.session?.user?.id) {
128135
const credential = await prisma.credential.create({
129136
data: {
130137
type: "office365_calendar",

0 commit comments

Comments
 (0)