@@ -15,44 +15,27 @@ export const PublicNoteSchema = z.object({
1515 . object ( {
1616 startDate : z . string ( ) . optional ( ) ,
1717 endDate : z . string ( ) . optional ( ) ,
18- autoRenewal : z . string ( ) . optional ( ) . default ( "" ) ,
19- cycle : z . string ( ) . optional ( ) . default ( "" ) ,
20- amount : z . string ( ) . optional ( ) . default ( "" ) ,
18+ autoRenewal : z . string ( ) . optional ( ) ,
19+ cycle : z . string ( ) . optional ( ) ,
20+ amount : z . string ( ) . optional ( ) ,
2121 } )
2222 . optional ( ) ,
2323 planDataMod : z
2424 . object ( {
25- bandwidth : z . string ( ) . optional ( ) . default ( "" ) ,
26- trafficVol : z . string ( ) . optional ( ) . default ( "" ) ,
27- trafficType : z . string ( ) . optional ( ) . default ( "" ) ,
28- IPv4 : z . string ( ) . optional ( ) . default ( "0" ) ,
29- IPv6 : z . string ( ) . optional ( ) . default ( "0" ) ,
30- networkRoute : z . string ( ) . optional ( ) . default ( "" ) ,
31- extra : z . string ( ) . optional ( ) . default ( "" ) ,
25+ bandwidth : z . string ( ) . optional ( ) ,
26+ trafficVol : z . string ( ) . optional ( ) ,
27+ trafficType : z . string ( ) . optional ( ) ,
28+ IPv4 : z . string ( ) . optional ( ) ,
29+ IPv6 : z . string ( ) . optional ( ) ,
30+ networkRoute : z . string ( ) . optional ( ) ,
31+ extra : z . string ( ) . optional ( ) ,
3232 } )
3333 . optional ( ) ,
3434} )
3535
3636export type PublicNote = z . infer < typeof PublicNoteSchema >
3737
38- export const defaultPublicNote : PublicNote = {
39- billingDataMod : {
40- startDate : "" ,
41- endDate : "" ,
42- autoRenewal : "" ,
43- cycle : "" ,
44- amount : "" ,
45- } ,
46- planDataMod : {
47- bandwidth : "" ,
48- trafficVol : "" ,
49- trafficType : "" ,
50- IPv4 : "0" ,
51- IPv6 : "0" ,
52- networkRoute : "" ,
53- extra : "" ,
54- } ,
55- }
38+ export const defaultPublicNote : PublicNote = { }
5639
5740export const isValidISOLike = ( v : string ) => {
5841 if ( ! v ) return true
@@ -77,36 +60,14 @@ export const parsePublicNote = (s?: string): PublicNote => {
7760 const obj = JSON . parse ( s )
7861 const parsed = PublicNoteSchema . safeParse ( obj )
7962 if ( parsed . success ) {
80- const v = parsed . data
81- return {
82- billingDataMod : {
83- startDate : v . billingDataMod ?. startDate ?? "" ,
84- endDate : v . billingDataMod ?. endDate ?? "" ,
85- autoRenewal : v . billingDataMod ?. autoRenewal ?? "" ,
86- cycle : v . billingDataMod ?. cycle ?? "" ,
87- amount : v . billingDataMod ?. amount ?? "" ,
88- } ,
89- planDataMod : {
90- bandwidth : v . planDataMod ?. bandwidth ?? "" ,
91- trafficVol : v . planDataMod ?. trafficVol ?? "" ,
92- trafficType : v . planDataMod ?. trafficType ?? "" ,
93- IPv4 : v . planDataMod ?. IPv4 === "1" ? "1" : "0" ,
94- IPv6 : v . planDataMod ?. IPv6 === "1" ? "1" : "0" ,
95- networkRoute : v . planDataMod ?. networkRoute ?? "" ,
96- extra : v . planDataMod ?. extra ?? "" ,
97- } ,
98- }
63+ return parsed . data
9964 }
10065 return defaultPublicNote
10166 } catch {
10267 return defaultPublicNote
10368 }
10469}
10570
106- /**
107- * Validate with zod and convert to a UI-friendly error map.
108- * Error keys follow the component's path naming; messages provided via i18n.t.
109- */
11071export const validatePublicNote = ( pn : PublicNote ) => {
11172 const errors : Partial < Record < string , string > > = { }
11273
0 commit comments