From 9011f436ae60e776fa09a30730c14010f8e06ca5 Mon Sep 17 00:00:00 2001 From: mgold1234 Date: Tue, 23 Jan 2024 12:27:45 +0200 Subject: [PATCH] Resolve Controlled Component Error by Initializing with Empty Strings --- .../steps/TargetEnvironment/Aws/index.tsx | 4 +-- src/store/wizardSlice.ts | 28 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Components/CreateImageWizardV2/steps/TargetEnvironment/Aws/index.tsx b/src/Components/CreateImageWizardV2/steps/TargetEnvironment/Aws/index.tsx index 54928db020..4dd8f3237f 100644 --- a/src/Components/CreateImageWizardV2/steps/TargetEnvironment/Aws/index.tsx +++ b/src/Components/CreateImageWizardV2/steps/TargetEnvironment/Aws/index.tsx @@ -82,7 +82,7 @@ const Aws = () => { isChecked={shareMethod === 'sources'} onChange={() => { dispatch(changeAwsSource(undefined)); - dispatch(changeAwsAccountId(undefined)); + dispatch(changeAwsAccountId('')); dispatch(changeAwsShareMethod('sources')); }} /> @@ -93,7 +93,7 @@ const Aws = () => { isChecked={shareMethod === 'manual'} onChange={() => { dispatch(changeAwsSource(undefined)); - dispatch(changeAwsAccountId(undefined)); + dispatch(changeAwsAccountId('')); dispatch(changeAwsShareMethod('manual')); }} /> diff --git a/src/store/wizardSlice.ts b/src/store/wizardSlice.ts index 558734abd4..f227be7857 100644 --- a/src/store/wizardSlice.ts +++ b/src/store/wizardSlice.ts @@ -23,21 +23,21 @@ import { RootState } from '.'; type wizardState = { env: { - serverUrl: string | undefined; - baseUrl: string | undefined; + serverUrl: string; + baseUrl: string; }; architecture: ImageRequest['architecture']; distribution: Distributions; imageTypes: ImageTypes[]; aws: { - accountId: string | undefined; + accountId: string; shareMethod: AwsShareMethod; source: V1ListSourceResponseItem | undefined; }; gcp: { shareMethod: GcpShareMethod; accountType: GcpAccountType; - email: string | undefined; + email: string; }; registration: { registrationType: string; @@ -57,21 +57,21 @@ type wizardState = { const initialState: wizardState = { env: { - serverUrl: undefined, - baseUrl: undefined, + serverUrl: '', + baseUrl: '', }, architecture: X86_64, distribution: RHEL_9, imageTypes: [], aws: { - accountId: undefined, + accountId: '', shareMethod: 'sources', source: undefined, }, gcp: { shareMethod: 'withGoogle', accountType: 'google', - email: undefined, + email: '', }, registration: { registrationType: 'register-now-rhc', @@ -109,7 +109,7 @@ export const selectImageTypes = (state: RootState) => { return state.wizard.imageTypes; }; -export const selectAwsAccountId = (state: RootState): string | undefined => { +export const selectAwsAccountId = (state: RootState): string => { return state.wizard.aws.accountId; }; @@ -164,10 +164,10 @@ export const wizardSlice = createSlice({ initialState, reducers: { initializeWizard: () => initialState, - changeServerUrl: (state, action: PayloadAction) => { + changeServerUrl: (state, action: PayloadAction) => { state.env.serverUrl = action.payload; }, - changeBaseUrl: (state, action: PayloadAction) => { + changeBaseUrl: (state, action: PayloadAction) => { state.env.baseUrl = action.payload; }, changeArchitecture: ( @@ -194,7 +194,7 @@ export const wizardSlice = createSlice({ changeImageTypes: (state, action: PayloadAction) => { state.imageTypes = action.payload; }, - changeAwsAccountId: (state, action: PayloadAction) => { + changeAwsAccountId: (state, action: PayloadAction) => { state.aws.accountId = action.payload; }, changeAwsShareMethod: (state, action: PayloadAction) => { @@ -210,7 +210,7 @@ export const wizardSlice = createSlice({ switch (action.payload) { case 'withInsights': state.gcp.accountType = undefined; - state.gcp.email = undefined; + state.gcp.email = ''; break; case 'withGoogle': state.gcp.accountType = 'google'; @@ -220,7 +220,7 @@ export const wizardSlice = createSlice({ changeGcpAccountType: (state, action: PayloadAction) => { state.gcp.accountType = action.payload; }, - changeGcpEmail: (state, action: PayloadAction) => { + changeGcpEmail: (state, action: PayloadAction) => { state.gcp.email = action.payload; }, changeRegistrationType: (state, action: PayloadAction) => {