Fix save progress bug
This commit is contained in:
@@ -41,6 +41,7 @@ export async function fetchAuthSession(): Promise<{
|
||||
export async function requestMagicLink(
|
||||
email: string,
|
||||
nextPath?: string,
|
||||
draft?: CreateFlowState,
|
||||
): Promise<{ ok: true } | { ok: false; error: string; retryAfterMs?: number }> {
|
||||
const res = await fetch("/api/auth/magic-link/request", {
|
||||
method: "POST",
|
||||
@@ -49,6 +50,7 @@ export async function requestMagicLink(
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
...(nextPath ? { next: nextPath } : {}),
|
||||
...(draft && Object.keys(draft).length > 0 ? { draft } : {}),
|
||||
}),
|
||||
});
|
||||
const data = await parseJson<{ error?: string; retryAfterMs?: number }>(res);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { CreateFlowState, CreateFlowStep } from "../../app/(app)/create/types";
|
||||
|
||||
/** Snapshot for save-progress / draft transfer (includes optional resume step). */
|
||||
export function buildCreateFlowDraftPayload(
|
||||
state: CreateFlowState,
|
||||
currentStep?: CreateFlowStep | null,
|
||||
): CreateFlowState {
|
||||
return {
|
||||
...state,
|
||||
...(currentStep ? { currentStep } : {}),
|
||||
};
|
||||
}
|
||||
@@ -222,3 +222,10 @@ export const putDraftBodySchema = z.object({
|
||||
payload: createFlowStateSchema,
|
||||
});
|
||||
export type CreateFlowStateValidated = z.infer<typeof createFlowStateSchema>;
|
||||
|
||||
export const magicLinkRequestBodySchema = z.object({
|
||||
email: z.string(),
|
||||
next: z.string().optional(),
|
||||
draft: createFlowStateSchema.optional(),
|
||||
});
|
||||
export type MagicLinkRequestBody = z.infer<typeof magicLinkRequestBodySchema>;
|
||||
|
||||
Reference in New Issue
Block a user