1
+ import { getQueryArg } from '@wordpress/url' ;
1
2
import { isValidUrl } from 'calypso/a8c-for-agencies/components/form/utils' ;
2
3
import { AgencyDetailsPayload } from '../agency-details-form/types' ;
3
4
@@ -40,16 +41,13 @@ const sanitizePhone = ( phoneNumber: string | null ) => {
40
41
} ;
41
42
42
43
/**
43
- * Sanitizes comma-separated values into an array
44
+ * Sanitizes string array
44
45
*/
45
- const sanitizeArrayFromString = ( value : string | null ) : string [ ] => {
46
- if ( ! value ) {
46
+ const sanitizeStringArray = ( values : string [ ] ) : string [ ] => {
47
+ if ( ! values ) {
47
48
return [ ] ;
48
49
}
49
- return value
50
- . split ( ',' )
51
- . map ( ( item ) => sanitizeString ( item ) )
52
- . filter ( Boolean ) ;
50
+ return values . map ( ( item ) => sanitizeString ( item ) ) . filter ( Boolean ) ;
53
51
} ;
54
52
55
53
export function getSignupDataFromRequestParameters ( ) : AgencyDetailsPayload | null {
@@ -66,9 +64,15 @@ export function getSignupDataFromRequestParameters(): AgencyDetailsPayload | nul
66
64
}
67
65
68
66
// Parse arrays from comma-separated strings
69
- const servicesOffered = sanitizeArrayFromString ( searchParams . get ( 'services_offered' ) ) ;
70
- const productsOffered = sanitizeArrayFromString ( searchParams . get ( 'products_offered' ) ) ;
71
- const productsToOffer = sanitizeArrayFromString ( searchParams . get ( 'products_to_offer' ) ) ;
67
+ const servicesOffered = sanitizeStringArray (
68
+ ( getQueryArg ( window . location . href , 'services_offered' ) as string [ ] ) ?? [ ]
69
+ ) ;
70
+ const productsOffered = sanitizeStringArray (
71
+ ( getQueryArg ( window . location . href , 'products_offered' ) as string [ ] ) ?? [ ]
72
+ ) ;
73
+ const productsToOffer = sanitizeStringArray (
74
+ ( getQueryArg ( window . location . href , 'products_to_offer' ) as string [ ] ) ?? [ ]
75
+ ) ;
72
76
73
77
// Get phone number
74
78
const phone = sanitizePhone ( searchParams . get ( 'phone_number' ) ) ;
0 commit comments