mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
update form
This commit is contained in:
parent
bdd89113c5
commit
6310e5f83b
4 changed files with 66 additions and 55 deletions
|
|
@ -34,7 +34,6 @@ import {
|
|||
import { analytics } from '../../utils/analytics'
|
||||
import {
|
||||
deleteTask,
|
||||
enqueueExportAllItems,
|
||||
enqueueImportFromIntegration,
|
||||
} from '../../utils/createTask'
|
||||
import { authorized } from '../../utils/gql-utils'
|
||||
|
|
@ -85,40 +84,6 @@ export const setIntegrationResolver = authorized<
|
|||
// save integration
|
||||
const integration = await saveIntegration(integrationToSave, uid)
|
||||
|
||||
if (integrationToSave.type === IntegrationType.Export && !input.id) {
|
||||
const authToken = await createIntegrationToken({
|
||||
uid,
|
||||
token: integration.token,
|
||||
})
|
||||
if (!authToken) {
|
||||
log.error('failed to create auth token', {
|
||||
integrationId: integration.id,
|
||||
})
|
||||
return {
|
||||
errorCodes: [SetIntegrationErrorCode.BadRequest],
|
||||
}
|
||||
}
|
||||
|
||||
// create a task to sync all the pages if new integration or enable integration (export type)
|
||||
await enqueueExportAllItems(integration.id, uid)
|
||||
} else if (integrationToSave.taskName) {
|
||||
// delete the task if disable integration and task exists
|
||||
const result = await deleteTask(integrationToSave.taskName)
|
||||
if (result) {
|
||||
log.info('task deleted', integrationToSave.taskName)
|
||||
}
|
||||
|
||||
// update task name in integration
|
||||
await updateIntegration(
|
||||
integration.id,
|
||||
{
|
||||
taskName: null,
|
||||
},
|
||||
uid
|
||||
)
|
||||
integration.taskName = null
|
||||
}
|
||||
|
||||
analytics.capture({
|
||||
distinctId: uid,
|
||||
event: 'integration_set',
|
||||
|
|
|
|||
|
|
@ -80,7 +80,11 @@ export const saveIntegration = async (
|
|||
userId: string
|
||||
) => {
|
||||
return authTrx(
|
||||
async (t) => t.getRepository(Integration).save(integration),
|
||||
async (t) => {
|
||||
const repo = t.getRepository(Integration)
|
||||
const newIntegration = await repo.save(integration)
|
||||
return repo.findOneByOrFail({ id: newIntegration.id })
|
||||
},
|
||||
undefined,
|
||||
userId
|
||||
)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export type SetIntegrationInput = {
|
|||
token: string
|
||||
enabled: boolean
|
||||
importItemState?: ImportItemState
|
||||
settings?: any
|
||||
}
|
||||
|
||||
type SetIntegrationResult = {
|
||||
|
|
@ -52,6 +53,7 @@ export async function setIntegrationMutation(
|
|||
enabled
|
||||
createdAt
|
||||
updatedAt
|
||||
settings
|
||||
}
|
||||
}
|
||||
... on SetIntegrationError {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,14 @@
|
|||
import { styled } from '@stitches/react'
|
||||
import { Button, Checkbox, Form, FormProps, Input, Space, Switch } from 'antd'
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
Form,
|
||||
FormProps,
|
||||
Input,
|
||||
message,
|
||||
Space,
|
||||
Switch,
|
||||
} from 'antd'
|
||||
import 'antd/dist/antd.compact.css'
|
||||
import { CheckboxValueType } from 'antd/lib/checkbox/Group'
|
||||
import Image from 'next/image'
|
||||
|
|
@ -12,6 +21,7 @@ import {
|
|||
import { PageMetaData } from '../../../components/patterns/PageMetaData'
|
||||
import { Beta } from '../../../components/templates/Beta'
|
||||
import { SettingsLayout } from '../../../components/templates/SettingsLayout'
|
||||
import { setIntegrationMutation } from '../../../lib/networking/mutations/setIntegrationMutation'
|
||||
import { useGetIntegrationsQuery } from '../../../lib/networking/queries/useGetIntegrationsQuery'
|
||||
|
||||
interface FieldData {
|
||||
|
|
@ -38,11 +48,12 @@ const Header = styled(Box, {
|
|||
|
||||
export default function Notion(): JSX.Element {
|
||||
const { integrations, revalidate } = useGetIntegrationsQuery()
|
||||
const fields = useMemo<FieldData[]>(() => {
|
||||
const notion = integrations.find(
|
||||
(i) => i.name == 'NOTION' && i.type == 'EXPORT'
|
||||
)
|
||||
return [
|
||||
const notion = useMemo(
|
||||
() => integrations.find((i) => i.name == 'NOTION' && i.type == 'EXPORT'),
|
||||
[integrations]
|
||||
)
|
||||
const fields = useMemo<FieldData[]>(
|
||||
() => [
|
||||
{
|
||||
name: 'parentPageId',
|
||||
value: notion?.settings?.parentPageId,
|
||||
|
|
@ -53,19 +64,43 @@ export default function Notion(): JSX.Element {
|
|||
},
|
||||
{
|
||||
name: 'autoSync',
|
||||
checked: notion?.settings?.autoSync,
|
||||
value: notion?.settings?.autoSync,
|
||||
},
|
||||
{
|
||||
name: 'properties',
|
||||
value: notion?.settings?.properties,
|
||||
},
|
||||
]
|
||||
}, [integrations])
|
||||
],
|
||||
[notion]
|
||||
)
|
||||
|
||||
const [form] = Form.useForm<FieldType>()
|
||||
const [messageApi, contextHolder] = message.useMessage()
|
||||
|
||||
const onFinish: FormProps<FieldType>['onFinish'] = (values) => {
|
||||
console.log('Success:', values)
|
||||
const updateNotion = async (values: FieldType) => {
|
||||
if (!notion) {
|
||||
throw new Error('Notion integration not found')
|
||||
}
|
||||
|
||||
await setIntegrationMutation({
|
||||
id: notion.id,
|
||||
name: notion.name,
|
||||
type: notion.type,
|
||||
token: notion.token,
|
||||
enabled: notion.enabled,
|
||||
settings: values,
|
||||
})
|
||||
}
|
||||
|
||||
const onFinish: FormProps<FieldType>['onFinish'] = async (values) => {
|
||||
try {
|
||||
await updateNotion(values)
|
||||
|
||||
revalidate()
|
||||
messageApi.success('Notion settings updated successfully.')
|
||||
} catch (error) {
|
||||
messageApi.error('There was an error updating Notion settings.')
|
||||
}
|
||||
}
|
||||
|
||||
const onFinishFailed: FormProps<FieldType>['onFinishFailed'] = (
|
||||
|
|
@ -76,11 +111,11 @@ export default function Notion(): JSX.Element {
|
|||
|
||||
const onDataChange = (value: Array<CheckboxValueType>) => {
|
||||
form.setFieldsValue({ properties: value.map((v) => v.toString()) })
|
||||
form.submit()
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{contextHolder}
|
||||
<PageMetaData title="Notion" path="/integrations/notion" />
|
||||
<SettingsLayout>
|
||||
<VStack
|
||||
|
|
@ -120,12 +155,7 @@ export default function Notion(): JSX.Element {
|
|||
},
|
||||
]}
|
||||
>
|
||||
<Space>
|
||||
<Input />
|
||||
<Button type="primary" htmlType="submit">
|
||||
Save
|
||||
</Button>
|
||||
</Space>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item<FieldType>
|
||||
|
|
@ -136,7 +166,11 @@ export default function Notion(): JSX.Element {
|
|||
<Input disabled />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item<FieldType> label="Automatic Sync" name="autoSync">
|
||||
<Form.Item<FieldType>
|
||||
label="Automatic Sync"
|
||||
name="autoSync"
|
||||
valuePropName="checked"
|
||||
>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
|
||||
|
|
@ -150,6 +184,12 @@ export default function Notion(): JSX.Element {
|
|||
<Checkbox value="notes">Notes</Checkbox>
|
||||
</Checkbox.Group>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item>
|
||||
<Button type="primary" htmlType="submit">
|
||||
Save
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
|
||||
<Space>
|
||||
|
|
|
|||
Loading…
Reference in a new issue