Skip to content

Commit 5592be7

Browse files
authored
SSH Migration: Improve the tracks event information (#107515)
1 parent 18a8fce commit 5592be7

File tree

1 file changed

+31
-0
lines changed
  • client/landing/stepper/declarative-flow/internals/steps-repository/site-migration-ssh-share-access

1 file changed

+31
-0
lines changed

client/landing/stepper/declarative-flow/internals/steps-repository/site-migration-ssh-share-access/index.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useLocale } from '@automattic/i18n-utils';
22
import { Step } from '@automattic/onboarding';
33
import { useQueryClient } from '@tanstack/react-query';
44
import { Button } from '@wordpress/components';
5+
import emailValidator from 'email-validator';
56
import { translate } from 'i18n-calypso';
67
import { useCallback, useEffect, useState } from 'react';
78
import DocumentHead from 'calypso/components/data/document-head';
@@ -31,6 +32,31 @@ import type { ImporterPlatform } from 'calypso/lib/importer/types';
3132

3233
import './styles.scss';
3334

35+
/**
36+
* Check if a string is a valid IPv4 address
37+
* @param value - The string to validate
38+
* @returns True if the string is a valid IPv4 address
39+
*/
40+
const isValidIPv4 = ( value: string ): boolean => {
41+
return (
42+
/^(\d{1,3}\.){3}\d{1,3}$/.test( value ) &&
43+
value.split( '.' ).every( ( octet ) => {
44+
const num = parseInt( octet, 10 );
45+
return num >= 0 && num <= 255;
46+
} )
47+
);
48+
};
49+
50+
/**
51+
* Check if a string is a valid IPv6 address
52+
* @param value - The string to validate
53+
* @returns True if the string is a valid IPv6 address
54+
*/
55+
const isValidIPv6 = ( value: string ): boolean => {
56+
// Simplified IPv6 check - looks for hex groups separated by colons
57+
return /^[a-f0-9:]+$/i.test( value );
58+
};
59+
3460
const SiteMigrationSshShareAccess: StepType< {
3561
submits: {
3662
destination?:
@@ -226,6 +252,11 @@ const SiteMigrationSshShareAccess: StepType< {
226252
step: 'share_access',
227253
action: 'click_button',
228254
button: 'continue',
255+
authentication_method: formState.authMethod,
256+
is_username_email: emailValidator.validate( formState.username ),
257+
is_server_address_ip:
258+
isValidIPv4( formState.serverAddress ) || isValidIPv6( formState.serverAddress ),
259+
host: host,
229260
} );
230261
setMigrationError( null );
231262

0 commit comments

Comments
 (0)