generated from pieceowater-dev/openAPI-frontend-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from pieceowater-dev/dev
Dev
- Loading branch information
Showing
21 changed files
with
347 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useNotify } from 'app/providers/app' | ||
import { useEffect } from 'react' | ||
import { getAxiosInstance } from 'shared/api/api-query/api-query' | ||
import { useAppSelector } from 'shared/redux/store' | ||
|
||
export const useBarChart = () => { | ||
const { openNotification } = useNotify() | ||
const dateType = useAppSelector((state) => state.dashboard.typeDate) | ||
const { start, end } = useAppSelector((state) => state.dashboard.selectedDates) | ||
const posts = useAppSelector((state) => state.dashboard.posts) | ||
|
||
const fetchData = async () => { | ||
try { | ||
const axiosInstance = await getAxiosInstance() | ||
const res = await axiosInstance.get('/payments/pie-posts', { | ||
params: { dateType: dateType, start: start, end: end, posts: posts }, | ||
}) | ||
console.log(res.data) | ||
} catch (error) { | ||
openNotification('Произошла ошибка при загрузке данных о платежах') | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
fetchData() | ||
}, [dateType, start, end, posts]) | ||
|
||
const bar = { | ||
labels: ['Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье'], | ||
datasets: [ | ||
{ | ||
label: 'Общая сумма', | ||
data: [12, 19, 3, 5, 2, 3, 7], | ||
backgroundColor: 'rgb(110, 189, 116)', | ||
}, | ||
], | ||
} | ||
|
||
return { bar } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { useBarChart } from 'entities/dashboard/bar-chart/bar-chart' | ||
|
||
export { useBarChart } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { usePieChart } from 'entities/dashboard/pie-chart/pie-chart' | ||
|
||
export { usePieChart } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useNotify } from 'app/providers/app' | ||
import { useEffect } from 'react' | ||
import { getAxiosInstance } from 'shared/api/api-query/api-query' | ||
import { useAppSelector } from 'shared/redux/store' | ||
|
||
export const usePieChart = () => { | ||
const { openNotification } = useNotify() | ||
const dateType = useAppSelector((state) => state.dashboard.typeDate) | ||
const { start, end } = useAppSelector((state) => state.dashboard.selectedDates) | ||
const posts = useAppSelector((state) => state.dashboard.posts) | ||
|
||
const fetchData = async () => { | ||
try { | ||
const axiosInstance = await getAxiosInstance() | ||
const res = await axiosInstance.get('/payments/pie-type', { | ||
params: { dateType: dateType, start: start, end: end, posts: posts }, | ||
}) | ||
console.log(res.data) | ||
} catch (error) { | ||
openNotification('Произошла ошибка при загрузке данных о платежах') | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
fetchData() | ||
}, [dateType, start, end, posts]) | ||
|
||
const pie = { | ||
labels: ['Наличные', 'Каспи'], | ||
datasets: [ | ||
{ | ||
data: [60, 40], | ||
backgroundColor: ['rgb(110, 189, 116)', 'rgba(218,18,18,0.8)'], | ||
}, | ||
], | ||
} | ||
|
||
return { pie } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/pages/dashboard/ui/dashboard-charts/dashboard-charts.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { | ||
ArcElement, | ||
BarElement, | ||
CategoryScale, | ||
Chart as ChartJS, | ||
Legend, | ||
LinearScale, | ||
Tooltip, | ||
} from 'chart.js' | ||
import { useBarChart } from 'entities/dashboard/bar-chart' | ||
import { usePieChart } from 'entities/dashboard/pie-chart' | ||
import { FC } from 'react' | ||
import { Bar, Pie } from 'react-chartjs-2' | ||
import { useMediaQuery } from 'react-responsive' | ||
import { useAppSelector } from 'shared/redux/store' | ||
import { PostCard } from 'shared/ui/post-card' | ||
|
||
ChartJS.register(ArcElement, Tooltip, Legend, CategoryScale, LinearScale, BarElement) | ||
|
||
export const DashboardCharts: FC = () => { | ||
const isMobile = useMediaQuery({ query: '(max-width: 768px )' }) | ||
const { pie } = usePieChart() | ||
const { bar } = useBarChart() | ||
const posts: { label: string; value: number }[] = useAppSelector( | ||
(state) => state.dashboard.postsData, | ||
) | ||
|
||
return ( | ||
<> | ||
<div | ||
style={{ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
marginBottom: 20, | ||
flexDirection: isMobile ? 'column' : 'row', | ||
gap: isMobile ? 20 : 0, | ||
}} | ||
> | ||
<div style={{ width: isMobile ? '100%' : '50%', height: isMobile ? 'fit-content' : 300 }}> | ||
<Pie data={pie} /> | ||
</div> | ||
|
||
<div style={{ width: isMobile ? '100%' : '50%', height: isMobile ? 'fit-content' : 300 }}> | ||
<Bar data={bar} /> | ||
</div> | ||
</div> | ||
|
||
<div | ||
style={{ | ||
height: 100, | ||
background: '#fafafa', | ||
padding: '1rem', | ||
marginBottom: 20, | ||
borderRadius: 8, | ||
overflow: 'auto', | ||
display: 'flex', | ||
gap: '20px', | ||
alignItems: 'center', | ||
}} | ||
> | ||
{posts.map((item) => ( | ||
<PostCard key={item.value} value={item.value} name={item.label} /> | ||
))} | ||
</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { DashboardCharts } from 'pages/dashboard/ui/dashboard-charts/dashboard-charts' | ||
|
||
export { DashboardCharts } |
68 changes: 68 additions & 0 deletions
68
src/pages/dashboard/ui/dashboard-filters/dashboard-filters.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { DatePicker, Select } from 'antd' | ||
import { IDashboardProps } from 'pages/dashboard/ui/dashboard-filters/model/interface' | ||
import React, { FC } from 'react' | ||
import { useMediaQuery } from 'react-responsive' | ||
import { dateFilter } from 'shared/lib/constants' | ||
import { | ||
setPaymentsPost, | ||
setPaymentsSelectedDates, | ||
setPaymentsTypeDate, | ||
} from 'shared/redux/dashboard/dashboard-slice' | ||
import { useAppDispatch, useAppSelector } from 'shared/redux/store' | ||
|
||
export const DashboardFilters: FC<IDashboardProps> = ({ refetch, options }) => { | ||
const isMobile = useMediaQuery({ query: '(max-width: 768px )' }) | ||
const dispatch = useAppDispatch() | ||
const type = useAppSelector((state) => state.dashboard.typeDate) | ||
|
||
return ( | ||
<div | ||
style={{ | ||
marginBottom: '10px', | ||
display: 'flex', | ||
gap: '10px', | ||
flexDirection: isMobile ? 'column' : 'row', | ||
}} | ||
> | ||
<div> | ||
<div style={{ marginBottom: '5px' }}>Посты</div> | ||
<Select | ||
mode={'multiple'} | ||
allowClear={true} | ||
options={options} | ||
maxTagCount={1} | ||
onChange={(value) => { | ||
dispatch(setPaymentsPost(value)) | ||
refetch() | ||
}} | ||
style={{ width: isMobile ? '100%' : 200 }} | ||
/> | ||
</div> | ||
|
||
<div> | ||
<div style={{ marginBottom: '5px' }}>Дата</div> | ||
<Select | ||
defaultValue={1} | ||
options={dateFilter} | ||
style={{ width: isMobile ? '100%' : 200, marginRight: 10 }} | ||
onChange={(value: number) => { | ||
if (value === 6) | ||
dispatch(setPaymentsSelectedDates({ start: undefined, end: undefined })) | ||
|
||
dispatch(setPaymentsTypeDate(value)) | ||
refetch() | ||
}} | ||
/> | ||
{type === 6 && ( | ||
<DatePicker.RangePicker | ||
onChange={(date) => { | ||
dispatch( | ||
setPaymentsSelectedDates({ start: date?.[0]?.toDate(), end: date?.[1]?.toDate() }), | ||
) | ||
}} | ||
/> | ||
)} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { DashboardFilters } from 'pages/dashboard/ui/dashboard-filters/dashboard-filters' | ||
|
||
export { DashboardFilters } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface IDashboardProps { | ||
refetch: () => void | ||
options: { label: string; value: number }[] | ||
} |
23 changes: 23 additions & 0 deletions
23
src/pages/dashboard/ui/dashboard-payment/dashboard-payment.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Table } from 'antd' | ||
import { IDashboardPaymentProps } from 'pages/dashboard/ui/dashboard-payment/model/interface' | ||
import React, { FC } from 'react' | ||
|
||
export const DashboardPayment: FC<IDashboardPaymentProps> = ({ total, sum, columns, rows }) => { | ||
return ( | ||
<> | ||
<Table | ||
columns={columns} | ||
dataSource={rows} | ||
bordered={true} | ||
showHeader={true} | ||
tableLayout={'fixed'} | ||
pagination={{ | ||
total: total, | ||
}} | ||
/> | ||
<div style={{ display: 'flex', alignItems: 'end', justifyContent: 'end' }}> | ||
{'Итого: ' + sum} | ||
</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { DashboardPayment } from 'pages/dashboard/ui/dashboard-payment/dashboard-payment' | ||
|
||
export { DashboardPayment } |
10 changes: 10 additions & 0 deletions
10
src/pages/dashboard/ui/dashboard-payment/model/interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ColumnsType } from 'antd/es/table' | ||
import { IColumnPayments } from 'entities/dashboard/payment-data/model/interface' | ||
import { ITablePaymentsState } from 'entities/dashboard/table-data/model/interface' | ||
|
||
export interface IDashboardPaymentProps { | ||
total: number | ||
sum: number | ||
rows: ITablePaymentsState[] | ||
columns: ColumnsType<IColumnPayments> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const dateFilter = [ | ||
{ label: 'За все время', value: 0 }, | ||
{ label: 'Сегодня', value: 1 }, | ||
{ label: 'Вчера', value: 2 }, | ||
{ label: 'Эта неделя', value: 3 }, | ||
{ label: 'Этот месяц', value: 4 }, | ||
{ label: 'Прошлая неделя', value: 5 }, | ||
{ label: 'Выбрать даты', value: 6 }, | ||
] |
Oops, something went wrong.