realbox edit components
This commit is contained in:
@@ -10,6 +10,7 @@ import BasePagination from '@/components/ui-kit/BasePagination';
|
||||
import { useAuthContext } from '@/context/auth-context';
|
||||
import { BoxStatus, BoxStatusList, IBox } from '@/data/box/box.model';
|
||||
import { box_requests } from '@/data/box/box.requests';
|
||||
import { IRealBox } from '@/data/real-box/real-box.model';
|
||||
import { real_box_requests } from '@/data/real-box/real-box.requests';
|
||||
import { DEFAULT_PAGE_SIZE, pageLinks } from '@/helpers/constants';
|
||||
import useDebouncedInput from '@/hooks/useDebouncedInput';
|
||||
@@ -23,6 +24,7 @@ import { getBoxStatusStyles, getStatusColor } from '@/theme/getStatusBoxStyles';
|
||||
import { Add, QrCode, AddCircleOutline, Circle, Delete, Download, Edit, FilterList, FilterListOff, Search, PlusOne } from '@mui/icons-material';
|
||||
import { Box, Button, Stack, Tooltip, Typography } from '@mui/material';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { log } from 'node:console';
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
type Props = {};
|
||||
@@ -84,6 +86,7 @@ const DashboardRealBoxesPage = (props: Props) => {
|
||||
};
|
||||
}
|
||||
}, [getBoxesQuery]);
|
||||
|
||||
const loading = getBoxesQuery.loading;
|
||||
const handleChange = (newPage: number) => {
|
||||
setTimeout(() => {
|
||||
@@ -102,7 +105,7 @@ const DashboardRealBoxesPage = (props: Props) => {
|
||||
|
||||
try {
|
||||
setDeleteIds(p => [...p, id]);
|
||||
await box_requests.delete({ packetId: id });
|
||||
await real_box_requests.delete({ boxId: id });
|
||||
getBoxesQuery.refetch();
|
||||
} catch (error) {
|
||||
notifyUnknownError(error);
|
||||
@@ -116,7 +119,7 @@ const DashboardRealBoxesPage = (props: Props) => {
|
||||
|
||||
try {
|
||||
setDownloadIds(p => [...p, id]);
|
||||
const response = await box_requests.downloadExcel({ packetId: id });
|
||||
const response = await real_box_requests.downloadExcel({ boxId: id });
|
||||
const file = new File([response.data], 'Box-excel.xlsx', { type: response.data.type });
|
||||
file_service.download(file);
|
||||
} catch (error) {
|
||||
@@ -126,6 +129,23 @@ const DashboardRealBoxesPage = (props: Props) => {
|
||||
}
|
||||
};
|
||||
|
||||
const onDownloadQrCode = async (id: number) => {
|
||||
if (downloadIds.includes(id)) return;
|
||||
|
||||
try {
|
||||
setDownloadIds(p => [...p, id]);
|
||||
const response = await real_box_requests.downloadQrCode({ boxId: id });
|
||||
console.log(response, "rres");
|
||||
const file = new File([response.data], 'qr.png', { type: response.data.type });
|
||||
file_service.download(file);
|
||||
} catch (error) {
|
||||
notifyUnknownError(error);
|
||||
console.log(error);
|
||||
} finally {
|
||||
setDownloadIds(prev => prev.filter(i => i !== id));
|
||||
}
|
||||
};
|
||||
|
||||
const onChangeStatus = async (id: number, newStatus: BoxStatus) => {
|
||||
if (changeStatusIds.includes(id)) return;
|
||||
|
||||
@@ -149,7 +169,7 @@ const DashboardRealBoxesPage = (props: Props) => {
|
||||
}, [keyword]);
|
||||
|
||||
// No, PartyName, PacketName, PartyTozaOg'irlik, CountOfItems, WeightOfItems, CargoID, PassportNameFamily - PacketStatusForInvoice
|
||||
const columns: ColumnData<IBox>[] = [
|
||||
const columns: ColumnData<IRealBox>[] = [
|
||||
{
|
||||
label: t('No'),
|
||||
width: 100,
|
||||
@@ -161,9 +181,12 @@ const DashboardRealBoxesPage = (props: Props) => {
|
||||
label: t("qr_code"),
|
||||
width: 120,
|
||||
renderCell: data => {
|
||||
return <Button>
|
||||
return <Button
|
||||
onClick={() =>
|
||||
onDownloadQrCode(data.id)
|
||||
}>
|
||||
<QrCode />
|
||||
</Button>;
|
||||
</Button >;
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -177,12 +200,12 @@ const DashboardRealBoxesPage = (props: Props) => {
|
||||
},
|
||||
},
|
||||
{
|
||||
dataKey: 'cargoId',
|
||||
dataKey: 'boxName',
|
||||
label: t('cargo_id'),
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
dataKey: 'partyName',
|
||||
dataKey: "boxName",
|
||||
label: t('party_name'),
|
||||
width: 120,
|
||||
},
|
||||
@@ -197,7 +220,7 @@ const DashboardRealBoxesPage = (props: Props) => {
|
||||
// width: 120,
|
||||
// },
|
||||
{
|
||||
dataKey: 'totalItems',
|
||||
dataKey: 'packetsCount',
|
||||
label: t('count_of_items'),
|
||||
width: 120,
|
||||
},
|
||||
@@ -360,7 +383,7 @@ const DashboardRealBoxesPage = (props: Props) => {
|
||||
</Stack>
|
||||
</Stack>
|
||||
<Box mb={6}>
|
||||
<MyTable columns={columns} data={list} loading={loading} />
|
||||
<MyTable columns={columns as any} data={list} loading={loading} />
|
||||
</Box>
|
||||
<Stack direction={'row'} justifyContent={'center'}>
|
||||
<BasePagination page={page} pageSize={pageSize} totalCount={totalElements} onChange={handleChange} />
|
||||
|
||||
Reference in New Issue
Block a user