Update web to work with latest integration API

This commit is contained in:
Jackson Harper 2023-02-16 17:04:06 +08:00 committed by Hongbo Wu
parent 6554d3b601
commit da1fdb85f9
4 changed files with 13 additions and 11 deletions

View file

@ -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) {

View file

@ -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

View file

@ -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

View file

@ -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) => {