Skip to content

Commit

Permalink
[TM-1457] add request to export (#681)
Browse files Browse the repository at this point in the history
* [TM-1457] add request to export

* [TM-1457] handle export function to delayed job
  • Loading branch information
LimberHope authored Nov 21, 2024
1 parent b89f7f5 commit 8ee04d6
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/admin/modules/organisations/components/OrganisationsList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Divider, Stack, Tab, Tabs } from "@mui/material";
import { useT } from "@transifex/react";
import { Fragment, useCallback, useState } from "react";
import {
Datagrid,
Expand All @@ -10,11 +11,9 @@ import {
SelectInput,
ShowButton,
TextField,
useDataProvider,
useListContext
} from "react-admin";

import { OrganisationDataProvider } from "@/admin/apiProvider/dataProviders/organisationDataProvider";
import ListActions from "@/admin/components/Actions/ListActions";
import ExportProcessingAlert from "@/admin/components/Alerts/ExportProcessingAlert";
import FundingProgrammesArrayField from "@/admin/components/Fields/FundingProgrammesArrayField";
Expand All @@ -23,9 +22,11 @@ import { MENU_PLACEMENT_BOTTOM_LEFT } from "@/components/elements/Menu/MenuVaria
import Text from "@/components/elements/Text/Text";
import Icon, { IconNames } from "@/components/extensive/Icon/Icon";
import { getOrganisationTypeOptions } from "@/constants/options/organisations";
import { ToastType, useToastContext } from "@/context/toast.provider";
import { fetchGetV2AdminOrganisationsExport } from "@/generated/apiComponents";
import { downloadFileBlob } from "@/utils/network";
import { optionToChoices } from "@/utils/options";

import modules from "../..";
import { useGetOrganisationsTotals } from "../hooks/useGetOrganisationsTotal";

const tabs = [
Expand Down Expand Up @@ -108,14 +109,35 @@ const ApplicationDataGrid = () => {
};

export const OrganisationsList = () => {
const t = useT();
const [exporting, setExporting] = useState<boolean>(false);
const { openToast } = useToastContext();
const onSuccess = (response: any) => {
openToast(t("successfully exported"));
downloadFileBlob(response, `organisations.csv`);
};

const organisationDataProvider = useDataProvider<OrganisationDataProvider>();
const onError = () => {
openToast(t("Something went wrong!"), ToastType.ERROR);
};

const handleExport = () => {
setExporting(true);

organisationDataProvider.export(modules.organisation.ResourceName).finally(() => setExporting(false));
fetchGetV2AdminOrganisationsExport({})
.then((response: any) => {
if (response.message) {
return fetchGetV2AdminOrganisationsExport({ queryParams: { force: true } });
} else {
return response;
}
})
.then((response: any) => {
onSuccess(response);
})
.catch(onError)
.finally(() => {
setExporting(false);
});
};

return (
Expand Down

0 comments on commit 8ee04d6

Please sign in to comment.