Skip to content

Commit

Permalink
fix invalidation order
Browse files Browse the repository at this point in the history
  • Loading branch information
vashjs committed Oct 27, 2024
1 parent ce5326f commit 74506f4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ export const BulkEditPreviewModal = ({
dismissible
onClose={onKeepEditing}
>
<BulkEditPreviewModalList
isPreviewEnabled={!isPreviewLoading}
onPreviewError={onKeepEditing}
/>
{open && (
<BulkEditPreviewModalList
isPreviewEnabled={!isPreviewLoading}
onPreviewError={onKeepEditing}
/>
)}
</Modal>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import {
FormattedMessage,
} from 'react-intl';
import { useQueryClient } from 'react-query';

import {
MessageBanner,
Expand All @@ -13,7 +14,6 @@ import {
} from '@folio/stripes-acq-components';

import { Preloader } from '@folio/stripes-data-transfer-components';
import { useQueryClient } from 'react-query';
import { PREVIEW_COLUMN_WIDTHS } from '../../../PermissionsModal/constants/lists';
import css from './BulkEditInAppPreviewModal.css';
import { usePagination } from '../../../../hooks/usePagination';
Expand Down Expand Up @@ -50,8 +50,12 @@ export const BulkEditPreviewModalList = ({
} = usePagination(PAGINATION_CONFIG);

const [previewLoaded, setPreviewLoaded] = useState(false);
const interval = previewLoaded ? 0 : 1;
const { bulkDetails } = useBulkOperationDetails({ id: bulkOperationId, interval, cacheTime: 0, staleTime: 0 });
const interval = previewLoaded ? 0 : 1000;
const { bulkDetails } = useBulkOperationDetails({
id: bulkOperationId,
interval,
enabled: isPreviewEnabled,
});

const visibleColumnKeys = getVisibleColumnsKeys(visibleColumns);
const enabled = isPreviewEnabled && bulkDetails?.status === JOB_STATUSES.REVIEW_CHANGES;
Expand Down
18 changes: 6 additions & 12 deletions src/hooks/useConfirmChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,22 @@ export const useConfirmChanges = ({

const totalRecords = bulkDetails?.totalNumOfRecords;

const resetStatusToDataModification = () => {
queryClient.setQueriesData(
BULK_OPERATION_DETAILS_KEY,
(preBulkOperation) => ({ ...preBulkOperation, status: JOB_STATUSES.DATA_MODIFICATION }),
);
};

const openPreviewModal = () => {
setIsPreviewModalOpened(true);
};

const closePreviewModal = () => {
setIsPreviewModalOpened(false);
resetStatusToDataModification();
};

const confirmChanges = (payload) => {
resetStatusToDataModification();
setIsPreviewLoading(true);

queryClient.removeQueries(PREVIEW_MODAL_KEY);

setIsPreviewModalOpened(true);
setIsPreviewLoading(true);
queryClient.setQueriesData(
BULK_OPERATION_DETAILS_KEY,
(preBulkOperation) => ({ ...preBulkOperation, status: JOB_STATUSES.DATA_MODIFICATION }),
);

updateFn(payload)
.then(() => bulkOperationStart({
Expand All @@ -68,6 +61,7 @@ export const useConfirmChanges = ({
}))
.then((response) => {
showErrorMessage(response);
openPreviewModal();
})
.catch((error) => {
showErrorMessage(error);
Expand Down

0 comments on commit 74506f4

Please sign in to comment.