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

fixes multi order status on bookmark page #1407

Merged
merged 6 commits into from
Mar 20, 2024
Merged
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
29 changes: 19 additions & 10 deletions src/components/hooks/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,18 @@ export function useSubmitOrders({ orders }) {
entry?.pids?.[0]
);

//default key to use if bookmarkKey is not provided
const orderKey = `${
entry?.materialData?.workId
}${entry?.materialData?.ownerWork?.materialTypes
?.map?.((type) => type?.materialTypeSpecific?.code)
?.join(" / ")}`;

const materialToOrder = {
key: `${
entry?.materialData?.workId
}${entry?.materialData?.ownerWork?.materialTypes
?.map?.((type) => type?.materialTypeSpecific?.code)
?.join(" / ")}`,
key: entry?.order?.bookmarkKey || orderKey,
pids: entry?.pids,
};

if (periodicaForm) {
materialToOrder.periodicaForm = {
pid: entry?.pids?.[0],
Expand All @@ -616,12 +620,15 @@ export function useSubmitOrders({ orders }) {
return materialToOrder;
});
const materialsToOrderInfo = validation?.validatedOrders?.map((entry) => {
//default key to use if bookmarkKey is not provided
const orderKey = `${
entry?.materialData?.workId
}${entry?.materialData?.ownerWork?.materialTypes
?.map?.((type) => type?.materialTypeSpecific?.code)
?.join(" / ")}`;

return {
key: `${
entry?.materialData?.workId
}${entry?.materialData?.ownerWork?.materialTypes
?.map?.((type) => type?.materialTypeSpecific?.code)
?.join(" / ")}`,
key: entry?.order?.bookmarkKey || orderKey,
...entry,
};
});
Expand Down Expand Up @@ -653,6 +660,7 @@ export function useSubmitOrders({ orders }) {
successfullyCreatedPids,
error: res?.error,
};

setReceipt(receipt);
setTimeout(() => {
receipt?.successfullyCreatedPids?.forEach((entry) => {
Expand Down Expand Up @@ -699,6 +707,7 @@ export function useOrderFlow() {
setSessionStorageItem("storedOrders", JSON.stringify(orders));
setInitialOrders(orders);
setOrders(orders);

if (isAuthenticated || branchId) {
modal.push("ematerialfilter", {});
} else {
Expand Down
11 changes: 11 additions & 0 deletions src/components/profile/bookmarks/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ const BookmarkPage = () => {
isLoading: bookmarsDataLoading,
} = useBookmarks();

const receipt =
modal?.stack?.find((item) => item.id === "multireceipt")?.context || {};
const { successMaterials, failedMaterials } = receipt;

const { data: populatedBookmarks, isLoading: isPopulateLoading } =
usePopulateBookmarks(bookmarksData);
const [activeStickyButton, setActiveStickyButton] = useState(null);
Expand All @@ -131,6 +135,12 @@ const BookmarkPage = () => {
setFailureAtCreationIds((prev) => [...prev, ...failedAtCreation]);
}

useEffect(() => {
if (successMaterials && failedMaterials) {
handleOrderFinished(successMaterials, failedMaterials);
}
}, [successMaterials, failedMaterials]);

useEffect(() => {
setSortBy(sortByValue);
}, [sortByValue]);
Expand Down Expand Up @@ -180,6 +190,7 @@ const BookmarkPage = () => {
const onOrderManyClick = () => {
const orders = checkboxList?.map((order) => ({
pids: order?.manifestations?.map((manifestation) => manifestation?.pid),
bookmarkKey: order?.key,
}));
if (orders?.length > 0) {
start({ orders });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const BookmarkColumn = ({
showFailedAtCreation,
showSuccessfullyOrdered,
handleOrderFinished,
bookmarkKey,
}) => {
// If there is a pid we have singleManifestation
const singleManifestation = !!pid;
Expand Down Expand Up @@ -68,6 +69,7 @@ const BookmarkColumn = ({
size="small"
shortText
handleOrderFinished={handleOrderFinished}
bookmarkKey={bookmarkKey}
/>
)}
{showFailedAtCreation && (
Expand Down Expand Up @@ -111,6 +113,7 @@ const MaterialRowBookmark = ({
showSuccessfullyOrdered = false,
showFailedAtCreation = false,
handleOrderFinished,
bookmarkKey,
}) => {
const onCheckboxClick = (e) => {
if (
Expand Down Expand Up @@ -230,6 +233,7 @@ const MaterialRowBookmark = ({
<div>
<BookmarkColumn
workId={workId}
bookmarkKey={bookmarkKey}
pid={pid}
flatMaterialTypes={flatMaterialTypes}
onBookmarkDelete={onBookmarkDelete}
Expand Down
5 changes: 4 additions & 1 deletion src/components/work/reservationbutton/ReservationButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function ReservationButtonWrapper({
overrideButtonText = null,
className,
handleOrderFinished = undefined,
bookmarkKey,
}) {
const { data: workData, isLoadingWorkData } = useData(
workId && overviewWork({ workId })
Expand Down Expand Up @@ -123,6 +124,7 @@ function ReservationButtonWrapper({
materialTypes,
hasPhysicalCopy,
hasDigitalCopy,
bookmarkKey,
}}
/>
);
Expand Down Expand Up @@ -156,6 +158,7 @@ export const ReservationButton = ({
workTypes,
materialTypes,
hasPhysicalCopy,
bookmarkKey,
}) => {
const { start } = useOrderFlow();
const noSelectedManifestations = Boolean(isEmpty(access));
Expand Down Expand Up @@ -183,7 +186,7 @@ export const ReservationButton = ({
skeleton: isEmpty(access),
dataCy: `button-order-overview-enabled`,
onClick: () => {
start({ orders: [{ pids }] });
start({ orders: [{ pids, bookmarkKey: bookmarkKey }] });
},
};

Expand Down