Skip to content

Commit b416dd5

Browse files
committed
refactor(edit-name-agent-modal): add isValid flag for name validation
This change introduces an `isValid` flag to the validation state, improving clarity and consistency when checking if the agent name is valid. The flag is used in the Enter key handler to determine if the save action should proceed.
1 parent 2258d2c commit b416dd5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

plugins/wazuh-fleet/public/components/agents/list/actions/edit-name-agent-modal.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ export const EditAgentNameModal = ({
3333
const [newName, setNewName] = useState('');
3434
const [isSaving, setIsSaving] = useState(false);
3535
const [validateName, setValidateName] = useState<{
36+
isValid: boolean;
3637
isInvalid: boolean;
3738
errors: string[];
3839
}>({
40+
isValid: true,
3941
isInvalid: false,
4042
errors: [],
4143
});
@@ -61,6 +63,7 @@ export const EditAgentNameModal = ({
6163
}
6264

6365
setValidateName({
66+
isValid: errors.length === 0,
6467
isInvalid: errors.length > 0,
6568
errors: errors,
6669
});
@@ -118,7 +121,7 @@ export const EditAgentNameModal = ({
118121
if (event.key === 'Enter') {
119122
event.preventDefault();
120123

121-
if (!validateName.isInvalid) {
124+
if (validateName.isValid) {
122125
handleSave();
123126
}
124127
}

0 commit comments

Comments
 (0)