mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Update web to work with latest integration API
This commit is contained in:
parent
6554d3b601
commit
da1fdb85f9
4 changed files with 13 additions and 11 deletions
|
|
@ -26,7 +26,7 @@ const Header = styled(Box, {
|
|||
export function Readwise(): JSX.Element {
|
||||
const { integrations, revalidate } = useGetIntegrationsQuery()
|
||||
const readwiseIntegration = useMemo(() => {
|
||||
return integrations.find((i) => i.type == 'READWISE')
|
||||
return integrations.find((i) => i.name == 'READWISE' && i.type == 'EXPORT')
|
||||
}, [integrations])
|
||||
|
||||
return (
|
||||
|
|
@ -82,7 +82,8 @@ function AddReadwiseForm(): JSX.Element {
|
|||
try {
|
||||
const result = await setIntegrationMutation({
|
||||
token,
|
||||
type: 'READWISE',
|
||||
name: 'READWISE',
|
||||
type: 'EXPORT',
|
||||
enabled: true,
|
||||
})
|
||||
if (result) {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ import { IntegrationType } from '../queries/useGetIntegrationsQuery'
|
|||
|
||||
export type SetIntegrationInput = {
|
||||
id?: string
|
||||
name: string
|
||||
type: IntegrationType
|
||||
token: string,
|
||||
token: string
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
|
|
@ -20,6 +21,7 @@ type SetIntegrationData = {
|
|||
|
||||
type Integration = {
|
||||
id: string
|
||||
name: string
|
||||
type: IntegrationType
|
||||
token: string
|
||||
enabled: boolean
|
||||
|
|
@ -31,13 +33,12 @@ export async function setIntegrationMutation(
|
|||
input: SetIntegrationInput
|
||||
): Promise<Integration | undefined> {
|
||||
const mutation = gql`
|
||||
mutation SetIntegration(
|
||||
$input: SetIntegrationInput!
|
||||
) {
|
||||
mutation SetIntegration($input: SetIntegrationInput!) {
|
||||
setIntegration(input: $input) {
|
||||
... on SetIntegrationSuccess {
|
||||
integration {
|
||||
id
|
||||
name
|
||||
type
|
||||
token
|
||||
enabled
|
||||
|
|
@ -52,12 +53,11 @@ export async function setIntegrationMutation(
|
|||
}
|
||||
`
|
||||
|
||||
const data = await gqlFetcher(mutation, { input }) as SetIntegrationResult
|
||||
const data = (await gqlFetcher(mutation, { input })) as SetIntegrationResult
|
||||
const output = data as any
|
||||
const error = data.setIntegration?.errorCodes?.find(() => true)
|
||||
if (error) {
|
||||
if (error === 'INVALID_TOKEN')
|
||||
throw 'Your token is invalid.'
|
||||
if (error === 'INVALID_TOKEN') throw 'Your token is invalid.'
|
||||
throw error
|
||||
}
|
||||
return output.setIntegration?.integration
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { publicGqlFetcher } from '../networkHelpers'
|
|||
|
||||
export interface Integration {
|
||||
id: string
|
||||
name: string
|
||||
type: IntegrationType
|
||||
token: string
|
||||
enabled: boolean
|
||||
|
|
@ -11,7 +12,7 @@ export interface Integration {
|
|||
updatedAt: Date
|
||||
}
|
||||
|
||||
export type IntegrationType = 'READWISE'
|
||||
export type IntegrationType = 'EXPORT' | 'IMPORT'
|
||||
|
||||
interface IntegrationsQueryResponse {
|
||||
isValidating: boolean
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ export default function Integrations(): JSX.Element {
|
|||
const router = useRouter()
|
||||
|
||||
const readwiseConnected = useMemo(() => {
|
||||
return integrations.find((i) => i.type == 'READWISE')
|
||||
return integrations.find((i) => i.name == 'READWISE' && i.type == 'EXPORT')
|
||||
}, [integrations])
|
||||
|
||||
const deleteIntegration = async (id: string) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue