Skip to content

Commit

Permalink
integrated api of Attendees Count month wise
Browse files Browse the repository at this point in the history
  • Loading branch information
Harrshhpattell committed Apr 18, 2024
1 parent 250fac0 commit 7a0b6dd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 25 deletions.
10 changes: 10 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
74 changes: 49 additions & 25 deletions src/views/widgets/WidgetsDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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
Expand All @@ -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 (
<CRow className={props.className} xs={{ gutter: 4 }}>
Expand Down Expand Up @@ -212,9 +235,9 @@ const WidgetsDropdown = (props) => {
value={
<>
{events.length}{" "}
<span className="fs-6 fw-normal">
{/* <span className="fs-6 fw-normal">
({percentageIncrease.toFixed(1)}% <CIcon icon={arrowIcon} />)
</span>
</span> */}
</>
}
title="Total Events"
Expand Down Expand Up @@ -295,43 +318,44 @@ const WidgetsDropdown = (props) => {
}
/>
</CCol>
{/* <CCol sm={6} xl={4} xxl={3}>
<CCol sm={6} xl={4} xxl={3}>
<CWidgetStatsA
color="warning"
value={
<>
2.49%{' '}
{allOrdersCounts}{" "}
<span className="fs-6 fw-normal">
(84.7% <CIcon icon={cilArrowTop} />)
{/* (84.7% <CIcon icon={cilArrowTop} />) */}
(2024)
</span>
</>
}
title="Conversion Rate"
action={
<CDropdown alignment="end">
<CDropdownToggle color="transparent" caret={false} className="text-white p-0">
<CIcon icon={cilOptions} />
</CDropdownToggle>
<CDropdownMenu>
<CDropdownItem>Action</CDropdownItem>
<CDropdownItem>Another action</CDropdownItem>
<CDropdownItem>Something else here...</CDropdownItem>
<CDropdownItem disabled>Disabled action</CDropdownItem>
</CDropdownMenu>
</CDropdown>
}
title="Total Attendees"
// action={
// <CDropdown alignment="end">
// <CDropdownToggle color="transparent" caret={false} className="text-white p-0">
// <CIcon icon={cilOptions} />
// </CDropdownToggle>
// <CDropdownMenu>
// <CDropdownItem>Action</CDropdownItem>
// <CDropdownItem>Another action</CDropdownItem>
// <CDropdownItem>Something else here...</CDropdownItem>
// <CDropdownItem disabled>Disabled action</CDropdownItem>
// </CDropdownMenu>
// </CDropdown>
// }
chart={
<CChartLine
className="mt-3"
style={{ height: '70px' }}
style={{ height: '70px', color: "#4F99FF" }}
data={{
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [
{
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,
},
],
Expand Down Expand Up @@ -367,7 +391,7 @@ const WidgetsDropdown = (props) => {
}
/>
</CCol>
<CCol sm={6} xl={4} xxl={3}>
{/* <CCol sm={6} xl={4} xxl={3}>
<CWidgetStatsA
color="danger"
value={
Expand Down

0 comments on commit 7a0b6dd

Please sign in to comment.