Skip to content

Commit

Permalink
add fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vashjs committed Oct 27, 2024
1 parent 01bef57 commit ce5326f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export const BulkEditPreviewModalList = ({
} = usePagination(PAGINATION_CONFIG);

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

const visibleColumnKeys = getVisibleColumnsKeys(visibleColumns);
const enabled = isPreviewEnabled && bulkDetails?.status === JOB_STATUSES.REVIEW_CHANGES;
Expand Down
1 change: 1 addition & 0 deletions src/hooks/api/useRecordsPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const useRecordsPreview = ({
{
queryKey: [key, namespaceKey, id, step, limit, offset],
cacheTime: 0,
staleTime: 0,
keepPreviousData: true,
queryFn: () => {
return ky.get(`bulk-operations/${id}/preview`, { searchParams: { limit, offset, step } }).json();
Expand Down
19 changes: 11 additions & 8 deletions src/hooks/useConfirmChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,26 @@ 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) => {
// as backend reset a status to 'DATA_MODIFICATION' only after the job started
// we need to set it manually to show the preview modal without a delay
queryClient.setQueriesData(
BULK_OPERATION_DETAILS_KEY,
(preBulkOperation) => ({ ...preBulkOperation, status: JOB_STATUSES.DATA_MODIFICATION }),
);
resetStatusToDataModification();

queryClient.removeQueries(PREVIEW_MODAL_KEY);

setIsPreviewModalOpened(true);
setIsPreviewLoading(true);
Expand All @@ -63,8 +68,6 @@ export const useConfirmChanges = ({
}))
.then((response) => {
showErrorMessage(response);

queryClient.invalidateQueries(PREVIEW_MODAL_KEY);
})
.catch((error) => {
showErrorMessage(error);
Expand Down

0 comments on commit ce5326f

Please sign in to comment.