Skip to content

Commit 56ad17a

Browse files
committed
fix: #OBS-I494: updated user form reset
1 parent d6306e2 commit 56ad17a

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

web-console-v2/src/pages/UserManagement/AddUser.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,26 @@ const AddUser: React.FC<AddUserProps> = ({ open, onClose, onSubmit, currentUser
7070
};
7171

7272
const handleSubmit = () => {
73-
try{
73+
try {
7474
setTimeout(() => {
7575
onSubmit(newUser);
7676
onClose();
77-
setNewUser({
78-
user_name: '',
79-
email_address: '',
80-
roles: ['viewer'],
81-
password: ''
82-
});
77+
resetForm();
8378
}, 1000);
84-
}
85-
catch (error) {
79+
} catch (error) {
8680
showAlert('Failed to create user', 'error');
8781
}
8882
};
8983

84+
const resetForm = () => {
85+
setNewUser({
86+
user_name: '',
87+
email_address: '',
88+
roles: ['viewer'],
89+
password: '',
90+
});
91+
};
92+
9093
const isEmailValid = newUser.email_address ? emailRegex.test(newUser.email_address) : true;
9194
const isFormValid =
9295
newUser.user_name &&
@@ -99,8 +102,13 @@ const AddUser: React.FC<AddUserProps> = ({ open, onClose, onSubmit, currentUser
99102

100103
const availableRoles = currentUser?.is_owner ? rolesOptions : rolesOptions.filter(role => role.value !== 'admin');
101104

105+
const handleCancel = () => {
106+
resetForm();
107+
onClose();
108+
};
109+
102110
return (
103-
<Dialog open={open} onClose={onClose}>
111+
<Dialog open={open} onClose={handleCancel}>
104112
<DialogTitle>Create New User</DialogTitle>
105113
<DialogContent>
106114
<TextField
@@ -176,7 +184,7 @@ const AddUser: React.FC<AddUserProps> = ({ open, onClose, onSubmit, currentUser
176184
</FormControl>
177185
</DialogContent>
178186
<DialogActions>
179-
<Button onClick={onClose} color="primary" variant='outlined' size='small'>
187+
<Button onClick={handleCancel} color="primary" variant='outlined' size='small'>
180188
Cancel
181189
</Button>
182190
<Button onClick={handleSubmit} color="primary" variant='contained' size='small' disabled={!isFormValid}>

0 commit comments

Comments
 (0)