-
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: prompt validation functionality (#3473)
* Added post validate prompt mutation * Updated prompt modal to use mutation to validate prompt * Removed post validate prompt from API.ts
- Loading branch information
1 parent
a734153
commit 081996e
Showing
3 changed files
with
91 additions
and
60 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
48 changes: 48 additions & 0 deletions
48
src/frontend/src/controllers/API/queries/nodes/use-post-validate-prompt.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,48 @@ | ||
import { | ||
APIClassType, | ||
PromptTypeAPI, | ||
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 IPostValidatePrompt { | ||
name: string; | ||
template: string; | ||
frontend_node: APIClassType; | ||
} | ||
|
||
export const usePostValidatePrompt: useMutationFunctionType< | ||
undefined, | ||
IPostValidatePrompt, | ||
PromptTypeAPI, | ||
ResponseErrorDetailAPI | ||
> = (options?) => { | ||
const { mutate } = UseRequestProcessor(); | ||
|
||
const postValidatePromptFn = async ( | ||
payload: IPostValidatePrompt, | ||
): Promise<PromptTypeAPI> => { | ||
const response = await api.post<PromptTypeAPI>( | ||
getURL("VALIDATE", { 1: "prompt" }), | ||
{ | ||
name: payload.name, | ||
template: payload.template, | ||
frontend_node: payload.frontend_node, | ||
}, | ||
); | ||
|
||
return response.data; | ||
}; | ||
|
||
const mutation: UseMutationResult< | ||
PromptTypeAPI, | ||
ResponseErrorDetailAPI, | ||
IPostValidatePrompt | ||
> = mutate(["usePostValidatePrompt"], postValidatePromptFn, 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