@@ -4,7 +4,7 @@ import { useEffect, useRef, useState } from "react";
44import useIsWriteable from "@/hooks/useIsWriteable" ;
55import { useMintHypercert } from "@/hypercerts/hooks/useMintHypercert" ;
66import { useLocalStorage } from "react-use" ;
7- import { type FieldErrors , useForm , useWatch } from "react-hook-form" ;
7+ import { type FieldErrors , useForm } from "react-hook-form" ;
88import { zodResolver } from "@hookform/resolvers/zod" ;
99import { toast } from "@/components/ui/use-toast" ;
1010import {
@@ -178,17 +178,16 @@ export function HypercertMintingForm({
178178} ) {
179179 const [ currentStep , setCurrentStep ] = useState ( 1 ) ;
180180 const [ language , setLanguage ] = useState ( "en-US" ) ;
181- const {
182- writeable,
183- errors : writeableErrors ,
184- resetErrors : resetWriteableErrors ,
185- } = useIsWriteable ( ) ;
181+ const { errors : writeableErrors } = useIsWriteable ( ) ;
186182
187183 const { mutateAsync : mintHypercert } = useMintHypercert ( ) ;
188184 const { mutateAsync : createBlueprint } = useCreateBlueprint ( ) ;
189- const [ value , setValue ] = useLocalStorage < HypercertFormValues > (
190- "user-hypercert-create-form-data" ,
191- formDefaultValues ,
185+ const localStorageKey = blueprintId
186+ ? `user-hypercert-blueprint-${ blueprintId } -form-data`
187+ : "user-hypercert-create-form-data" ;
188+ const [ values , setValues ] = useLocalStorage < HypercertFormValues > (
189+ localStorageKey ,
190+ presetValues || formDefaultValues ,
192191 {
193192 raw : false ,
194193 serializer : JSON . stringify ,
@@ -202,37 +201,24 @@ export function HypercertMintingForm({
202201 blueprint_minter_address : true ,
203202 } ) ;
204203
205- const defaultValues = presetValues
206- ? {
207- ...presetValues ,
208- allowlistEntries : presetValues . allowlistEntries ?. map ( ( entry ) => ( {
209- ...entry ,
210- units : BigInt ( entry . units ) ,
211- } ) ) ,
212- projectDates : {
213- to : new Date ( presetValues . projectDates . to ) ,
214- from : new Date ( presetValues . projectDates . from ) ,
215- } ,
216- }
217- : value ;
218-
219204 const form = useForm < HypercertFormValues > ( {
220205 resolver : zodResolver ( formSchemaUsed ) ,
221- defaultValues,
206+ defaultValues : values ,
222207 mode : "onBlur" ,
223208 } ) ;
224209
225- const watchedValues = useWatch ( {
226- control : form . control ,
227- name : [ "title" , "banner" , "logo" , "tags" , "projectDates" ] ,
228- } ) ;
210+ const title = form . watch ( "title" ) ;
211+ const banner = form . watch ( "banner" ) ;
212+ const logo = form . watch ( "logo" ) ;
213+ const tags = form . watch ( "tags" ) ;
214+ const projectDates = form . watch ( "projectDates" ) ;
229215
230216 const cardPreviewData = {
231- title : watchedValues [ 0 ] ?? formDefaultValues . title ,
232- banner : watchedValues [ 1 ] ?? formDefaultValues . banner ,
233- logo : watchedValues [ 2 ] ?? formDefaultValues . logo ,
234- tags : watchedValues [ 3 ] ?? formDefaultValues . tags ,
235- projectDates : watchedValues [ 4 ] ?? formDefaultValues . projectDates ,
217+ title : title ?? formDefaultValues . title ,
218+ banner : banner ?? formDefaultValues . banner ,
219+ logo : logo ?? formDefaultValues . logo ,
220+ tags : tags ?? formDefaultValues . tags ,
221+ projectDates : projectDates ?? formDefaultValues . projectDates ,
236222 } ;
237223 const cardRef = useRef < HTMLDivElement > ( null ) ;
238224
@@ -241,12 +227,11 @@ export function HypercertMintingForm({
241227 } , [ ] ) ;
242228
243229 const onBlur = ( ) => {
244- console . log ( "blur" ) ;
245- setValue ( form . getValues ( ) ) ;
230+ setValues ( form . getValues ( ) ) ;
246231 } ;
247232
248233 const onReset = ( ) => {
249- setValue ( formDefaultValues ) ;
234+ setValues ( formDefaultValues ) ;
250235 form . reset ( formDefaultValues ) ;
251236 setCurrentStep ( 1 ) ;
252237 } ;
0 commit comments