This commit is contained in:
Samandar Turg'unboev
2025-05-29 09:51:29 +05:00
parent 1c57e2a9ee
commit c8d259d1ba
6 changed files with 53 additions and 22 deletions

View File

@@ -35,4 +35,7 @@ export const party_requests = {
async downloadPartyItemsExcel(params: { partyId: number | string }) {
return request.get<Blob>('/parties/items/download', { params, responseType: 'blob' });
},
async downloadPartyItemsAllExcel(params: { partyId: number | string }) {
return request.get<Blob>('/parties/download/box-order', { params, responseType: 'blob' });
},
};

View File

@@ -40,6 +40,7 @@ const DashboardPartiesPage = (props: Props) => {
const [deleteIds, setDeleteIds] = useState<number[]>([]);
const [downloadIds, setDownloadIds] = useState<number[]>([]);
const [downloadItemIds, setDownloadItemIds] = useState<number[]>([]);
const [downloadItemIdsExel, setDownloadItemIdsExel] = useState<number[]>([]);
const [changeStatusIds, setChangeStatusIds] = useState<number[]>([]);
const partyStatusOptions = useMemo(() => {
@@ -145,6 +146,21 @@ const DashboardPartiesPage = (props: Props) => {
}
};
const onDownloadPartyItemsExel = async (id: number, name: string) => {
if (downloadItemIds.includes(id)) return;
try {
setDownloadItemIdsExel(p => [...p, id]);
const response = await party_requests.downloadPartyItemsAllExcel({ partyId: id });
const file = new File([response.data], `${name}.xlsx`, { type: response.data.type });
file_service.download(file);
} catch (error) {
notifyUnknownError(error);
} finally {
setDownloadItemIdsExel(prev => prev.filter(i => i !== id));
}
};
const onChangeStatus = async (id: number, newStatus: PartyStatus) => {
if (changeStatusIds.includes(id)) return;
@@ -290,29 +306,38 @@ const DashboardPartiesPage = (props: Props) => {
},
...(isAdmin
? [
{
icon: <Download sx={{ path: { color: '#3489E4' } }} />,
label: t('download_all_items'),
onClick: () => {
onDownloadPartyItems(data.id);
},
dontCloseOnClick: true,
loading: downloadItemIds.includes(data.id),
},
]
{
icon: <Download sx={{ path: { color: '#3489E4' } }} />,
label: t('download_all_items'),
onClick: () => {
onDownloadPartyItems(data.id);
},
dontCloseOnClick: true,
loading: downloadItemIds.includes(data.id),
},
]
: []),
{
icon: <Download sx={{ path: { color: '#3489E4' } }} />,
label: t('download_all_items_exel'),
onClick: () => {
onDownloadPartyItemsExel(data.id, data.name);
},
dontCloseOnClick: true,
loading: downloadItemIdsExel.includes(data.id),
},
...(Boolean(data.partyStatus === 'ON_THE_WAY' || data.partyStatus === 'ARRIVED')
? [
{
icon: <Download sx={{ path: { color: '#3489E4' } }} />,
label: t('download_excel'),
onClick: () => {
onDownloadExcel(data.id);
},
loading: downloadIds.includes(data.id),
dontCloseOnClick: true,
},
]
{
icon: <Download sx={{ path: { color: '#3489E4' } }} />,
label: t('download_excel'),
onClick: () => {
onDownloadExcel(data.id);
},
loading: downloadIds.includes(data.id),
dontCloseOnClick: true,
},
]
: []),
]}
/>