From 26b30b47cdd2ccd96b6ae361010783a63d4c2161 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 26 Jan 2024 22:07:43 +0100 Subject: [PATCH] connect status --- public/locales/de/translation.json | 14 +++ public/locales/en/translation.json | 14 +++ src/Pages/Store/Calendar/index.js | 162 +++++++++++++++++++++-------- 3 files changed, 147 insertions(+), 43 deletions(-) diff --git a/public/locales/de/translation.json b/public/locales/de/translation.json index 323fcdb..b12ecc4 100644 --- a/public/locales/de/translation.json +++ b/public/locales/de/translation.json @@ -196,6 +196,20 @@ "subTitle": "Klicken Sie auf die Schaltfläche unten, um Ihren Google Kalender zu verbinden.", "button": "Jetzt verbinden" }, + "googleCalendarPending": { + "title": "Vorbereiten von Google Kalender", + "subTitle": "Bitte warten Sie, während wir Ihren Google-Kalender vorbereiten. Dies kann einen Moment dauern." + }, + "googleCalendarNoPerm": { + "title": "Keine Berechtigungen für Google Calendar", + "subTitle": "Bitte erteilen Sie die Berechtigungen für den Zugriff auf den Google-Kalender.", + "button": "Erneut verbinden" + }, + "googleCalendarError": { + "title": "Fehler beim Verbinden mit Google Calendar", + "subTitle": "Bei der Verbindung zu Ihrem Google-Kalender ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.", + "button": "Erneut verbinden" + }, "unlinkGoogleCalendar": { "title": "Google Kalender trennen", "description": "Aus Sicherheitsgründen müssen Sie Ihr Passwort eingeben, um die Verbindung zu Ihrem Google Kalender zu trennen.", diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 0ff08b9..df892fc 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -199,6 +199,20 @@ "subTitle": "Click on the button below to connect your Google Calendar.", "button": "Connect now" }, + "googleCalendarPending": { + "title": "Preparing Google Calendar", + "subTitle": "Please wait while we prepare your Google Calendar. This may take a moment." + }, + "googleCalendarNoPerm": { + "title": "No permissions for Google Calendar", + "subTitle": "Please grant the authorisations for access to the Google calendar.", + "button": "Connect again" + }, + "googleCalendarError": { + "title": "Error when connecting to Google Calendar", + "subTitle": "An error occurred while connecting to your Google Calendar. Please try again.", + "button": "Connect again" + }, "unlinkGoogleCalendar": { "title": "Unlink Google Calendar", "description": "For security reasons, you need to enter your password to unlink your Google Calendar.", diff --git a/src/Pages/Store/Calendar/index.js b/src/Pages/Store/Calendar/index.js index 7414157..5c8b43b 100644 --- a/src/Pages/Store/Calendar/index.js +++ b/src/Pages/Store/Calendar/index.js @@ -47,6 +47,7 @@ export default function StoreCalendar() { const [calendarSettings, setCalendarSettings] = useState({}); const [isRequesting, setIsRequesting] = useState(true); + const timer = useRef(); useEffect(() => { // delete session cookie @@ -67,6 +68,31 @@ export default function StoreCalendar() { }); }, []); + useEffect(() => { + // if status is pending, check again after + + if (calendarSettings.status === "PENDING") { + timer.current = setTimeout(() => { + myFetch({ + url: "/calendar/settings", + method: "GET", + notificationApi: notificationApi, + t: t, + }) + .then((res) => { + setCalendarSettings(res); + }) + .catch((err) => { + console.log(err); + }); + }, 2000); + } + + return () => { + clearTimeout(timer.current); + }; + }, [calendarSettings]); + if (isRequesting) { return ( @@ -75,56 +101,106 @@ export default function StoreCalendar() { ); } + const ConnectCalendarButton = ({ text }) => ( + + ); + + if (calendarSettings.status === "NOT_CONNECTED") { + return ( + + } + /> + + ); + } + + if (calendarSettings.status === "PENDING") { + return ( + + } + /> + + ); + } + + if (calendarSettings.status === "NOPERM") { + return ( + + + } + /> + + ); + } + + if (calendarSettings.status === "ERROR") { + return ( + + + } + /> + + ); + } + + // status OK return ( <> {notificationContextHolder} - {calendarSettings.connected === false ? ( - - { - document.cookie = `session=${getUserSessionFromLocalStorage()}; path=/;`; +

{t("calendar.pageTitle")}

- window.location.href = `${Constants.API_ADDRESS}/calendar/auth/google`; - }} - > - {t("calendar.googleCalendarNotConnected.button")} - - } + + + -
- ) : ( - <> -

{t("calendar.pageTitle")}

+ + + {calendarSettings.storeSettings && ( + + )} + - - - - - - {calendarSettings.storeSettings && ( - - )} - - - - - - - - - - )} + + + + + + ); }