From a638708871e0c4f1a18b9b3802234d1dda3b2339 Mon Sep 17 00:00:00 2001 From: Leo Giovanetti Date: Thu, 15 Dec 2022 10:45:54 -0300 Subject: [PATCH] Baikal CalDAV error hint (#6021) --- apps/web/public/static/locales/en/common.json | 2 +- packages/app-store/caldavcalendar/api/add.ts | 18 +++++++++++++-- .../caldavcalendar/pages/setup/index.tsx | 23 ++++++++++++++++++- .../components/ImpersonatingBanner.tsx | 2 +- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index c445ac1ff2..4a09c31c4e 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -920,7 +920,7 @@ "allow_booker_to_select_duration": "Allow booker to select duration", "impersonate_user_tip": "All uses of this feature is audited.", "impersonating_user_warning": "Impersonating username \"{{user}}\".", - "impersonating_stop_instructions": "<0>Click Here to stop.", + "impersonating_stop_instructions": "Click here to stop", "event_location_changed": "Updated - Your event changed the location", "location_changed_event_type_subject": "Location Changed: {{eventType}} with {{name}} at {{date}}", "current_location": "Current Location", diff --git a/packages/app-store/caldavcalendar/api/add.ts b/packages/app-store/caldavcalendar/api/add.ts index 98fa3fe297..600f0accac 100644 --- a/packages/app-store/caldavcalendar/api/add.ts +++ b/packages/app-store/caldavcalendar/api/add.ts @@ -40,8 +40,22 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) await prisma.credential.create({ data, }); - } catch (reason) { - logger.error("Could not add this caldav account", reason); + } catch (e) { + logger.error("Could not add this caldav account", e); + if (e instanceof Error) { + let message = e.message; + if (e.message.indexOf("Invalid credentials") > -1 && url.indexOf("dav.php") > -1) { + const parsedUrl = new URL(url); + const adminUrl = + parsedUrl.protocol + + "//" + + parsedUrl.hostname + + (parsedUrl.port ? ":" + parsedUrl.port : "") + + "/admin/?/settings/standard/"; + message = `Couldn\'t connect to caldav account, please verify WebDAV authentication type is set to "Basic"`; + return res.status(500).json({ message, actionUrl: adminUrl }); + } + } return res.status(500).json({ message: "Could not add this caldav account" }); } diff --git a/packages/app-store/caldavcalendar/pages/setup/index.tsx b/packages/app-store/caldavcalendar/pages/setup/index.tsx index bfcc1fe61d..424b7b5733 100644 --- a/packages/app-store/caldavcalendar/pages/setup/index.tsx +++ b/packages/app-store/caldavcalendar/pages/setup/index.tsx @@ -18,6 +18,7 @@ export default function CalDavCalendarSetup() { }); const [errorMessage, setErrorMessage] = useState(""); + const [errorActionUrl, setErrorActionUrl] = useState(""); return (
@@ -49,6 +50,9 @@ export default function CalDavCalendarSetup() { const json = await res.json(); if (!res.ok) { setErrorMessage(json?.message || t("something_went_wrong")); + if (json.actionUrl) { + setErrorActionUrl(json.actionUrl); + } } else { router.push(json.url); } @@ -78,7 +82,24 @@ export default function CalDavCalendarSetup() { /> - {errorMessage && } + {errorMessage && ( + + Go to Admin + + ) : undefined + } + className="my-4" + /> + )}