Skip to content

Commit

Permalink
Update readOnly logic and set error in revert form
Browse files Browse the repository at this point in the history
  • Loading branch information
shreeyash07 authored and samshara committed Dec 18, 2024
1 parent a86e689 commit fc7e9a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"successMessage": "Local unit added successfully!",
"revertChangesSuccessMessage": "Local unit reverted successfully!",
"failedMessage": "Failed to add local unit",
"revertChangesfailedMessage": "Failed to revert changes in local unit",
"revertChangesFailedMessage": "Failed to revert changes in local unit",
"updateMessage": "Local unit updated successfully!",
"updateFailedMessage": "Failed to update local unit",
"specialitiesAndCapacityTitle": "Specialities & Capacity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ function LocalUnitsForm(props: Props) {
},
});

const readOnly = readOnlyFromProps || localUnitDetailsResponse?.is_locked;
const readOnly = readOnlyFromProps
|| isNotDefined(localUnitDetailsResponse)
|| localUnitDetailsResponse?.is_locked;

const {
response: localUnitsOptions,
Expand Down Expand Up @@ -558,18 +560,19 @@ function LocalUnitsForm(props: Props) {
{ variant: 'success' },
);
},
onFailure: (response) => {
onFailure: (error) => {
const {
value: { messageForNotification },
debugMessage,
} = response;
value: {
formErrors,
},
} = error;

setError(transformObjectError(formErrors, () => undefined));

alert.show(
strings.revertChangesfailedMessage,
strings.revertChangesFailedMessage,
{
variant: 'danger',
description: messageForNotification,
debugMessage,
},
);
},
Expand Down Expand Up @@ -639,6 +642,7 @@ function LocalUnitsForm(props: Props) {
<div className={styles.localUnitsForm}>
{!localUnitDetailsResponse?.is_locked
&& readOnlyFromProps
&& isNotDefined(localUnitDetailsResponse)
&& isDefined(actionsContainerRef.current) && (
<Portal container={actionsContainerRef.current}>
{(environment !== 'production') && (
Expand Down

0 comments on commit fc7e9a5

Please sign in to comment.