2022-10-22 23:54:10 +00:00
|
|
|
import { gql } from 'graphql-request'
|
|
|
|
|
import useSWR from 'swr'
|
|
|
|
|
import { publicGqlFetcher } from '../networkHelpers'
|
|
|
|
|
|
|
|
|
|
export interface Integration {
|
2022-10-25 03:14:28 +00:00
|
|
|
id: string
|
2023-02-16 09:04:06 +00:00
|
|
|
name: string
|
2022-10-22 23:54:10 +00:00
|
|
|
type: IntegrationType
|
2022-10-25 03:14:28 +00:00
|
|
|
token: string
|
|
|
|
|
enabled: boolean
|
2022-10-22 23:54:10 +00:00
|
|
|
createdAt: Date
|
|
|
|
|
updatedAt: Date
|
2023-07-20 01:52:23 +00:00
|
|
|
taskName?: string
|
2024-03-13 05:27:00 +00:00
|
|
|
settings?: any
|
2022-10-22 23:54:10 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-16 09:04:06 +00:00
|
|
|
export type IntegrationType = 'EXPORT' | 'IMPORT'
|
2022-10-22 23:54:10 +00:00
|
|
|
|
|
|
|
|
interface IntegrationsQueryResponse {
|
|
|
|
|
isValidating: boolean
|
|
|
|
|
integrations: Integration[]
|
|
|
|
|
revalidate: () => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IntegrationsQueryResponseData {
|
|
|
|
|
integrations: IntegrationsData
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IntegrationsData {
|
|
|
|
|
integrations: unknown
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function useGetIntegrationsQuery(): IntegrationsQueryResponse {
|
|
|
|
|
const query = gql`
|
|
|
|
|
query GetIntegrations {
|
|
|
|
|
integrations {
|
|
|
|
|
... on IntegrationsSuccess {
|
|
|
|
|
integrations {
|
|
|
|
|
id
|
2023-02-24 06:31:14 +00:00
|
|
|
name
|
2022-10-22 23:54:10 +00:00
|
|
|
type
|
|
|
|
|
token
|
|
|
|
|
enabled
|
|
|
|
|
createdAt
|
|
|
|
|
updatedAt
|
2023-07-20 01:52:23 +00:00
|
|
|
taskName
|
2024-03-12 14:38:44 +00:00
|
|
|
settings
|
2022-10-22 23:54:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
... on IntegrationsError {
|
|
|
|
|
errorCodes
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
|
2023-02-27 02:34:12 +00:00
|
|
|
const { data, mutate, isValidating } = useSWR(query, publicGqlFetcher)
|
2022-10-22 23:54:10 +00:00
|
|
|
try {
|
|
|
|
|
if (data) {
|
|
|
|
|
const result = data as IntegrationsQueryResponseData
|
|
|
|
|
const integrations = result.integrations.integrations as Integration[]
|
|
|
|
|
return {
|
|
|
|
|
isValidating,
|
|
|
|
|
integrations,
|
|
|
|
|
revalidate: () => {
|
|
|
|
|
mutate()
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log('error', error)
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
isValidating: false,
|
|
|
|
|
integrations: [],
|
2023-05-15 13:46:11 +00:00
|
|
|
revalidate: () => {
|
|
|
|
|
mutate()
|
|
|
|
|
},
|
2022-10-22 23:54:10 +00:00
|
|
|
}
|
|
|
|
|
}
|