Skip to content

Commit

Permalink
feat: api utils make router optional (#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusualhashash authored Dec 4, 2024
2 parents cbedb15 + 189ef73 commit 8347b32
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions apps/web/src/app/[lang]/app/actions/api-utils-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import type { ServerResponse } from "src/lib";

export const handlePutResponse = (
response: { type: "success" | "error" | "api-error"; message: string },
router: AppRouterInstance,
router?: AppRouterInstance,
redirectTo?: string,
) => {
if (response.type === "success") {
toast.success("Updated successfully");
if (!router) return;
if (redirectTo) {
router.push(redirectTo);
}
Expand All @@ -22,13 +23,14 @@ export const handlePutResponse = (

export const handlePostResponse = <T>(
response: ServerResponse<T>,
router: AppRouterInstance,
router?: AppRouterInstance,
redirectTo?:
| string
| { prefix: string; identifier: keyof T; suffix?: string },
) => {
if (response.type === "success") {
toast.success("Created successfully");
if (!router) return;
if (typeof redirectTo === "string") {
router.push(redirectTo);
} else if (redirectTo) {
Expand All @@ -43,11 +45,12 @@ export const handlePostResponse = <T>(
};
export const handleDeleteResponse = (
response: { type: "success" | "error" | "api-error"; message: string },
router: AppRouterInstance,
router?: AppRouterInstance,
redirectTo?: string,
) => {
if (response.type === "success") {
toast.success("Deleted successfully");
if (!router) return;
if (redirectTo) {
router.push(redirectTo);
}
Expand Down

0 comments on commit 8347b32

Please sign in to comment.