Fix/edit user label (#1631)
* fixed user label editing bug * fixed user label editing bug * feedback Co-authored-by: Agnieszka Gancarczyk <agancarc@redhat.com>
This commit is contained in:
parent
bc8ffed934
commit
72c34e0d46
1 changed files with 14 additions and 10 deletions
|
@ -243,9 +243,13 @@ export const UserCredentials = ({ user }: UserCredentialsProps) => {
|
||||||
}, [selectedCredential.credentialData]);
|
}, [selectedCredential.credentialData]);
|
||||||
|
|
||||||
const saveUserLabel = async () => {
|
const saveUserLabel = async () => {
|
||||||
|
const credentialToEdit = userCredentials.find(
|
||||||
|
(credential) => credential.id === editedUserCredential.id
|
||||||
|
);
|
||||||
|
|
||||||
const userLabelFormValue = getValues1();
|
const userLabelFormValue = getValues1();
|
||||||
|
|
||||||
if (Object.keys(editedUserCredential).length === 0) {
|
if (!credentialToEdit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,17 +257,18 @@ export const UserCredentials = ({ user }: UserCredentialsProps) => {
|
||||||
await adminClient.users.updateCredentialLabel(
|
await adminClient.users.updateCredentialLabel(
|
||||||
{
|
{
|
||||||
id: user.id!,
|
id: user.id!,
|
||||||
credentialId: editedUserCredential.id!,
|
credentialId: credentialToEdit.id!,
|
||||||
},
|
},
|
||||||
userLabelFormValue.userLabel || ""
|
userLabelFormValue.userLabel || ""
|
||||||
);
|
);
|
||||||
refresh();
|
refresh();
|
||||||
addAlert(t("updateCredentialUserLabelSuccess"), AlertVariant.success);
|
addAlert(t("updateCredentialUserLabelSuccess"), AlertVariant.success);
|
||||||
setIsUserLabelEdit(false);
|
setEditedUserCredential({});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
addError(t("updateCredentialUserLabelError"), error);
|
addError(t("updateCredentialUserLabelError"), error);
|
||||||
setIsUserLabelEdit(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setIsUserLabelEdit(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -475,7 +480,7 @@ export const UserCredentials = ({ user }: UserCredentialsProps) => {
|
||||||
</Tr>
|
</Tr>
|
||||||
</Thead>
|
</Thead>
|
||||||
<Tbody>
|
<Tbody>
|
||||||
<Tr key={"key"}>
|
<Tr>
|
||||||
{userCredentials.map((credential) => (
|
{userCredentials.map((credential) => (
|
||||||
<>
|
<>
|
||||||
<Td
|
<Td
|
||||||
|
@ -506,11 +511,9 @@ export const UserCredentials = ({ user }: UserCredentialsProps) => {
|
||||||
/>
|
/>
|
||||||
<div className="kc-userLabel-actionBtns">
|
<div className="kc-userLabel-actionBtns">
|
||||||
<Button
|
<Button
|
||||||
key={"key-acceptBtn"}
|
|
||||||
variant="link"
|
variant="link"
|
||||||
className="kc-editUserLabel-acceptBtn"
|
className="kc-editUserLabel-acceptBtn"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setEditedUserCredential(credential);
|
|
||||||
handleSubmit1(saveUserLabel)();
|
handleSubmit1(saveUserLabel)();
|
||||||
setIsUserLabelEdit(false);
|
setIsUserLabelEdit(false);
|
||||||
}}
|
}}
|
||||||
|
@ -518,7 +521,6 @@ export const UserCredentials = ({ user }: UserCredentialsProps) => {
|
||||||
icon={<CheckIcon />}
|
icon={<CheckIcon />}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
key={"key-cancelBtn"}
|
|
||||||
variant="link"
|
variant="link"
|
||||||
className="kc-editUserLabel-cancelBtn"
|
className="kc-editUserLabel-cancelBtn"
|
||||||
onClick={() => setIsUserLabelEdit(false)}
|
onClick={() => setIsUserLabelEdit(false)}
|
||||||
|
@ -531,10 +533,12 @@ export const UserCredentials = ({ user }: UserCredentialsProps) => {
|
||||||
<>
|
<>
|
||||||
{credential.userLabel ?? ""}
|
{credential.userLabel ?? ""}
|
||||||
<Button
|
<Button
|
||||||
key={"key"}
|
|
||||||
variant="link"
|
variant="link"
|
||||||
className="kc-editUserLabel-btn"
|
className="kc-editUserLabel-btn"
|
||||||
onClick={() => setIsUserLabelEdit(true)}
|
onClick={() => {
|
||||||
|
setEditedUserCredential(credential);
|
||||||
|
setIsUserLabelEdit(true);
|
||||||
|
}}
|
||||||
data-testid="editUserLabelBtn"
|
data-testid="editUserLabelBtn"
|
||||||
icon={<PencilAltIcon />}
|
icon={<PencilAltIcon />}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in a new issue