From d21eb2dc5bae8a84a2e3c778e0b7616dc5df1fb4 Mon Sep 17 00:00:00 2001 From: pawan-dot <71133473+pawan-dot@users.noreply.github.com> Date: Wed, 10 Aug 2022 13:55:18 +0530 Subject: [PATCH] recheck --- src/_nav.js | 12 +- src/index.js | 2 +- src/views/dashboard/Dashboard.js | 116 +++++- src/views/pages/register/Change_password.js | 2 +- src/views/pages/register/ForgotPassword.js | 2 +- src/views/widgets/WidgetsDropdown.js | 417 ++++++-------------- 6 files changed, 234 insertions(+), 317 deletions(-) diff --git a/src/_nav.js b/src/_nav.js index d7b0639..646006f 100644 --- a/src/_nav.js +++ b/src/_nav.js @@ -85,12 +85,12 @@ const _nav = [ icon: , to: '/requirement', }, - { - component: CNavItem, - name: 'FAQs', - icon: , - to: '/FAQs', - }, + // { + // component: CNavItem, + // name: 'FAQs', + // icon: , + // to: '/FAQs', + // }, { component: CNavItem, name: 'Users', diff --git a/src/index.js b/src/index.js index 05329e4..dc6683f 100644 --- a/src/index.js +++ b/src/index.js @@ -12,7 +12,7 @@ import axios from 'axios' const setupAxios = () => { axios.defaults.baseURL = 'https://cms-api-dashboard.herokuapp.com/'; - // axios.defaults.baseURL = 'http://localhost:5000' + //axios.defaults.baseURL = 'http://localhost:5000' axios.defaults.headers = { 'Cache-Control': 'no-cache,no-store', 'Pragma': 'no-cache', diff --git a/src/views/dashboard/Dashboard.js b/src/views/dashboard/Dashboard.js index eae717a..9aa67bd 100644 --- a/src/views/dashboard/Dashboard.js +++ b/src/views/dashboard/Dashboard.js @@ -1,20 +1,122 @@ import React, { lazy } from 'react' - - +import axios from "axios"; +import { useEffect, useState, useCallback, useMemo } from "react"; +import { isAutheticated } from "../../auth.js"; const WidgetsDropdown = lazy(() => import('../widgets/WidgetsDropdown.js')) -const WidgetsBrand = lazy(() => import('../widgets/WidgetsBrand.js')) + const Dashboard = () => { - const random = (min, max) => { - return Math.floor(Math.random() * (max - min + 1) + min) - } + //1 st + const [users, setUsers] = useState([]) + const token = isAutheticated(); + + const getAllUsers = useCallback(async () => { + let res = await axios.get( + `/api/v1/admin/users`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + // console.log(res.data) + setUsers(res.data.users) + }, [token]); + //2nd + const [category, setCategory] = useState([]) + const getAllCategory = useCallback(async () => { + let res = await axios.get( + `/api/category/getAll`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + // console.log(res.data.category[0].image.url) + setCategory(res.data.category) + }, [token]); + //3 requiment + const [requirement, setRequirement] = useState([]) + // console.log(token) + const getRequirement = useCallback(async () => { + let res = await axios.get( + `/api/requirement/getAll`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + + setRequirement(res.data.Requirement) + + }, [token]); + //4 news + const [news, setNews] = useState([]) + + const getNews = useCallback(async () => { + let res = await axios.get( + `/api/news/getAll`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + + setNews(res.data.news) + + + }, [token]); + //5 offers + const [offer, setOffer] = useState([]) + + const getOffer = useCallback(async () => { + let res = await axios.get( + `/api/offer/getAll`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + // console.log(res.data) + setOffer(res.data.offer) + + + }, [token]); + //6 event + const [event, setEvent] = useState([]) + const getEvent = useCallback(async () => { + let res = await axios.get( + `/api/event/getAll`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + // console.log(res.data) + setEvent(res.data.Event) + + + }, [token]); + useEffect(() => { + getAllUsers(); + getAllCategory() + getRequirement() + getNews() + getOffer() + getEvent() + }, [getAllUsers, getAllCategory, getRequirement, getNews, getOffer, getEvent]); return ( <> - + ) diff --git a/src/views/pages/register/Change_password.js b/src/views/pages/register/Change_password.js index 1db3639..753c631 100644 --- a/src/views/pages/register/Change_password.js +++ b/src/views/pages/register/Change_password.js @@ -83,7 +83,7 @@ const Register = () => { - setOldPassword(e.target.value)} /> + setOldPassword(e.target.value)} /> diff --git a/src/views/pages/register/ForgotPassword.js b/src/views/pages/register/ForgotPassword.js index a0d29d9..d9f306a 100644 --- a/src/views/pages/register/ForgotPassword.js +++ b/src/views/pages/register/ForgotPassword.js @@ -31,7 +31,7 @@ const ForgotPassword = () => { setLoading(true) const res = await axios.post(`/api/v1/user/password/forgot`, { email: email }) - //console.log(res); + // console.log(res); if (res.data.success === true) { setLoading(false) // alert("Email Send Successfully! please check your mail for reset password") diff --git a/src/views/widgets/WidgetsDropdown.js b/src/views/widgets/WidgetsDropdown.js index 3b5b078..468f679 100644 --- a/src/views/widgets/WidgetsDropdown.js +++ b/src/views/widgets/WidgetsDropdown.js @@ -13,7 +13,7 @@ import { CChartBar, CChartLine } from '@coreui/react-chartjs' import CIcon from '@coreui/icons-react' import { cilArrowBottom, cilArrowTop, cilOptions } from '@coreui/icons' -const WidgetsDropdown = () => { +const WidgetsDropdown = ({ users, category, requirement, news, offer, event }) => { return ( @@ -22,85 +22,82 @@ const WidgetsDropdown = () => { color="primary" value={ <> - 26K{' '} - {/* - (-12.4% ) - */} + {users.length} } - title="Users" - // action={ - // - // - // - // - // - // Action - // Another action - // Something else here... - // Disabled action - // - // - // } - chart={ - - } + title="Total Users" + // action={ + // + // + // + // + // + // Action + // Another action + // Something else here... + // Disabled action + // + // + // } + // chart={ + // + // } /> @@ -109,157 +106,25 @@ const WidgetsDropdown = () => { color="info" value={ <> - $6.200{' '} - {/* - (40.9% ) - */} + {category.length} } - title="Income" - // action={ - // - // - // - // - // - // Action - // Another action - // Something else here... - // Disabled action - // - // - // } - chart={ - - } + title="Total Categories" + /> - {/* + - 2.49{' '} - - (84.7% ) - + {requirement.length} + } - title="Conversion Rate" - action={ - - - - - - Action - Another action - Something else here... - Disabled action - - - } - chart={ - - } + title="Requirements" + /> @@ -268,92 +133,42 @@ const WidgetsDropdown = () => { color="danger" value={ <> - 44K{' '} - - (-23.6% ) - + {news.length} + } - title="Sessions" - action={ - - - - - - Action - Another action - Something else here... - Disabled action - - - } - chart={ - - } + title="Total News" + /> - */} + + + + {offer.length} + + + } + title="Total Offers" + + /> + + + + {event.length} + + + } + title="Total Events" + + /> + ) }