V2Wizard: Update GCP validator and state management

The e-mail validator now requires a domain.

Switching from 'withGoogle' to 'withInsights' now sets the other GCP
related options to 'undefined' in order to keep the store state such
that it accurately reflects the current wizard state.

This is done in the reducer, not via a listener. That is a bit
inconsistent with the current listeners in place but this is an evolving
design and the inconsistency is acceptable for now. We may either accept
it, move the reducer actions here into listeners, or move the existing
listeners into reducers at some point in the future.
This commit is contained in:
lucasgarfield 2024-01-12 12:38:51 +01:00 committed by Klara Simickova
parent 7c8cfe7f63
commit 5a3726a4c8
3 changed files with 17 additions and 4 deletions

View file

@ -15,7 +15,12 @@ import { ValidatedTextInput } from '../../../ValidatedTextInput';
import { isGcpEmailValid } from '../../../validators';
export type GcpShareMethod = 'withGoogle' | 'withInsights';
export type GcpAccountTypes = 'google' | 'service' | 'group' | 'domain';
export type GcpAccountType =
| 'google'
| 'service'
| 'group'
| 'domain'
| undefined;
const Gcp = () => {
const dispatch = useAppDispatch();

View file

@ -9,11 +9,11 @@ export const isAwsAccountIdValid = (awsAccountId: string | undefined) => {
return false;
};
// TODO: this validator thinks asdf@asdf is a valid e-mail address, is that intentional or a bug?
export const isGcpEmailValid = (gcpShareWithAccount: string | undefined) => {
if (
gcpShareWithAccount !== undefined &&
/^[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,}$/.test(gcpShareWithAccount)
/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,12}$/.test(gcpShareWithAccount) &&
gcpShareWithAccount.length <= 253
) {
return true;
}

View file

@ -7,7 +7,7 @@ import {
V1ListSourceResponseItem,
} from '../Components/CreateImageWizardV2/steps/TargetEnvironment/Aws';
import {
GcpAccountTypes as GcpAccountType,
GcpAccountType,
GcpShareMethod,
} from '../Components/CreateImageWizardV2/steps/TargetEnvironment/Gcp';
import { RHEL_9, X86_64 } from '../constants';
@ -126,6 +126,14 @@ export const wizardSlice = createSlice({
state.aws.source = action.payload;
},
changeGcpShareMethod: (state, action: PayloadAction<GcpShareMethod>) => {
switch (action.payload) {
case 'withInsights':
state.gcp.accountType = undefined;
state.gcp.email = undefined;
break;
case 'withGoogle':
state.gcp.accountType = 'google';
}
state.gcp.shareMethod = action.payload;
},
changeGcpAccountType: (state, action: PayloadAction<GcpAccountType>) => {