Skip to content

Commit

Permalink
UIIN-2628: Optimistic locking message not working for instances in no…
Browse files Browse the repository at this point in the history
…n-consortial tenant (#2316)
  • Loading branch information
mariia-aloshyna authored Oct 23, 2023
1 parent f0c4b11 commit 33589f7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Enable/disable consortial holdings/item actions based on User permissions. Refs UIIN-2452.
* User receives an error when searching for an item in the Inventory app. Fixes UIIN-2634.
* Create new instance success toast no longer shows the instance HRID. Fixes UIIN-2635.
* Optimistic locking message not working for instances in non-consortial tenant. Fixes UIIN-2628.

## [10.0.0](https://github.com/folio-org/ui-inventory/tree/v10.0.0) (2023-10-13)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v9.4.12...v10.0.0)
Expand Down
10 changes: 4 additions & 6 deletions src/Instance/InstanceEdit/InstanceEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,20 @@ const InstanceEdit = ({
}, [callout, goBack]);

const onError = async error => {
const parsedError = await parseHttpError(error);
const response = await error.response;
const parsedError = await parseHttpError(response);
setHttpError(parsedError);
};

const isMemberTenant = checkIfUserInMemberTenant(stripes);
const tenantId = (isMemberTenant && instance?.shared) ? stripes.user.user.consortium.centralTenantId : stripes.okapi.tenant;

const { mutateInstance } = useInstanceMutation({
options: { onSuccess, onError },
tenantId,
});
const { mutateInstance } = useInstanceMutation({ tenantId });

const onSubmit = useCallback((initialInstance) => {
const updatedInstance = marshalInstance(initialInstance, identifierTypesByName);

return mutateInstance(updatedInstance);
return mutateInstance(updatedInstance, { onSuccess, onError });
}, [mutateInstance]);

if (isInstanceLoading) return <LoadingView />;
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useInstanceMutation/useInstanceMutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import { useTenantKy } from '../../common';
const useInstanceMutation = ({ tenantId, options = {} }) => {
const ky = useTenantKy({ tenantId });

const { mutateAsync } = useMutation({
const { mutate } = useMutation({
mutationFn: (instance) => {
const kyMethod = instance.id ? 'put' : 'post';
const kyPath = instance.id ? `inventory/instances/${instance.id}` : 'inventory/instances';

return ky[kyMethod](kyPath, { json: instance });
return ky[kyMethod](kyPath, { json: instance }).json();
},
...options,
});

return {
mutateInstance: mutateAsync,
mutateInstance: mutate,
};
};

Expand Down

0 comments on commit 33589f7

Please sign in to comment.