Skip to content

Commit 859a7f9

Browse files
authored
A4A: Fix parsing bug with Signup data via request parameter. (#103526)
* Fix parsing but with Signup data via request parameter. * Change sanitize function name.
1 parent a1358c0 commit 859a7f9

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

client/a8c-for-agencies/sections/signup/lib/signup-data-from-reqest-parameters.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getQueryArg } from '@wordpress/url';
12
import { isValidUrl } from 'calypso/a8c-for-agencies/components/form/utils';
23
import { AgencyDetailsPayload } from '../agency-details-form/types';
34

@@ -40,16 +41,13 @@ const sanitizePhone = ( phoneNumber: string | null ) => {
4041
};
4142

4243
/**
43-
* Sanitizes comma-separated values into an array
44+
* Sanitizes string array
4445
*/
45-
const sanitizeArrayFromString = ( value: string | null ): string[] => {
46-
if ( ! value ) {
46+
const sanitizeStringArray = ( values: string[] ): string[] => {
47+
if ( ! values ) {
4748
return [];
4849
}
49-
return value
50-
.split( ',' )
51-
.map( ( item ) => sanitizeString( item ) )
52-
.filter( Boolean );
50+
return values.map( ( item ) => sanitizeString( item ) ).filter( Boolean );
5351
};
5452

5553
export function getSignupDataFromRequestParameters(): AgencyDetailsPayload | null {
@@ -66,9 +64,15 @@ export function getSignupDataFromRequestParameters(): AgencyDetailsPayload | nul
6664
}
6765

6866
// 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+
);
7276

7377
// Get phone number
7478
const phone = sanitizePhone( searchParams.get( 'phone_number' ) );

0 commit comments

Comments
 (0)