diff --git a/src/api.js b/src/api.js index 31c0a2f..8f29e9b 100644 --- a/src/api.js +++ b/src/api.js @@ -50,6 +50,16 @@ export const getEventsCountByMonth = async () => { throw error } } +export const getOrdersCountByMonth = async () => { + try { + const currentYear = new Date().getFullYear(); + const response = await axios.get(`http://localhost:8000/api/v1/adminOrders/getOrdersCountByMonth/${currentYear}`) + return response.data + } catch (error) { + console.error('Error fetching users:', error) + throw error + } +} export const deleteEventById = async (eventId) => { diff --git a/src/views/widgets/WidgetsDropdown.js b/src/views/widgets/WidgetsDropdown.js index c9b70f2..119fd3f 100644 --- a/src/views/widgets/WidgetsDropdown.js +++ b/src/views/widgets/WidgetsDropdown.js @@ -15,7 +15,7 @@ import { getStyle } from '@coreui/utils' import { CChartBar, CChartLine } from '@coreui/react-chartjs' import CIcon from '@coreui/icons-react' import { cilArrowBottom, cilArrowTop, cilOptions } from '@coreui/icons' -import { getAllUsers, getEventsCountByMonth, getUsersCountByMonth, getallevents } from '../../api' +import { getAllUsers, getEventsCountByMonth, getOrdersCountByMonth, getUsersCountByMonth, getallevents, getallorders } from '../../api' const WidgetsDropdown = (props) => { const widgetChartRef1 = useRef(null) @@ -41,6 +41,8 @@ const WidgetsDropdown = (props) => { const [users, setUsers] = useState([]) const [getUsersMonthWise, setGetUsersMonthWise] = useState([]) + const [allOrdersCounts, setAllOrdersCounts] = useState() + // console.log("allOrdersCounts",allOrdersCounts) useEffect(() => { const fetchUsers = async () => { @@ -61,14 +63,25 @@ const WidgetsDropdown = (props) => { console.error('Error fetching getUsersCountByMonth:', error) } }; + const getallorderscount = async () => { + try { + const getallordersCount = await getallorders() + setAllOrdersCounts(getallordersCount.length) + } catch (error) { + // Handle error + console.error('Error fetching getallordersCount:', error) + } + }; fetchUsers() getUsersCounts() + getallorderscount() }, []) const [events, setEvents] = useState([]) const [getEventsMonthWise, setGetEventsMonthWise] = useState([]) + const [getOrdersMonthWise, setGetOrdersMonthWise] = useState([]) useEffect(() => { const fetchEvents = async () => { @@ -89,9 +102,19 @@ const WidgetsDropdown = (props) => { console.error('Error fetching getUsersCountByMonth:', error) } }; + const getOrdersCount = async () => { + try { + const getOrdersCount = await getOrdersCountByMonth() + setGetOrdersMonthWise(getOrdersCount) + } catch (error) { + // Handle error + console.error('Error fetching getUsersCountByMonth:', error) + } + }; fetchEvents() getEventsCounts() + getOrdersCount() }, []) // calculating increasing or decreasing rate @@ -110,8 +133,8 @@ const WidgetsDropdown = (props) => { const eventsCountForPreviousMonth = eventsForPreviousMonth.length; // Calculate the percentage increase - const percentageIncrease = ((eventsCountForCurrentMonth - eventsCountForPreviousMonth) / eventsCountForPreviousMonth) * 100; - const arrowIcon = percentageIncrease >= 0 ? cilArrowTop : cilArrowBottom; + // const percentageIncrease = ((eventsCountForCurrentMonth - eventsCountForPreviousMonth) / eventsCountForPreviousMonth) * 100; + // const arrowIcon = percentageIncrease >= 0 ? cilArrowTop : cilArrowBottom; return ( @@ -212,9 +235,9 @@ const WidgetsDropdown = (props) => { value={ <> {events.length}{" "} - + {/* ({percentageIncrease.toFixed(1)}% ) - + */} } title="Total Events" @@ -295,35 +318,36 @@ const WidgetsDropdown = (props) => { } /> - {/* + - 2.49%{' '} + {allOrdersCounts}{" "} - (84.7% ) + {/* (84.7% ) */} + (2024) } - title="Conversion Rate" - action={ - - - - - - Action - Another action - Something else here... - Disabled action - - - } + title="Total Attendees" + // action={ + // + // + // + // + // + // Action + // Another action + // Something else here... + // Disabled action + // + // + // } chart={ { label: 'My First dataset', backgroundColor: 'rgba(255,255,255,.2)', borderColor: 'rgba(255,255,255,.55)', - data: [78, 81, 80, 45, 34, 12, 40], + data: getOrdersMonthWise, fill: true, }, ], @@ -367,7 +391,7 @@ const WidgetsDropdown = (props) => { } /> - + {/*