-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds
useMutation
compatible utility function and other abstractions (…
- Loading branch information
1 parent
69527b8
commit ba80ea9
Showing
12 changed files
with
194 additions
and
71 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
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
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,26 @@ | ||
import { callApi } from "@/Utils/request/query"; | ||
import { APICallOptions, Route } from "@/Utils/request/types"; | ||
|
||
/** | ||
* Creates a TanStack Query compatible mutation function. | ||
* | ||
* Example: | ||
* ```tsx | ||
* const { mutate: createPrescription, isPending } = useMutation({ | ||
* mutationFn: mutate(MedicineRoutes.createPrescription, { | ||
* pathParams: { consultationId }, | ||
* }), | ||
* onSuccess: () => { | ||
* toast.success(t("medication_request_prescribed")); | ||
* }, | ||
* }); | ||
* ``` | ||
*/ | ||
export default function mutate<TData, TBody>( | ||
route: Route<TData, TBody>, | ||
options?: APICallOptions<TBody>, | ||
) { | ||
return (variables: TBody) => { | ||
return callApi(route, { ...options, body: variables }); | ||
}; | ||
} |
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 was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.