From 4550bd42b5aec025feb8c31c70060326776697e9 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Sun, 24 Mar 2024 11:32:25 +0800 Subject: [PATCH] go to integrations page if integration is not connected when adding rules --- packages/web/pages/settings/rules.tsx | 52 +++++++++++++++++++++------ 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/packages/web/pages/settings/rules.tsx b/packages/web/pages/settings/rules.tsx index 97fa56cf5..02247631d 100644 --- a/packages/web/pages/settings/rules.tsx +++ b/packages/web/pages/settings/rules.tsx @@ -1,5 +1,4 @@ import { Button, Form, Input, Modal, Select, Space, Table, Tag } from 'antd' -// import 'antd/dist/antd.dark.css' import 'antd/dist/antd.compact.css' import { useCallback, useMemo, useState } from 'react' import { Toaster } from 'react-hot-toast' @@ -8,13 +7,14 @@ import { SettingsLayout } from '../../components/templates/SettingsLayout' import { Label } from '../../lib/networking/fragments/labelFragment' import { deleteRuleMutation } from '../../lib/networking/mutations/deleteRuleMutation' import { setRuleMutation } from '../../lib/networking/mutations/setRuleMutation' +import { useGetIntegrationsQuery } from '../../lib/networking/queries/useGetIntegrationsQuery' import { useGetLabelsQuery } from '../../lib/networking/queries/useGetLabelsQuery' import { Rule, RuleAction, RuleActionType, RuleEventType, - useGetRulesQuery, + useGetRulesQuery } from '../../lib/networking/queries/useGetRulesQuery' import { applyStoredTheme } from '../../lib/themeUpdater' import { showErrorToast, showSuccessToast } from '../../lib/toastHelpers' @@ -124,6 +124,13 @@ type CreateActionModalProps = { const CreateActionModal = (props: CreateActionModalProps): JSX.Element => { const [form] = Form.useForm() const { labels } = useGetLabelsQuery() + const { integrations } = useGetIntegrationsQuery() + + const integrationOptions = ['Notion', 'Readwise'] + + const isIntegrationEnabled = (integration: string): boolean => { + return integrations.some((i) => i.name.toUpperCase() === integration.toUpperCase()) + } const onOk = async (values: any) => { const actionType = form.getFieldValue('actionType') as RuleActionType @@ -236,17 +243,39 @@ const CreateActionModal = (props: CreateActionModalProps): JSX.Element => { { + value.forEach((v) => { + if (!isIntegrationEnabled(v)) { + return Promise.reject(`Integration ${v} is not enabled`) + } + }) + + return Promise.resolve() + }, + }, ]} > )} @@ -259,8 +288,9 @@ export default function Rules(): JSX.Element { const { rules, revalidate } = useGetRulesQuery() const { labels } = useGetLabelsQuery() const [isCreateRuleModalOpen, setIsCreateRuleModalOpen] = useState(false) - const [createActionRule, setCreateActionRule] = - useState(undefined) + const [createActionRule, setCreateActionRule] = useState( + undefined + ) const dataSource = useMemo(() => { return rules.map((rule: Rule) => {