Skip to content

Commit

Permalink
Add client fn for cloud free connector info API
Browse files Browse the repository at this point in the history
  • Loading branch information
ambirdsall committed Jan 13, 2023
1 parent 38f7f69 commit 5ce541f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { apiOverride } from "core/request/apiOverride";

export type WebBackendGetFreeConnectorProgramInfoForWorkspaceResult = NonNullable<
Awaited<ReturnType<typeof webBackendGetFreeConnectorProgramInfoForWorkspace>>
>;

export interface WorkspaceIdRequestBody {
workspaceId: WorkspaceId;
}

/**
* Workspace Id from OSS Airbyte instance
*/
export type WorkspaceId = string;

// eslint-disable-next-line
type SecondParameter<T extends (...args: any) => any> = T extends (config: any, args: infer P) => any ? P : never;

/**
* @summary Return a summary of Free Connector Program info for the indicated Cloud Workspace
*/
export const webBackendGetFreeConnectorProgramInfoForWorkspace = (
workspaceIdRequestBody: WorkspaceIdRequestBody,
options?: SecondParameter<typeof apiOverride>
) => {
return apiOverride<WorkspaceFreeConnectorProgramInfoResponse>(
{
url: `/v1/web_backend/cloud_workspaces/free_connector_program_info`,
method: "post",
headers: { "Content-Type": "application/json" },
data: workspaceIdRequestBody,
},
options
);
};

export interface WorkspaceFreeConnectorProgramInfoResponse {
hasEligibleConnector: boolean;
hasPaymentAccountSaved: boolean;
}
19 changes: 19 additions & 0 deletions airbyte-webapp/src/packages/cloud/services/freeConnectorProgram.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useQuery } from "react-query";

import { useCurrentWorkspace } from "hooks/services/useWorkspace";
import { useDefaultRequestMiddlewares } from "services/useDefaultRequestMiddlewares";

import { webBackendGetFreeConnectorProgramInfoForWorkspace } from "../lib/domain/freeConnectorProgram/api";
import { useConfig } from "./config";

export const useFreeConnectorProgramInfo = () => {
const { workspaceId } = useCurrentWorkspace();
const { cloudApiUrl } = useConfig();
const config = { apiUrl: cloudApiUrl };
const middlewares = useDefaultRequestMiddlewares();
const requestOptions = { config, middlewares };

return useQuery(["freeConnectorProgramInfo", workspaceId], () =>
webBackendGetFreeConnectorProgramInfoForWorkspace({ workspaceId }, requestOptions)
);
};

0 comments on commit 5ce541f

Please sign in to comment.