diff --git a/src/Holding/CreateHolding/CreateHolding.js b/src/Holding/CreateHolding/CreateHolding.js
index 1cfcceef9..d778690ee 100644
--- a/src/Holding/CreateHolding/CreateHolding.js
+++ b/src/Holding/CreateHolding/CreateHolding.js
@@ -30,7 +30,7 @@ const CreateHolding = ({
const callout = useCallout();
const { instance, isLoading: isInstanceLoading } = useInstance(instanceId);
const sourceId = referenceData.holdingsSourcesByName?.FOLIO?.id;
- const { location: { state: { tenantFrom } } } = history;
+ const tenantFrom = location?.state?.tenantFrom || stripes.okapi.tenant;
const goBack = useCallback(() => {
history.push({
@@ -39,13 +39,15 @@ const CreateHolding = ({
});
}, [location.search, instanceId]);
- const onCancel = useCallback(() => {
- switchAffiliation(stripes, tenantFrom, goBack);
+ const onCancel = useCallback(async () => {
+ await switchAffiliation(stripes, tenantFrom, goBack);
}, [stripes, tenantFrom, goBack]);
const onSubmit = useCallback((newHolding) => {
return mutator.holding.POST(newHolding)
- .then((holdingsRecord) => {
+ .then(async (holdingsRecord) => {
+ await onCancel();
+
callout.sendCallout({
type: 'success',
message: ,
});
- onCancel();
});
}, [onCancel, callout]);
diff --git a/src/Holding/DuplicateHolding/DuplicateHolding.js b/src/Holding/DuplicateHolding/DuplicateHolding.js
index 96fb49f32..eac3e2078 100644
--- a/src/Holding/DuplicateHolding/DuplicateHolding.js
+++ b/src/Holding/DuplicateHolding/DuplicateHolding.js
@@ -16,13 +16,20 @@ import {
} from '../../hooks';
import HoldingsForm from '../../edit/holdings/HoldingsForm';
import withLocation from '../../withLocation';
+import { switchAffiliation } from '../../utils';
const DuplicateHolding = ({
goTo,
history,
instanceId,
holdingId,
- location: { search, state: locationState },
+ location: {
+ search,
+ state: {
+ backPathname: locationState,
+ tenantFrom,
+ } = {},
+ },
referenceTables,
}) => {
const callout = useCallout();
@@ -37,10 +44,18 @@ const DuplicateHolding = ({
sourceId,
}), [holding, sourceId]);
+ const goToDuplicatedHolding = useCallback((id) => {
+ history.push({
+ pathname: `/inventory/view/${instanceId}/${id}`,
+ search,
+ state: { tenantTo: stripes.okapi.tenant },
+ });
+ }, [search, instanceId]);
+
const onSuccess = useCallback(async (response) => {
const { id, hrid } = await response.json();
- goTo(`/inventory/view/${instanceId}/${id}`);
+ await switchAffiliation(stripes, tenantFrom, () => goToDuplicatedHolding(id));
return callout.sendCallout({
type: 'success',
@@ -53,13 +68,17 @@ const DuplicateHolding = ({
const { mutateHolding } = useHoldingMutation({ onSuccess });
- const onCancel = useCallback(() => {
+ const goBack = useCallback(() => {
history.push({
pathname: locationState?.backPathname ?? `/inventory/view/${instanceId}`,
search,
});
}, [search, instanceId]);
+ const onCancel = useCallback(async () => {
+ await switchAffiliation(stripes, tenantFrom, goBack);
+ }, [stripes, tenantFrom, goBack]);
+
const onSubmit = useCallback(holdingValues => (
mutateHolding(holdingValues)
), [mutateHolding]);
diff --git a/src/Holding/EditHolding/EditHolding.js b/src/Holding/EditHolding/EditHolding.js
index bb9e3432e..4a855213f 100644
--- a/src/Holding/EditHolding/EditHolding.js
+++ b/src/Holding/EditHolding/EditHolding.js
@@ -17,7 +17,10 @@ import {
} from '../../hooks';
import HoldingsForm from '../../edit/holdings/HoldingsForm';
import withLocation from '../../withLocation';
-import { parseHttpError } from '../../utils';
+import {
+ parseHttpError,
+ switchAffiliation,
+} from '../../utils';
const EditHolding = ({
goTo,
@@ -28,7 +31,13 @@ const EditHolding = ({
referenceTables,
}) => {
const callout = useCallout();
- const { search, state: locationState } = location;
+ const {
+ search,
+ state: {
+ backPathname: locationState,
+ tenantFrom,
+ } = {},
+ } = location;
const stripes = useStripes();
const [httpError, setHttpError] = useState();
const { instance, isLoading: isInstanceLoading } = useInstanceQuery(instanceId);
@@ -42,17 +51,21 @@ const EditHolding = ({
referenceTables?.holdingsSources?.find(source => source.id === holding?.sourceId)?.name === 'MARC'
), [holding]);
- const onCancel = useCallback(() => {
+ const goBack = useCallback(() => {
history.push({
pathname: locationState?.backPathname ?? `/inventory/view/${instanceId}`,
search,
});
}, [search, instanceId]);
- const onSuccess = useCallback(() => {
- onCancel();
+ const onCancel = useCallback(async () => {
+ await switchAffiliation(stripes, tenantFrom, goBack);
+ }, [stripes, tenantFrom, goBack]);
+
+ const onSuccess = useCallback(async () => {
+ await onCancel();
- return callout.sendCallout({
+ callout.sendCallout({
type: 'success',
message: switchAffiliation(stripes, tenantId, onViewHolding)}
+ onClick={async () => {
+ await switchAffiliation(stripes, tenantId, onViewHolding);
+ }}
>
@@ -58,7 +60,9 @@ const HoldingButtonsGroup = ({