From 420839bcf547c7c573879f40175a0da252f4cd85 Mon Sep 17 00:00:00 2001 From: femyeda Date: Sun, 15 Aug 2021 08:49:30 -0500 Subject: [PATCH 1/2] fix issue where user cant cancel caldav dialog --- pages/integrations/index.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pages/integrations/index.tsx b/pages/integrations/index.tsx index ef9cde37..4d9f6612 100644 --- a/pages/integrations/index.tsx +++ b/pages/integrations/index.tsx @@ -234,7 +234,7 @@ export default function Home({ integrations }: Props) { const ConnectCalDavServerDialog = ({ isOpen }) => { return ( - + setIsAddCalDavIntegrationDialogOpen(isOpen)}> Save - + { + setIsAddCalDavIntegrationDialogOpen(false); + }} + as="button" + className="btn btn-white mx-2"> Cancel From 19ef588fa55fff0b3ec1efcaab01d572341b2319 Mon Sep 17 00:00:00 2001 From: femyeda Date: Sun, 15 Aug 2021 09:22:05 -0500 Subject: [PATCH 2/2] fix issue where client side vali dation not happening show error message from server --- .../components/AddCalDavIntegration.tsx | 4 +- pages/api/integrations/caldav/add.ts | 4 +- pages/integrations/index.tsx | 74 +++++++++---------- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/lib/integrations/CalDav/components/AddCalDavIntegration.tsx b/lib/integrations/CalDav/components/AddCalDavIntegration.tsx index 3510c09e..5a135c86 100644 --- a/lib/integrations/CalDav/components/AddCalDavIntegration.tsx +++ b/lib/integrations/CalDav/components/AddCalDavIntegration.tsx @@ -4,6 +4,8 @@ type Props = { onSubmit: () => void; }; +export const ADD_CALDAV_INTEGRATION_FORM_TITLE = "addCalDav"; + const AddCalDavIntegration = React.forwardRef((props, ref) => { const onSubmit = (event) => { event.preventDefault(); @@ -13,7 +15,7 @@ const AddCalDavIntegration = React.forwardRef((props, re }; return ( -
+
- {integration.type === "caldav_calendar" ? ( - - ) : ( - // - - )} +
); @@ -206,41 +201,43 @@ export default function Home({ integrations }: Props) {
); - function handleAddCalDavIntegrationSaveButtonPress() { + const handleAddCalDavIntegrationSaveButtonPress = async () => { const form = addCalDavIntegrationRef.current.elements; const url = form.url.value; const password = form.password.value; const username = form.username.value; + try { - handleAddCalDavIntegration({ username, password, url }); + setAddCalDavError(null); + const addCalDavIntegrationResponse = await handleAddCalDavIntegration({ username, password, url }); + if (addCalDavIntegrationResponse.ok) { + setIsAddCalDavIntegrationDialogOpen(false); + } else { + const j = await addCalDavIntegrationResponse.json(); + setAddCalDavError({ message: j.message }); + } } catch (reason) { console.error(reason); } - } - - const onSubmit = () => { - const form = addCalDavIntegrationRef.current; - - if (form) { - if (typeof form.requestSubmit === "function") { - form.requestSubmit(); - } else { - form.dispatchEvent(new Event("submit", { cancelable: true })); - } - - setIsAddCalDavIntegrationDialogOpen(false); - } }; - const ConnectCalDavServerDialog = ({ isOpen }) => { + const ConnectCalDavServerDialog = useCallback(() => { return ( - setIsAddCalDavIntegrationDialogOpen(isOpen)}> + setIsAddCalDavIntegrationDialogOpen(isOpen)}>
+ {addCalDavError && ( +

+ Error: + {addCalDavError.message} +

+ )}
@@ -264,7 +262,7 @@ export default function Home({ integrations }: Props) {
); - }; + }, [isAddCalDavIntegrationDialogOpen, addCalDavError]); if (loading) { return ; @@ -372,7 +370,7 @@ export default function Home({ integrations }: Props) { - + );