|
|
|
|
@ -3,29 +3,42 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
|
|
import { exportPoints } from "../../../api";
|
|
|
|
|
import { handleExportSuccess } from "../ExportButton";
|
|
|
|
|
import { usePendingPointsFilters } from "../../../stores/usePendingPointsFilters";
|
|
|
|
|
import { STATUSES } from "../../../config.js";
|
|
|
|
|
|
|
|
|
|
export const useExportPendingData = (enabled, onSettled) => {
|
|
|
|
|
const { filters } = usePendingPointsFilters();
|
|
|
|
|
const { prediction, status, categories, region } = filters;
|
|
|
|
|
const { prediction, categories, region } = filters;
|
|
|
|
|
const { selection } = usePointSelection();
|
|
|
|
|
const includedArr = [...selection.included];
|
|
|
|
|
const excludedArr = [...selection.excluded];
|
|
|
|
|
|
|
|
|
|
return useQuery(
|
|
|
|
|
["export-initial", filters, selection],
|
|
|
|
|
async () => {
|
|
|
|
|
const params = new URLSearchParams({
|
|
|
|
|
"prediction_current[]": prediction,
|
|
|
|
|
"status[]": status,
|
|
|
|
|
"categories[]": categories,
|
|
|
|
|
"included[]": [...selection.included],
|
|
|
|
|
"excluded[]": [...selection.excluded],
|
|
|
|
|
"status[]": [STATUSES.pending],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (categories.length) {
|
|
|
|
|
params.append("categories[]", categories);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (includedArr.length) {
|
|
|
|
|
params.append("included[]", includedArr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (excludedArr.length) {
|
|
|
|
|
params.append("excluded[]", excludedArr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await exportPoints(params, region);
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
enabled,
|
|
|
|
|
onSuccess: handleExportSuccess,
|
|
|
|
|
onSettled,
|
|
|
|
|
retry: false,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|