@betterstart/cli 0.1.47 → 0.1.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -2643,13 +2643,29 @@ function escapeQuotes(str) {
2643
2643
  return str.replace(/'/g, "\\'");
2644
2644
  }
2645
2645
  function buildComponentSource(p7) {
2646
+ const queryClientImport = p7.hasFileUpload ? `
2647
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'` : "";
2648
+ const queryClientSetup = p7.hasFileUpload ? `
2649
+ const queryClient = new QueryClient()
2650
+ ` : "";
2651
+ const formComponentDecl = p7.hasFileUpload ? `function ${p7.pascal}FormInner` : `export function ${p7.pascal}Form`;
2652
+ const exportWrapper = p7.hasFileUpload ? `
2653
+ export function ${p7.pascal}Form() {
2654
+ return (
2655
+ <QueryClientProvider client={queryClient}>
2656
+ <${p7.pascal}FormInner />
2657
+ </QueryClientProvider>
2658
+ )
2659
+ }
2660
+ ` : "";
2646
2661
  return `'use client'
2647
2662
 
2648
2663
  import { zodResolver } from '@hookform/resolvers/zod'
2649
2664
  import { Check, ChevronLeft, ChevronRight } from 'lucide-react'
2665
+ import { parseAsInteger, parseAsArrayOf, useQueryState } from 'nuqs'
2650
2666
  import { useState } from 'react'
2651
2667
  ${p7.rhfImport}
2652
- import { z } from 'zod/v3'
2668
+ import { z } from 'zod/v3'${queryClientImport}
2653
2669
  import { create${p7.pascal}Submission } from '@cms/actions/${p7.kebab}-form'
2654
2670
  import { Button } from '${p7.buttonImport}'
2655
2671
  import {
@@ -2679,12 +2695,13 @@ ${p7.zodFields}
2679
2695
  })
2680
2696
 
2681
2697
  type FormValues = z.infer<typeof formSchema>
2682
-
2698
+ ${queryClientSetup}
2683
2699
  ${p7.stepsConst}
2684
2700
 
2685
- export function ${p7.pascal}Form() {
2686
- const [currentStep, setCurrentStep] = useState(0)
2687
- const [completedSteps, setCompletedSteps] = useState<Set<number>>(new Set())
2701
+ ${formComponentDecl}() {
2702
+ const [currentStep, setCurrentStep] = useQueryState('step', parseAsInteger.withDefault(0))
2703
+ const [completedStepsArr, setCompletedStepsArr] = useQueryState('completed', parseAsArrayOf(parseAsInteger).withDefault([]))
2704
+ const completedSteps = new Set(completedStepsArr)
2688
2705
  const [submitted, setSubmitted] = useState(false)
2689
2706
  const [submitting, setSubmitting] = useState(false)
2690
2707
 
@@ -2701,13 +2718,15 @@ ${p7.fieldArraySetup}${p7.watchSetup}
2701
2718
  STEPS[currentStep].fields as (keyof FormValues)[]
2702
2719
  )
2703
2720
  if (isValid) {
2704
- setCompletedSteps((prev) => new Set(prev).add(currentStep))
2705
- setCurrentStep((prev) => prev + 1)
2721
+ if (!completedSteps.has(currentStep)) {
2722
+ setCompletedStepsArr([...completedStepsArr, currentStep])
2723
+ }
2724
+ setCurrentStep(currentStep + 1)
2706
2725
  }
2707
2726
  }
2708
2727
 
2709
2728
  function handleBack() {
2710
- setCurrentStep((prev) => prev - 1)
2729
+ setCurrentStep(currentStep - 1)
2711
2730
  }
2712
2731
 
2713
2732
  function handleStepClick(index: number) {
@@ -2829,7 +2848,7 @@ ${p7.stepContentBlocks}
2829
2848
  </Form>
2830
2849
  )
2831
2850
  }
2832
- `;
2851
+ ${exportWrapper}`;
2833
2852
  }
2834
2853
 
2835
2854
  // src/generators/form-pipeline/form-component-single.ts
@@ -2868,12 +2887,27 @@ ${buildFieldArrayDecls(listFields)}
2868
2887
  const selectImport = resolveUiImport(cwd, "select");
2869
2888
  const radioGroupImport = resolveUiImport(cwd, "radio-group");
2870
2889
  const mediaUploadImport = resolveUiImport(cwd, "media-upload-field");
2890
+ const queryClientImport = hasFileUpload ? `
2891
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'` : "";
2892
+ const queryClientSetup = hasFileUpload ? `
2893
+ const queryClient = new QueryClient()
2894
+ ` : "";
2895
+ const formComponentDecl = hasFileUpload ? `function ${pascal}FormInner` : `export function ${pascal}Form`;
2896
+ const exportWrapper = hasFileUpload ? `
2897
+ export function ${pascal}Form() {
2898
+ return (
2899
+ <QueryClientProvider client={queryClient}>
2900
+ <${pascal}FormInner />
2901
+ </QueryClientProvider>
2902
+ )
2903
+ }
2904
+ ` : "";
2871
2905
  const content = `'use client'
2872
2906
 
2873
2907
  import { zodResolver } from '@hookform/resolvers/zod'
2874
2908
  import { useState } from 'react'
2875
2909
  ${rhfImport}
2876
- import { z } from 'zod/v3'
2910
+ import { z } from 'zod/v3'${queryClientImport}
2877
2911
  import { create${pascal}Submission } from '@cms/actions/${kebab}-form'
2878
2912
  import { Button } from '${buttonImport}'
2879
2913
  import {
@@ -2902,8 +2936,8 @@ ${zodFields}
2902
2936
  })
2903
2937
 
2904
2938
  type FormValues = z.infer<typeof formSchema>
2905
-
2906
- export function ${pascal}Form() {
2939
+ ${queryClientSetup}
2940
+ ${formComponentDecl}() {
2907
2941
  const [submitted, setSubmitted] = useState(false)
2908
2942
  const [submitting, setSubmitting] = useState(false)
2909
2943
 
@@ -2955,7 +2989,7 @@ ${fieldJSX}
2955
2989
  </Form>
2956
2990
  )
2957
2991
  }
2958
- `;
2992
+ ${exportWrapper}`;
2959
2993
  fs9.writeFileSync(filePath, content, "utf-8");
2960
2994
  return { files: [path9.relative(cwd, filePath)] };
2961
2995
  }