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)}>
+ {addCalDavError && ( +

+ Error: + {addCalDavError.message} +

+ )}
- + { + setIsAddCalDavIntegrationDialogOpen(false); + }} + as="button" + className="btn btn-white mx-2"> Cancel
); - }; + }, [isAddCalDavIntegrationDialogOpen, addCalDavError]); if (loading) { return ; @@ -367,7 +370,7 @@ export default function Home({ integrations }: Props) { - + );