From afb42e3cbb5f8935aa9d8c68fbb93cc628f0e7e5 Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Fri, 17 Jan 2025 15:01:50 +0530 Subject: [PATCH] refactor(type): replace 'any' with generic type in POST request. --- src/features/user/CompleteSignup/index.tsx | 2 +- .../user/TreeMapper/MySpecies/SpeciesAutoComplete.tsx | 7 +++++-- src/utils/apiRequests/api.ts | 10 +++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/features/user/CompleteSignup/index.tsx b/src/features/user/CompleteSignup/index.tsx index daaaaca27..830faa8e8 100644 --- a/src/features/user/CompleteSignup/index.tsx +++ b/src/features/user/CompleteSignup/index.tsx @@ -178,7 +178,7 @@ export default function CompleteSignup(): ReactElement | null { setRequestSent(true); setIsProcessing(true); try { - const res = await postRequest({ + const res = await postRequest({ tenant: tenantConfig?.id, url: `/app/profile`, data: bodyToSend, diff --git a/src/features/user/TreeMapper/MySpecies/SpeciesAutoComplete.tsx b/src/features/user/TreeMapper/MySpecies/SpeciesAutoComplete.tsx index 59c21a791..a955270a7 100644 --- a/src/features/user/TreeMapper/MySpecies/SpeciesAutoComplete.tsx +++ b/src/features/user/TreeMapper/MySpecies/SpeciesAutoComplete.tsx @@ -25,7 +25,10 @@ interface Props< helperText?: React.ReactNode; // mySpecies?: any; } - +type SubmitData = { + q: string; + t: 'species'; +}; export default function SpeciesSelect< TFieldValues extends FieldValues, TName extends FieldPath @@ -62,7 +65,7 @@ export default function SpeciesSelect< // Todo: debouncing if (value.length > 2) { try { - const res = await postRequest({ + const res = await postRequest({ tenant: tenantConfig?.id, url: `/suggest.php`, data: { diff --git a/src/utils/apiRequests/api.ts b/src/utils/apiRequests/api.ts index 8a043b9ba..0a76e9d36 100644 --- a/src/utils/apiRequests/api.ts +++ b/src/utils/apiRequests/api.ts @@ -41,8 +41,8 @@ interface PutAuthRequestOptions extends BaseRequestOptions { data?: D; logoutUser: (value?: string | undefined) => void; } -interface PostRequestOptions extends BaseRequestOptions { - data: any; +interface PostRequestOptions extends BaseRequestOptions { + data: D; } interface GetRequestOptions extends BaseRequestOptions { queryParams?: { [key: string]: string }; @@ -221,7 +221,11 @@ export function postAuthenticatedRequest({ }); } -export function postRequest({ tenant, url, data }: PostRequestOptions) { +export function postRequest({ + tenant, + url, + data, +}: PostRequestOptions) { const lang = localStorage.getItem('language') || 'en'; return new Promise((resolve, reject) => { (async () => {