@betterstart/cli 0.1.56 → 0.1.58
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 +15 -12
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2667,7 +2667,7 @@ export function ${p7.pascal}Form() {
|
|
|
2667
2667
|
import { zodResolver } from '@hookform/resolvers/zod'
|
|
2668
2668
|
import { ChevronLeft, ChevronRight${p7.hasListFields ? ", Trash2" : ""} } from 'lucide-react'
|
|
2669
2669
|
import { parseAsInteger, useQueryState } from 'nuqs'
|
|
2670
|
-
import {
|
|
2670
|
+
import { useState } from 'react'
|
|
2671
2671
|
${p7.rhfImport}
|
|
2672
2672
|
import { z } from 'zod/v3'${queryClientImport}
|
|
2673
2673
|
import { create${p7.pascal}Submission } from '@cms/actions/${p7.kebab}-form'
|
|
@@ -2709,24 +2709,27 @@ ${formComponentDecl}() {
|
|
|
2709
2709
|
|
|
2710
2710
|
const form = useForm<FormValues>({
|
|
2711
2711
|
resolver: zodResolver(formSchema),
|
|
2712
|
-
mode: '
|
|
2712
|
+
mode: 'onSubmit',
|
|
2713
2713
|
defaultValues: {
|
|
2714
2714
|
${p7.defaults}
|
|
2715
2715
|
},
|
|
2716
2716
|
})
|
|
2717
2717
|
|
|
2718
|
-
const prevStep = useRef(currentStep)
|
|
2719
|
-
useEffect(() => {
|
|
2720
|
-
if (currentStep !== prevStep.current) {
|
|
2721
|
-
form.clearErrors(STEPS[currentStep].fields as (keyof FormValues)[])
|
|
2722
|
-
prevStep.current = currentStep
|
|
2723
|
-
}
|
|
2724
|
-
}, [currentStep, form])
|
|
2725
2718
|
${p7.fieldArraySetup}${p7.watchSetup}
|
|
2726
2719
|
async function handleNext() {
|
|
2727
|
-
const
|
|
2728
|
-
|
|
2729
|
-
)
|
|
2720
|
+
const stepFields = STEPS[currentStep].fields as (keyof FormValues)[]
|
|
2721
|
+
const values = form.getValues()
|
|
2722
|
+
form.clearErrors(stepFields)
|
|
2723
|
+
let isValid = true
|
|
2724
|
+
for (const fieldName of stepFields) {
|
|
2725
|
+
const fieldSchema = formSchema.shape[fieldName]
|
|
2726
|
+
if (!fieldSchema) continue
|
|
2727
|
+
const result = fieldSchema.safeParse(values[fieldName])
|
|
2728
|
+
if (!result.success) {
|
|
2729
|
+
form.setError(fieldName, { type: 'validate', message: result.error.issues[0].message })
|
|
2730
|
+
isValid = false
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2730
2733
|
if (isValid) {
|
|
2731
2734
|
setCurrentStep(currentStep + 1)
|
|
2732
2735
|
}
|