sbt-idp/cope2n-fe/src/pages/dashboard/index.tsx

126 lines
3.6 KiB
TypeScript
Raw Normal View History

2024-01-31 04:08:20 +00:00
import { t } from '@lingui/macro';
2024-02-05 11:20:10 +00:00
import { Button, Form, Select } from 'antd';
2024-01-31 04:08:20 +00:00
import { SbtPageHeader } from 'components/page-header';
2024-01-31 09:54:39 +00:00
import { ReportOverViewTable } from 'components/report-detail';
2024-02-01 05:54:12 +00:00
import { useOverViewReport } from 'queries/report';
import { useState } from 'react';
2024-01-31 04:08:20 +00:00
import { useNavigate } from 'react-router-dom';
2024-02-05 08:52:15 +00:00
import { DownloadOutlined } from '@ant-design/icons';
import { downloadDashboardReport } from 'request/report';
2024-01-31 04:08:20 +00:00
export interface ReportFormValues {
2024-02-05 08:52:15 +00:00
duration: string;
2024-01-31 09:54:39 +00:00
subsidiary: string;
2024-01-31 04:08:20 +00:00
}
const Dashboard = () => {
const navigate = useNavigate();
2024-02-05 08:52:15 +00:00
const [duration, setDuration] = useState<string>('30d');
2024-02-05 11:20:10 +00:00
const [subsidiary, setSubsidiary] = useState<string>('ALL');
2024-02-01 05:54:12 +00:00
const [form] = Form.useForm<ReportFormValues>();
const { isLoading, data } = useOverViewReport({
2024-02-05 11:20:10 +00:00
duration: duration,
subsidiary: subsidiary,
2024-02-01 05:54:12 +00:00
});
2024-01-31 04:08:20 +00:00
2024-02-05 08:52:15 +00:00
const handleDownloadReport = async () => {
console.log('duration >>>', duration);
console.log('subsidiary >>>', subsidiary);
const {file, filename} = await downloadDashboardReport(duration, subsidiary);
const anchorElement = document.createElement('a');
anchorElement.href = URL.createObjectURL(file);
anchorElement.download = filename;
document.body.appendChild(anchorElement);
anchorElement.click();
// Clean up
document.body.removeChild(anchorElement);
URL.revokeObjectURL(anchorElement.href);
};
2024-01-31 04:08:20 +00:00
return (
<>
<SbtPageHeader
title={t`Dashboard`}
extra={
2024-01-31 09:54:39 +00:00
<>
2024-02-05 08:52:15 +00:00
<Button type='primary' size='large' icon={<DownloadOutlined />}
onClick={() => handleDownloadReport()}
>
{t`Download`}
</Button>
<Button type='primary' size='large' onClick={() => navigate('/reports')}>
2024-01-31 09:54:39 +00:00
{t`Go to Report page`}
2024-02-05 08:52:15 +00:00
</Button>
2024-01-31 09:54:39 +00:00
</>
2024-01-31 04:08:20 +00:00
}
/>
2024-02-01 05:54:12 +00:00
<Form
2024-01-31 09:54:39 +00:00
form={form}
style={{ display: 'flex', flexDirection: 'row', gap: 10 }}
>
2024-02-05 08:52:15 +00:00
<Form.Item
label={t`Duration`}
rules={[
{
required: true,
message: 'Please select a duration',
},
]}
required
>
<Select
placeholder='Select a date range'
style={{ width: 200 }}
options={[
{ value: '30d', label: 'Last 30 days' },
2024-02-05 11:20:10 +00:00
{ value: '7d', label: 'Last 7 days' },
2024-02-05 08:52:15 +00:00
]}
value={duration}
onChange={(value) => {
setDuration(value);
}}
/>
</Form.Item>
2024-01-31 09:54:39 +00:00
<Form.Item
name='subsidiary'
label={t`Subsidiary`}
2024-02-05 09:35:57 +00:00
required
2024-01-31 09:54:39 +00:00
>
<Select
placeholder='Select a subsidiary'
style={{ width: 200 }}
options={[
2024-02-05 11:20:10 +00:00
{ value: 'ALL', label: 'ALL' },
{ value: 'SEAU', label: 'SEAU' },
{ value: 'SESP', label: 'SESP' },
{ value: 'SME', label: 'SME' },
{ value: 'SEPCO', label: 'SEPCO' },
{ value: 'TSE', label: 'TSE' },
{ value: 'SEIN', label: 'SEIN' },
2024-01-31 09:54:39 +00:00
]}
2024-02-05 11:20:10 +00:00
defaultValue='ALL'
2024-02-05 08:52:15 +00:00
value={subsidiary}
onChange={(value) => {
setSubsidiary(value);
}}
2024-01-31 09:54:39 +00:00
/>
</Form.Item>
<Form.Item>
2024-02-05 09:32:47 +00:00
<Button type='primary' style={{ height: 38 }}
>
2024-02-05 08:52:15 +00:00
View
2024-01-31 09:54:39 +00:00
</Button>
</Form.Item>
2024-02-01 05:54:12 +00:00
</Form>
<ReportOverViewTable
isLoading={isLoading}
data={data}
/>
2024-01-31 04:08:20 +00:00
</>
);
};
export default Dashboard;