Skip to content

Commit

Permalink
Fix direct manipulation of state and clone the state before modifying…
Browse files Browse the repository at this point in the history
… the object
  • Loading branch information
bipuladh committed Feb 1, 2021
1 parent 79c6d11 commit 104291b
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ export const KMSConfigure: React.FC<KMSConfigureProps> = ({ state, dispatch, mod
const [kmsProvider, setKMSProvider] = React.useState<string>(KMSProviders[0].name);

const setServiceName = (name: string) => {
const kmsObj: KMSConfig = kms;
const kmsObj: KMSConfig = _.cloneDeep(kms);
kmsObj.name.value = name;
name !== '' ? (kms.name.valid = true) : (kms.name.valid = false);
kmsObj.hasHandled = kms.name.valid;
setEncryptionDispatch(ActionType.SET_KMS_ENCRYPTION, mode, dispatch, kmsObj);
};

const setAddress = (address: string) => {
const kmsObj: KMSConfig = kms;
const kmsObj: KMSConfig = _.cloneDeep(kms);
kmsObj.address.value = address;
address !== '' && parseURL(address.trim())
? (kms.address.valid = true)
Expand All @@ -52,7 +52,7 @@ export const KMSConfigure: React.FC<KMSConfigureProps> = ({ state, dispatch, mod
};

const setAddressPort = (port: string) => {
const kmsObj: KMSConfig = kms;
const kmsObj: KMSConfig = _.cloneDeep(kms);
kmsObj.port.value = port;
port !== '' && !_.isNaN(Number(port)) && Number(port) > 0
? (kms.port.valid = true)
Expand All @@ -62,7 +62,7 @@ export const KMSConfigure: React.FC<KMSConfigureProps> = ({ state, dispatch, mod
};

const setToken = (token: string) => {
const kmsObj: KMSConfig = kms;
const kmsObj: KMSConfig = _.cloneDeep(kms);
kmsObj.token.value = token;
token !== '' ? (kms.token.valid = true) : (kms.token.valid = false);
kmsObj.hasHandled = kms.token.valid;
Expand Down

0 comments on commit 104291b

Please sign in to comment.