Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bibdk2021 2388 multi error #1378

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ const MultiOrder = ({ context }) => {
const onSubmit = async (selectedPickupBranch, pincode) => {
setIsCreatingOrders(true);
pickupBranch.current = selectedPickupBranch;

await createOrders({
materials: sortedMaterials,
pickupBranch: selectedPickupBranch,
Expand Down
1 change: 0 additions & 1 deletion src/components/_modal/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export function handleSubmitOrder(
if (pincode) {
userParameters = { ...userParameters, pincode };
}

orderMutation.post(
orderMutations.submitOrder({
pids,
Expand Down
27 changes: 16 additions & 11 deletions src/components/hooks/useBookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ const useBookmarksCore = ({ hasCulrUniqueId, isMock = false } = {}) => {
}
};

const getABookMark = ({ materialId, materialType, title, workId }) => {
return {
materialId: materialId,
materialType: materialType,
title: title,
workId: workId,
};
};

/**
* Set a value in bookmark list
*/
Expand All @@ -121,14 +130,7 @@ const useBookmarksCore = ({ hasCulrUniqueId, isMock = false } = {}) => {
// Doesn't exist - Add
await bookmarkMutation.post(
bookmarkMutations.addBookmarks({
bookmarks: [
{
materialId: value.materialId,
materialType: value.materialType,
title: value.title,
workId: value.workId,
},
],
bookmarks: [getABookMark(value)],
})
);
} else {
Expand Down Expand Up @@ -272,6 +274,7 @@ const useBookmarksCore = ({ hasCulrUniqueId, isMock = false } = {}) => {
return {
setBookmark,
deleteBookmarks,
getABookMark,
clearLocalBookmarks,
bookmarks: hasCulrUniqueId ? globalBookmarks : localBookmarks,
paginatedBookmarks: hasCulrUniqueId
Expand Down Expand Up @@ -368,14 +371,16 @@ export default useBookmarks;
*/
export const usePopulateBookmarks = (bookmarks) => {
//all works both for specific edition and entire work
const workIds = bookmarks?.map((work) => work.workId);
const workIds = bookmarks
?.map((work) => work.workId)
.filter((id) => id !== undefined);

const { data: workByIdsData, isLoading: idsToWorksLoading } = useData(
workIds &&
!isEmpty(workIds) &&
workFragments.idsToWorks({
ids: workIds,
})
);

const workByIdsDataRemovedDuplicates = workByIdsData?.works?.filter(
(value, idx) => workByIdsData?.works?.indexOf(value) === idx
);
Expand Down
8 changes: 6 additions & 2 deletions src/components/profile/bookmarks/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,12 @@ const BookmarkPage = () => {
*/
function handleOrderFinished(successfullyCreated, failedAtCreation) {
setCheckboxList([]);
setSuccessfullyCreatedIds((prev) => [...prev, ...successfullyCreated]);
setFailureAtCreationIds((prev) => [...prev, ...failedAtCreation]);
setSuccessfullyCreatedIds((prev) => [
...new Set([...prev, ...successfullyCreated]),
]);
setFailureAtCreationIds((prev) => [
...new Set([...failedAtCreation, ...prev]),
]);
}

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const BookmarkColumn = ({
return (
<div className={sharedStyles.dynamicColumnHorizontal}>
<div className={sharedStyles.bookmarkOrderButtonContainer}>
{showSuccessfullyOrdered ? (
{!showFailedAtCreation && showSuccessfullyOrdered ? (
<TextWithCheckMark
text={Translate({
context: "bookmark-order",
Expand All @@ -68,6 +68,7 @@ const BookmarkColumn = ({
size="small"
shortText
handleOrderFinished={handleOrderFinished}
useMultiOrder={true}
/>
)}
{showFailedAtCreation && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { createEditionText } from "../../details/utils/details.utils";
import cx from "classnames";
import isEmpty from "lodash/isEmpty";

function getBookmarkKey(material) {
export function getBookmarkKey(material) {
return (
material?.materialId + formatMaterialTypesToCode(material?.materialTypes)
);
Expand Down
43 changes: 43 additions & 0 deletions src/components/work/reservationbutton/ReservationButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ import uniq from "lodash/uniq";
import { openLoginModal } from "@/components/_modal/pages/login/utils";
import useAuthentication from "@/components/hooks/user/useAuthentication";
import useLoanerInfo from "@/components/hooks/user/useLoanerInfo";
import useBookmarks, {
usePopulateBookmarks,
} from "@/components/hooks/useBookmarks";
import { getBookmarkKey } from "@/components/work/overview/bookmarkDropdown/BookmarkDropdown";
import {
formatMaterialTypesToCode,
manifestationMaterialTypeFactory,
} from "@/lib/manifestationFactoryUtils";

function TextAboveButton({ access, isAuthenticated }) {
return (
Expand Down Expand Up @@ -63,6 +71,7 @@ function ReservationButtonWrapper({
overrideButtonText = null,
className,
handleOrderFinished = undefined,
useMultiOrder = false,
}) {
const { isAuthenticated } = useAuthentication();
const { loanerInfo, isLoading } = useLoanerInfo();
Expand All @@ -87,6 +96,37 @@ function ReservationButtonWrapper({
allEnrichedAccesses?.map((singleAccess) => singleAccess?.pid)
);

/** FAKE A MULTIORDER **/
// when ordering (single order) you may now pass a prop (useMultiorder) to reservationbutton
// if prop is true we fake a bookmark here and use the multiorder modal.

const { uniqueMaterialTypes } = useMemo(() => {
return manifestationMaterialTypeFactory(manifestations);
}, [manifestations]);

const { getABookMark } = useBookmarks();
const fakeBookmark = getABookMark({
materialId: workId,
materialType: formatMaterialTypesToCode(uniqueMaterialTypes[0]),
workId: workId,
title: "",
});

fakeBookmark.key = getBookmarkKey({
materialId: workId,
materialTypes: uniqueMaterialTypes[0],
});
// populate fake bookmark
const bookmarks = usePopulateBookmarks([fakeBookmark]);
const multiordercontext = () => {
return {
sortType: "createdAt",
bookmarksToOrder: bookmarks?.data,
handleOrderFinished: handleOrderFinished,
};
};
/** END FAKE MULTIORDER **/

if (
!workId ||
!selectedPids ||
Expand Down Expand Up @@ -123,6 +163,7 @@ function ReservationButtonWrapper({
overrideButtonText={overrideButtonText}
modal={modal}
handleOrderFinished={handleOrderFinished}
multiorderContext={useMultiOrder ? multiordercontext() : null}
/>
);
}
Expand Down Expand Up @@ -157,6 +198,7 @@ export const ReservationButton = ({
overrideButtonText = null,
modal,
handleOrderFinished = undefined,
multiorderContext = undefined,
}) => {
const physicalCopy = checkPhysicalCopy([access?.[0]])?.[0]; //TODO why do we check all accesses if only one is used in the end?
const digitalCopy = checkDigitalCopy([access?.[0]])?.[0]; //TODO why do we check all accesses if only one is used in the end?
Expand Down Expand Up @@ -219,6 +261,7 @@ export const ReservationButton = ({
singleManifestation: singleManifestation,
storeLoanerInfo: true, // user is already logged in, we want to keep that
handleOrderFinished: handleOrderFinished,
multiOrderContext: multiorderContext,
})
: handleOpenLoginAndAddOrderModalToStore();
},
Expand Down
23 changes: 13 additions & 10 deletions src/components/work/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ export function openOrderModal({
singleManifestation,
storeLoanerInfo = false,
handleOrderFinished = undefined,
multiOrderContext = null,
}) {
modal.push("order", {
title: Translate({ context: "modal", label: "title-order" }),
pids: pids,
selectedAccesses: selectedAccesses,
workId: workId,
...(singleManifestation && { orderType: "singleManifestation" }),
singleManifestation: singleManifestation,
storeLoanerInfo: storeLoanerInfo,
handleOrderFinished: handleOrderFinished,
});
multiOrderContext
? modal.push("multiorder", multiOrderContext)
: modal.push("order", {
title: Translate({ context: "modal", label: "title-order" }),
pids: pids,
selectedAccesses: selectedAccesses,
workId: workId,
...(singleManifestation && { orderType: "singleManifestation" }),
singleManifestation: singleManifestation,
storeLoanerInfo: storeLoanerInfo,
handleOrderFinished: handleOrderFinished,
});
}

export function openReferencesModal(modal, pids, workId, work, manifestation) {
Expand Down
1 change: 0 additions & 1 deletion src/lib/manifestationFactoryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export function formatMaterialTypesToCode(materialTypeArray) {
if (!Array.isArray(materialTypeArray)) {
return materialTypeArray;
}

return (
materialTypeArray
?.map((mat) =>
Expand Down