Skip to content

Commit 9b37224

Browse files
committedJun 11, 2024
feat: add Next navigation props to onSuccess and onSettled action callbacks
1 parent 57b167d commit 9b37224

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed
 

‎packages/next-safe-action/src/action-builder.ts

+8
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ export function actionBuilder<
256256
bindArgsClientInputs: (bindArgsSchemas.length ? clientInputs.slice(0, -1) : []) as InferInArray<BAS>,
257257
parsedInput: parsedInputDatas.at(-1) as S extends Schema ? Infer<S> : undefined,
258258
bindArgsParsedInputs: parsedInputDatas.slice(0, -1) as InferArray<BAS>,
259+
hasRedirected: isRedirectError(frameworkError),
260+
hasNotFound: isNotFoundError(frameworkError),
259261
})
260262
);
261263

@@ -264,6 +266,8 @@ export function actionBuilder<
264266
clientInput: clientInputs.at(-1) as S extends Schema ? InferIn<S> : undefined,
265267
bindArgsClientInputs: (bindArgsSchemas.length ? clientInputs.slice(0, -1) : []) as InferInArray<BAS>,
266268
result: {},
269+
hasRedirected: isRedirectError(frameworkError),
270+
hasNotFound: isNotFoundError(frameworkError),
267271
})
268272
);
269273

@@ -296,6 +300,8 @@ export function actionBuilder<
296300
bindArgsClientInputs: (bindArgsSchemas.length ? clientInputs.slice(0, -1) : []) as InferInArray<BAS>,
297301
parsedInput: parsedInputDatas.at(-1) as S extends Schema ? Infer<S> : undefined,
298302
bindArgsParsedInputs: parsedInputDatas.slice(0, -1) as InferArray<BAS>,
303+
hasRedirected: false,
304+
hasNotFound: false,
299305
})
300306
);
301307
} else {
@@ -314,6 +320,8 @@ export function actionBuilder<
314320
clientInput: clientInputs.at(-1) as S extends Schema ? InferIn<S> : undefined,
315321
bindArgsClientInputs: (bindArgsSchemas.length ? clientInputs.slice(0, -1) : []) as InferInArray<BAS>,
316322
result: actionResult,
323+
hasRedirected: false,
324+
hasNotFound: false,
317325
})
318326
);
319327

‎packages/next-safe-action/src/index.types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ export type SafeActionCallbacks<
141141
bindArgsClientInputs: InferInArray<BAS>;
142142
parsedInput: S extends Schema ? Infer<S> : undefined;
143143
bindArgsParsedInputs: InferArray<BAS>;
144+
hasRedirected: boolean;
145+
hasNotFound: boolean;
144146
}) => MaybePromise<void>;
145147
onError?: (args: {
146148
error: Prettify<Omit<SafeActionResult<ServerError, S, BAS, CVE, CBAVE, Data>, "data">>;
@@ -151,5 +153,7 @@ export type SafeActionCallbacks<
151153
result: Prettify<SafeActionResult<ServerError, S, BAS, CVE, CBAVE, Data>>;
152154
clientInput: S extends Schema ? InferIn<S> : undefined;
153155
bindArgsClientInputs: InferInArray<BAS>;
156+
hasRedirected: boolean;
157+
hasNotFound: boolean;
154158
}) => MaybePromise<void>;
155159
};

‎website/docs/safe-action-client/action-callbacks.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ const action = actionClient
1616
.action(async () => {
1717
// ...
1818
}, {
19-
onSuccess: ({ data, clientInput, bindArgsClientInputs, parsedInput, bindArgsParsedInputs }) => {},
19+
onSuccess: ({
20+
data,
21+
clientInput,
22+
bindArgsClientInputs,
23+
parsedInput,
24+
bindArgsParsedInputs,
25+
hasRedirected,
26+
hasNotFound,
27+
}) => {},
2028
onError: ({ error, clientInput, bindArgsClientInputs }) => {},
2129
onSettled: ({ result, clientInput, bindArgsClientInputs }) => {},
2230
});

0 commit comments

Comments
 (0)