fix: Handle error when no default calendar exists for a o365 account (#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>
This commit is contained in:
co-authored by
cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
parent
8d04a23bce
commit
8568cab283
@@ -106,7 +106,7 @@ export function CalendarListContainer({
|
||||
const { error, setQuery: setError } = useRouterQuery("error");
|
||||
|
||||
useEffect(() => {
|
||||
if (error === "account_already_linked") {
|
||||
if (error === "account_already_linked" || error === "no_default_calendar") {
|
||||
showToast(t(error), "error", { id: error });
|
||||
setError(undefined);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import App from "@components/apps/App";
|
||||
function SingleAppPage(props: AppDataProps) {
|
||||
const { error, setQuery: setError } = useRouterQuery("error");
|
||||
const { t } = useLocale();
|
||||
if (error === "account_already_linked") {
|
||||
if (error === "account_already_linked" || error === "no_default_calendar") {
|
||||
showToast(t(error), "error", { id: error });
|
||||
setError(undefined);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ function SingleAppPage(props: AppDataProps) {
|
||||
// privacy="https://zoom.us/privacy"
|
||||
body={
|
||||
<>
|
||||
{/* eslint-disable-next-line react/no-danger */}
|
||||
{ }
|
||||
<div dangerouslySetInnerHTML={{ __html: markdownToSafeHTML(source.content) }} />
|
||||
</>
|
||||
}
|
||||
|
||||
@@ -2893,6 +2893,7 @@
|
||||
"field_identifiers_as_variables": "Use field identifiers as variables for your custom event redirect",
|
||||
"field_identifiers_as_variables_with_example": "Use field identifiers as variables for your custom event redirect (e.g. {{variable}})",
|
||||
"account_already_linked": "Account is already linked",
|
||||
"no_default_calendar": "No default calendar found for this account, unable to link",
|
||||
"send_email": "Send email",
|
||||
"cal_ai_phone_call_action": "Call attendee using Cal.ai Voice Agent",
|
||||
"call_to_confirm_booking": "Call to confirm booking",
|
||||
|
||||
@@ -104,15 +104,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
logger.info("Office365 Calendar: handleErrorsJson completed", {
|
||||
userId: req.session?.user?.id,
|
||||
calendarCount: calBody.value.length ?? 0,
|
||||
calendarCount: calBody.value?.length ?? 0,
|
||||
});
|
||||
|
||||
if (typeof responseBody === "string") {
|
||||
calBody = JSON.parse(responseBody) as { value: OfficeCalendar[] };
|
||||
}
|
||||
|
||||
const findDefaultCalendar = calBody.value.find((calendar) => calendar.isDefaultCalendar);
|
||||
|
||||
const findDefaultCalendar = (calBody.value ?? []).find((calendar) => calendar.isDefaultCalendar);
|
||||
if (findDefaultCalendar) {
|
||||
defaultCalendar = findDefaultCalendar;
|
||||
}
|
||||
@@ -124,7 +123,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultCalendar?.id && req.session?.user?.id) {
|
||||
if (!defaultCalendar?.id) {
|
||||
const errorMessage = "no_default_calendar";
|
||||
res.redirect(
|
||||
`${getSafeRedirectUrl(state?.onErrorReturnTo) ?? getInstalledAppPath({ variant: "calendar", slug: "office365-calendar" })}?error=${errorMessage}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.session?.user?.id) {
|
||||
const credential = await prisma.credential.create({
|
||||
data: {
|
||||
type: "office365_calendar",
|
||||
|
||||
Reference in New Issue
Block a user