Skip to content

Commit c597ec8

Browse files
committed
feat: Update API functions to support generic response types
1 parent 5e1a77b commit c597ec8

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/Common/Api.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,22 +227,22 @@ function fetchInTime(
227227
})
228228
}
229229

230-
export const post = (
230+
export const post = <T = any>(
231231
url: string,
232232
data: object,
233233
options?: APIOptions,
234234
isMultipartRequest?: boolean,
235-
): Promise<ResponseType> => fetchInTime(url, 'POST', data, options, isMultipartRequest)
235+
): Promise<ResponseType<T>> => fetchInTime(url, 'POST', data, options, isMultipartRequest)
236236

237-
export const put = (url: string, data: object, options?: APIOptions): Promise<ResponseType> =>
237+
export const put = <T = any>(url: string, data: object, options?: APIOptions): Promise<ResponseType<T>> =>
238238
fetchInTime(url, 'PUT', data, options)
239239

240-
export const patch = (url: string, data: object, options?: APIOptions): Promise<ResponseType> =>
240+
export const patch = <T = any>(url: string, data: object, options?: APIOptions): Promise<ResponseType<T>> =>
241241
fetchInTime(url, 'PATCH', data, options)
242242

243243
export const get = <T = any>(url: string, options?: APIOptions): Promise<ResponseType<T>> => fetchInTime(url, 'GET', null, options)
244244

245-
export const trash = (url: string, data?: object, options?: APIOptions): Promise<ResponseType> =>
245+
export const trash = <T = any>(url: string, data?: object, options?: APIOptions): Promise<ResponseType<T>> =>
246246
fetchInTime(url, 'DELETE', data, options)
247247

248248
/**

src/Common/MultiSelectCustomization.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import React from 'react'
1818
import Select, { components } from 'react-select'
1919
import Tippy from '@tippyjs/react'
20-
import { ReactComponent as ClearIcon } from '../Assets/Icon/ic-appstatus-cancelled.svg'
2120
import { ReactComponent as ICErrorCross } from '@Icons/ic-error-cross.svg'
21+
import { ReactComponent as ClearIcon } from '../Assets/Icon/ic-appstatus-cancelled.svg'
2222
import { ReactComponent as Check } from '../Assets/Icon/ic-check.svg'
2323
import { ReactComponent as RedWarning } from '../Assets/Icon/ic-error-medium.svg'
2424
import { Checkbox } from './Checkbox'

src/Shared/Components/Plugin/service.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { get, getIsRequestAborted, getUrlWithSearchParams, ResponseType, ROUTES, showError } from '../../../Common'
22
import { stringComparatorBySortOrder } from '../../Helpers'
33
import {
4+
GetParentPluginListPayloadType,
45
GetPluginListPayloadType,
56
GetPluginStoreDataReturnType,
67
GetPluginStoreDataServiceParamsType,
@@ -98,5 +99,7 @@ export const getAvailablePluginTags = async (appId: number): Promise<string[]> =
9899
}
99100
}
100101

101-
export const getParentPluginList = async (appId?: number): Promise<ResponseType<MinParentPluginDTO[]>> =>
102-
get<MinParentPluginDTO[]>(getUrlWithSearchParams(ROUTES.PLUGIN_LIST_MIN, { appId }))
102+
export const getParentPluginList = async (appId?: number): Promise<ResponseType<MinParentPluginDTO[]>> => {
103+
const queryParams: GetParentPluginListPayloadType = { appId }
104+
return get<MinParentPluginDTO[]>(getUrlWithSearchParams(ROUTES.PLUGIN_LIST_MIN, queryParams))
105+
}

src/Shared/Components/Plugin/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ export enum PluginCreationType {
99
PRESET = 'PRESET',
1010
}
1111

12-
export interface GetPluginTagsPayloadType {
12+
export interface PluginAPIBaseQueryParamsType {
1313
appId: number
1414
}
1515

16+
export interface GetPluginTagsPayloadType extends PluginAPIBaseQueryParamsType {}
17+
export interface GetParentPluginListPayloadType extends PluginAPIBaseQueryParamsType {}
18+
1619
export interface PluginTagNamesDTO {
1720
tagNames: string[]
1821
}

0 commit comments

Comments
 (0)