-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add code validation functionality on tanstack mutation (#3469)
* Added Validate endpoint * Added API Code Validate type * Added post validate code hook * Used mutation instead of API call to validate code * Removed validate code api call
- Loading branch information
1 parent
bf650ec
commit f328179
Showing
5 changed files
with
89 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/frontend/src/controllers/API/queries/nodes/use-post-validate-code.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
APICodeValidateType, | ||
ResponseErrorDetailAPI, | ||
useMutationFunctionType, | ||
} from "@/types/api"; | ||
import { UseMutationResult } from "@tanstack/react-query"; | ||
import { api } from "../../api"; | ||
import { getURL } from "../../helpers/constants"; | ||
import { UseRequestProcessor } from "../../services/request-processor"; | ||
|
||
interface IPostValidateCode { | ||
code: string; | ||
} | ||
|
||
export const usePostValidateCode: useMutationFunctionType< | ||
undefined, | ||
IPostValidateCode, | ||
APICodeValidateType, | ||
ResponseErrorDetailAPI | ||
> = (options?) => { | ||
const { mutate } = UseRequestProcessor(); | ||
|
||
const postValidateCodeFn = async ( | ||
payload: IPostValidateCode, | ||
): Promise<APICodeValidateType> => { | ||
const response = await api.post<APICodeValidateType>( | ||
getURL("VALIDATE", { 1: "code" }), | ||
{ | ||
code: payload.code, | ||
}, | ||
); | ||
|
||
return response.data; | ||
}; | ||
|
||
const mutation: UseMutationResult< | ||
APICodeValidateType, | ||
ResponseErrorDetailAPI, | ||
IPostValidateCode | ||
> = mutate(["usePostValidateCode"], postValidateCodeFn, options); | ||
|
||
return mutation; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters