Create flow: session UI, draft sync, publish #44
Reference in New Issue
Block a user
Delete Branch "adilallo/feature/BackendImplementation2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Overview
This branch ships the signed-in create-flow experience, server draft sync (when enabled), anonymous → account draft transfer after magic link, and publish to
POST /api/rulesfrom final review. It aligns the app with the backend roadmap and Linear work through CR-77 (publish wiring), building on CR-75 (session affordances) and CR-76 (draft sync hardening).Goals: magic-link auth from header and create-flow exit,
PUT /api/drafts/mefor signed-in save/exit and post-login transfer, Finalize persistingPublishedRuleand showing the result on completed, with clearer errors and layout polish (viewport-anchored chrome, non-blocking error overlays, client-only create shell to avoid hydration mismatches after redirects).Changes
Auth & marketing shell
AuthModalProvider+ header Log in / Profile; login modal variants (default vs save progress);LoginFormsupportsmagicLinkNextPath,syncDraft=1transfer flag whennextincludes it.AuthModalProvider.Create flow state & persistence
localStorage(create-flow-anonymous); transfer-pending flag;CreateFlowContexthydration when guest persistence turns on.SignedInDraftHydration: load server draft with optional conflict handling vs anonymous copy; i18n for hydration copy.PostLoginDraftTransfer: after verify with?syncDraft=1,PUTdraft whenNEXT_PUBLIC_ENABLE_BACKEND_SYNC=true, or merge local draft into memory when sync is off; strips query after run.useCreateFlowExit: Save & Exit →saveDraftToServerwith parsed API errors; draft save banner context.CreateFlowBackendSyncin favor of explicit hooks/components.Publish (CR-77)
buildPublishPayload: mapsCreateFlowState→{ title, summary?, document }withCommunityRuleDocument-shapedsections+ fallback overview section.publishRule: resilient JSON/error handling and network failures; returnsstatusfor 401 handling.lastPublishedRule:sessionStoragebridge to completed (until a publicGET /api/rules/[id]exists)./create/final-review?syncDraft=1.Create layout
CreateFlowLayoutGate(dynamic+ssr: false) +CreateFlowLayoutClientto avoid hydration mismatches on pathname-heavy shell after magic-link redirects.API client & types
saveDraftToServer/fetchDraftFromServer;CreateFlowState+hasCreateFlowUserInputfor Save & Exit gating.CONTRIBUTING: notes onPOST /api/rules(new row per finalize) andsyncDraftbehavior when sync is off.Docs
docs/backend-roadmap.mdanddocs/backend-linear-tickets.mdfor current behavior and ticket alignment.Tests & stories
saveDraftToServer,buildPublishPayload,publishRule, draft hydration helpers,hasCreateFlowUserInput, Auth modal, Login/LoginForm, FinalReview, CreateFlowTopNav.Screenshots
How to Test
.envfrom.env.example; Postgres up (docker compose up -d postgres);npx prisma migrate dev; optionalNEXT_PUBLIC_ENABLE_BACKEND_SYNC=trueand Mailhog / dev log magic links.PUT /api/drafts/meand banner on failure.GET /api/ruleslists rule.npm run build,npx vitest run,npx tsc --noEmit(as in CI).Notes
RuleTemplate— not in this PR.GET /api/rules/[id](e.g. CR-81) to replacesessionStoragefor completed; profile / my rules (CR-86); API error contract (CR-84). Each finalize still creates a new published row until an update API exists (documented in CONTRIBUTING).ssr: false: brief black loading shell while the create layout chunk loads—tradeoff for stable client navigation after auth redirects.