diff --git a/next.config.js b/next.config.js index 414aee90ba..9ffb8597d2 100644 --- a/next.config.js +++ b/next.config.js @@ -1,5 +1,20 @@ const withTM = require('next-transpile-modules')(['react-timezone-select']); +const validJson = (jsonString) => { + try { + const o = JSON.parse(jsonString); + if (o && typeof o === "object") { + return o; + } + } + catch (e) {} + return false; +} + +if (process.env.GOOGLE_API_CREDENTIALS && ! validJson(process.env.GOOGLE_API_CREDENTIALS)) { + console.warn('\x1b[33mwarn', '\x1b[0m', "- Disabled 'Google Calendar' integration. Reason: Invalid value for GOOGLE_API_CREDENTIALS environment variable. When set, this value needs to contain valid JSON like {\"web\":{\"client_id\":\"\",\"client_secret\":\"\",\"redirect_uris\":[\"/api/integrations/googlecalendar/callback>\"]}. You can download this JSON from your OAuth Client @ https://console.cloud.google.com/apis/credentials."); +} + module.exports = withTM({ future: { webpack5: true, diff --git a/pages/integrations/index.tsx b/pages/integrations/index.tsx index edb01a2924..76e16a3489 100644 --- a/pages/integrations/index.tsx +++ b/pages/integrations/index.tsx @@ -7,7 +7,7 @@ import { useSession, getSession } from 'next-auth/client'; import { CheckCircleIcon, XCircleIcon, ChevronRightIcon, PlusIcon } from '@heroicons/react/solid'; import { InformationCircleIcon } from '@heroicons/react/outline'; -export default function Home(props) { +export default function Home({ integrations }) { const [session, loading] = useSession(); const [showAddModal, setShowAddModal] = useState(false); @@ -24,7 +24,7 @@ export default function Home(props) { } function integrationHandler(type) { - fetch('/api/integrations/' + type + '/add') + fetch('/api/integrations/' + type.replace('_', '') + '/add') .then((response) => response.json()) .then((data) => window.location.href = data.url); } @@ -38,73 +38,63 @@ export default function Home(props) {
- - {props.credentials.length == 0 && -
-
-
- + : +
+
+
+ +
+
+

+ You don't have any integrations added. +

+
+

+ You currently do not have any integrations set up. Add your first integration to get started. +

-
-

- You don't have any integrations added. -

-
-

- You currently do not have any integrations set up. Add your first integration to get started. -

-
-
- -
+
+
+
}
{showAddModal && @@ -150,30 +140,18 @@ export default function Home(props) {
    -
  • + {integrations.filter( (integration) => integration.installed ).map( (integration) => (
  • - Office 365 / Outlook.com Calendar + {integration.title}
    -

    Office 365 / Outlook.com Calendar

    -

    For personal and business accounts

    +

    { integration.title }

    +

    { integration.description }

    - +
    -
  • -
  • -
    - Google Calendar -
    -
    -

    Google Calendar

    -

    For personal and business accounts

    -
    -
    - -
    -
  • + ))}
@@ -190,6 +168,17 @@ export default function Home(props) { ); } +const validJson = (jsonString: string) => { + try { + const o = JSON.parse(jsonString); + if (o && typeof o === "object") { + return o; + } + } + catch (e) {} + return false; +} + export async function getServerSideProps(context) { const session = await getSession(context); @@ -212,7 +201,24 @@ export async function getServerSideProps(context) { key: true } }); + + const integrations = [ { + installed: !!(process.env.GOOGLE_API_CREDENTIALS && validJson(process.env.GOOGLE_API_CREDENTIALS)), + credential: credentials.find( (integration) => integration.type === "google_calendar" ) || null, + type: "google_calendar", + title: "Google Calendar", + imageSrc: "integrations/google-calendar.png", + description: "For personal and business accounts", + }, { + installed: !!(process.env.MS_GRAPH_CLIENT_ID && process.env.MS_GRAPH_CLIENT_SECRET), + type: "office365_calendar", + credential: credentials.find( (integration) => integration.type === "office365_calendar" ) || null, + title: "Office 365 / Outlook.com Calendar", + imageSrc: "integrations/office-365.png", + description: "For personal and business accounts", + } ]; + return { - props: {credentials}, // will be passed to the page component as props + props: {integrations}, } -} +} \ No newline at end of file