From 6fc6d8b36ff3563a81fcfd1b4eb343168c7a69ff Mon Sep 17 00:00:00 2001 From: pawan-dot <71133473+pawan-dot@users.noreply.github.com> Date: Tue, 28 Jun 2022 12:29:55 +0530 Subject: [PATCH] make it better --- .env | 4 +- .gitignore | Bin 360 -> 332 bytes package.json | 6 +- src/App.js | 79 ++++-- src/_nav.js | 39 +++ src/auth.js | 1 + src/components/AppHeader.js | 2 +- src/routes.js | 54 ++++ src/store.js | 48 ++-- src/views/Banners/AddBanner.js | 219 +++++++++++++++ src/views/Banners/Banner.js | 166 +++++++++++ src/views/Banners/EditBanner.js | 238 ++++++++++++++++ src/views/Banners/ViewBanner.js | 128 +++++++++ src/views/CMS/EditCms.js | 125 +++++++++ src/views/CMS/ViewCms.js | 127 +++++++++ src/views/CMS/cms.js | 245 +++++++++++++++++ src/views/Category/Category.js | 4 +- src/views/Directory/Add_Business.js | 99 ++++++- src/views/Directory/Bisuness.js | 290 ++++++++++---------- src/views/Directory/EditBisuness.js | 57 +++- src/views/Directory/View_Bisuness.js | 69 ++--- src/views/Events/AddEvent.js | 164 +++++++++++ src/views/Events/EditEvent.js | 178 ++++++++++++ src/views/Events/Event.js | 166 +++++++++++ src/views/Events/ViewEvent.js | 122 ++++++++ src/views/Feedback/Pagination.js | 25 ++ src/views/Feedback/ViewFeedback.js | 123 +++++++++ src/views/Feedback/feedback.js | 146 ++++++++++ src/views/News/EditNews.js | 1 - src/views/News/News.js | 6 +- src/views/News/ViewNews.js | 47 ++-- src/views/Offers/AddOffer.js | 215 +++++++++++++++ src/views/Offers/EditOffer.js | 224 +++++++++++++++ src/views/Offers/Offer.js | 162 +++++++++++ src/views/Offers/ViewOffer.js | 137 +++++++++ src/views/Users/Pagination.js | 25 ++ src/views/Users/ViewUsers.js | 131 +++++++++ src/views/Users/users.js | 153 +++++++++++ src/views/pages/login/Login.js | 25 +- src/views/pages/register/Change_password.js | 20 +- 40 files changed, 3768 insertions(+), 302 deletions(-) create mode 100644 src/views/Banners/AddBanner.js create mode 100644 src/views/Banners/Banner.js create mode 100644 src/views/Banners/EditBanner.js create mode 100644 src/views/Banners/ViewBanner.js create mode 100644 src/views/CMS/EditCms.js create mode 100644 src/views/CMS/ViewCms.js create mode 100644 src/views/CMS/cms.js create mode 100644 src/views/Events/AddEvent.js create mode 100644 src/views/Events/EditEvent.js create mode 100644 src/views/Events/Event.js create mode 100644 src/views/Events/ViewEvent.js create mode 100644 src/views/Feedback/Pagination.js create mode 100644 src/views/Feedback/ViewFeedback.js create mode 100644 src/views/Feedback/feedback.js create mode 100644 src/views/Offers/AddOffer.js create mode 100644 src/views/Offers/EditOffer.js create mode 100644 src/views/Offers/Offer.js create mode 100644 src/views/Offers/ViewOffer.js create mode 100644 src/views/Users/Pagination.js create mode 100644 src/views/Users/ViewUsers.js create mode 100644 src/views/Users/users.js diff --git a/.env b/.env index 0c48d3c..a0be3ed 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ -PORT=3000 -CHOKIDAR_USEPOLLING=true +PORT = 3000 +CHOKIDAR_USEPOLLING = true \ No newline at end of file diff --git a/.gitignore b/.gitignore index 89228afba5db6561552f30e4083847e764050b48..e080cd5fb78aaf40b77f487c198655abed98ea96 100644 GIT binary patch delta 7 OcmaFCbcShz4 @@ -22,33 +24,72 @@ const Register = React.lazy(() => import('./views/pages/register/Change_password const Page404 = React.lazy(() => import('./views/pages/page404/Page404')) const Page500 = React.lazy(() => import('./views/pages/page500/Page500')) -class App extends Component { - render() { - return ( - - - - < Route exact path="/" name="Login Page" render={(props) => } /> +const App = () => { - } /> - } /> + const [userdata, setUserData] = useState(null) + const token = isAutheticated(); - } /> - } /> + useEffect(() => { + const getUser = async () => { + let existanceData = localStorage.getItem("authToken"); + if (!existanceData) { + // console.log(existanceData.userData) + setUserData(false) + } else { + try { + console.log('requesting user data from server') + let response = await axios.get(`/api/v1/user/details`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }) + //console.log(response) + const data = response.data + if (data.success) { + + setUserData(data.user); + } else { + setUserData(false) + } + + } + catch (err) { + setUserData(false) + console.log(err); + }; + } + + } + getUser() + }, []) + + return ( + + + + < Route exact path="/" name="Login Page" render={(props) => } /> + + } /> + } /> + + } /> + } /> - {/* localStorage.getItem('authToken') ? */} - } /> - {/* < ProtectedRoute path="/" name="Home" render={(props) => } /> */} + {/* localStorage.getItem('authToken') ? */} + ( + userdata && userdata?._id ? : + userdata === false ? :
+ )} /> + {/* < ProtectedRoute path="/" name="Home" render={(props) => } /> */} -
-
-
- ) - } +
+
+
+ ) } //@coreui/coreui-free-react-admin-template@4.1.1 export default App diff --git a/src/_nav.js b/src/_nav.js index c854006..a7a8cdb 100644 --- a/src/_nav.js +++ b/src/_nav.js @@ -14,6 +14,8 @@ import { cilSpeedometer, cilStar, cilUser, + + } from '@coreui/icons' import { CNavGroup, CNavItem, CNavTitle } from '@coreui/react' @@ -44,6 +46,43 @@ const _nav = [ icon: , to: '/news', }, + { + component: CNavItem, + name: 'Events', + icon: , + to: '/event', + }, + { + component: CNavItem, + name: 'Offers', + icon: , + to: '/offer', + }, + + { + component: CNavItem, + name: 'Banners', + icon: , + to: '/banner', + }, + { + component: CNavItem, + name: 'CMS', + icon: , + to: '/cms', + }, + { + component: CNavItem, + name: 'Customer Feedback', + icon: , + to: '/feedback', + }, + { + component: CNavItem, + name: 'Users', + icon: , + to: '/users', + }, ] diff --git a/src/auth.js b/src/auth.js index 434c3d9..bcf96f4 100644 --- a/src/auth.js +++ b/src/auth.js @@ -5,6 +5,7 @@ export const isAutheticated = () => { if (localStorage.getItem("authToken")) { return (localStorage.getItem("authToken")); + //console.log(localStorage.getItem("authToken")) } else { return false; } diff --git a/src/components/AppHeader.js b/src/components/AppHeader.js index 9b9b9aa..6ebfec6 100644 --- a/src/components/AppHeader.js +++ b/src/components/AppHeader.js @@ -32,7 +32,7 @@ const AppHeader = () => { -

Courier

+

CMP

diff --git a/src/routes.js b/src/routes.js index 9c36913..cc1bbd4 100644 --- a/src/routes.js +++ b/src/routes.js @@ -13,6 +13,31 @@ import AddNews from "./views/News/AddNews" import EditNews from "./views/News/EditNews" import News from "./views/News/News" import ViewNews from "./views/News/ViewNews" +//Events +import Event from './views/Events/Event' +import EditEvent from './views/Events/EditEvent' +import AddEvent from './views/Events/AddEvent' +import ViewEvent from './views/Events/ViewEvent' +//offers Route +import Offer from './views/Offers/Offer' +import AddOffer from './views/Offers/AddOffer' +import EditOffer from './views/Offers/EditOffer' +import ViewOffer from './views/Offers/ViewOffer' +//Banner +import Banner from './views/Banners/Banner' +import ViewBanner from './views/Banners/ViewBanner' +import EditBanner from './views/Banners/EditBanner' +import AddBanner from './views/Banners/AddBanner' +//cms +import CMS from './views/CMS/cms' +import CMSView from './views/CMS/ViewCms' +import CMSEdit from './views/CMS/EditCms' +//cms +import Feedback from './views/Feedback/feedback' +import ViewFeedback from './views/Feedback/ViewFeedback' +//cms +import Users from './views/Users/users' +import ViewUsers from './views/Users/ViewUsers' // DashBoard const Change_Password = React.lazy(() => import('./views/pages/register/Change_password')) @@ -42,8 +67,37 @@ const routes = [ { path: '/addNews', name: 'addNews', component: AddNews }, { path: '/news/edit/:id', name: 'EditNews', component: EditNews }, { path: '/news', name: 'news', component: News }, + //Events route + { path: '/event/view/:id', name: 'ViewEvent', component: ViewEvent }, + { path: '/addevent', name: 'AddEvent', component: AddEvent }, + { path: '/event/edit/:id', name: 'EditEvent', component: EditEvent }, + { path: '/event', name: 'Event', component: Event }, + + //Offers route + { path: '/offer/view/:id', name: 'Viewoffer', component: ViewOffer }, + { path: '/addOffer', name: 'AddOffer', component: AddOffer }, + { path: '/offer/edit/:id', name: 'EditOffer', component: EditOffer }, + { path: '/offer', name: 'offer', component: Offer }, + + //BANNERS + { path: '/banner/view/:id', name: 'ViewBanner', component: ViewBanner }, + { path: '/addbanner', name: 'AddBanner', component: AddBanner }, + { path: '/banner/edit/:id', name: 'EditBanner', component: EditBanner }, + { path: '/banner', name: 'Banner', component: Banner }, + //CMS + { path: '/cms/view/:id', name: 'CMS', component: CMSView }, + { path: '/cms/edit/:id', name: 'CMS', component: CMSEdit }, + { path: '/cms', name: 'CMS', component: CMS }, + //CMS + { path: '/feedback/view/:id', name: 'ViewFeedback', component: ViewFeedback }, + { path: '/feedback', name: 'Feedback', component: Feedback }, + + //Users + { path: '/users/view/:id', name: 'ViewUsers', component: ViewUsers }, + { path: '/users', name: 'users', component: Users }, //dashboard + { path: '/dashboard', name: 'Dashboard', component: Dashboard }, ] diff --git a/src/store.js b/src/store.js index 5f2dc7b..81c401c 100644 --- a/src/store.js +++ b/src/store.js @@ -1,31 +1,31 @@ -// import { createStore } from 'redux' +import { createStore } from 'redux' -// const initialState = { -// sidebarShow: true, -// } +const initialState = { + sidebarShow: true, +} -// const changeState = (state = initialState, { type, ...rest }) => { -// switch (type) { -// case 'set': -// return { ...state, ...rest } -// default: -// return state -// } -// } +const changeState = (state = initialState, { type, ...rest }) => { + switch (type) { + case 'set': + return { ...state, ...rest } + default: + return state + } +} -// const store = createStore(changeState) -// export default store -import { configureStore } from "@reduxjs/toolkit"; -import { newCategoryReducer, AllcategoryReducer } from "./reducers/categoryReducer.js"; -import { loginReducer } from "./reducers/directoryReducer.js"; +const store = createStore(changeState) +export default store +// import { configureStore } from "@reduxjs/toolkit"; +// import { newCategoryReducer, AllcategoryReducer } from "./reducers/categoryReducer.js"; +// import { loginReducer } from "./reducers/directoryReducer.js"; -const store = configureStore({ - reducer: { +// const store = configureStore({ +// reducer: { - newCategory: newCategoryReducer, - AllCategory: AllcategoryReducer, +// newCategory: newCategoryReducer, +// AllCategory: AllcategoryReducer, - }, -}); +// }, +// }); -export default store; \ No newline at end of file +// export default store; \ No newline at end of file diff --git a/src/views/Banners/AddBanner.js b/src/views/Banners/AddBanner.js new file mode 100644 index 0000000..1dbebd0 --- /dev/null +++ b/src/views/Banners/AddBanner.js @@ -0,0 +1,219 @@ +import axios from "axios"; +import React, { useCallback, useEffect, useState } from "react"; +import { API } from "../../data"; +import { isAutheticated } from "../../auth"; +import ClipLoader from "react-spinners/ClipLoader"; +import { useHistory } from "react-router-dom"; +import swal from 'sweetalert'; + + +import { + CButton, + CCard, + CCardBody, + CCol, + CContainer, + CForm, + CFormInput, + CInputGroup, + CInputGroupText, + CRow, +} from '@coreui/react' +import CIcon from '@coreui/icons-react' +import { cilPencil, cilNotes, cilCalendar } from '@coreui/icons' +const AddBanner = () => { + const { token } = isAutheticated(); + let history = useHistory(); + const [image, setImage] = useState(""); + const [title, setTitle] = useState(""); + const [subTitle, setSubTitle] = useState(""); + const [section, setSection] = useState(""); + + const [startDate, setStartDate] = useState(new Date()); + const [endDate, setEndDate] = useState(new Date()); + + + const [loading, setLoading] = useState(false); + + + const handleSubmit = async () => { + const myForm = new FormData(); + + myForm.set("title", title); + myForm.set("subTitle", subTitle); + myForm.set("section", section); + myForm.set("startDate", startDate); + myForm.set("endDate", endDate); + myForm.set("image", image); + setLoading({ loading: true }); + // console.log(image) + let res = await axios.post( + `/api/banner/create`, myForm, + { + headers: { + "Content-Type": 'multipart/form-data', + Authorization: `Bearer ${token}`, + }, + } + ); + // console.log(res.data) + if (res.data) { + swal("success!", "Banner Added Successfully!", "success"); + history.goBack(); + } + + setLoading(false); + }; + const handleImage = (e) => { + const files = e.target.files[0]; + // console.log(files) + setImage(files); + + }; + // + const onCancel = () => { + // window.location = "/comproducts"; + history.goBack() + + }; + + return ( + <> +
+ + + + + + +

Add Banner

+
+
+ + + + + setTitle(e.target.value)} + value={title} + placeholder="Title" /> + + + + + + setSubTitle(e.target.value)} + value={subTitle} + placeholder="sub title" /> + + + + + + + + + + + + Start Date* + + + {/* */} + + setStartDate(e.target.value)} + value={startDate} + placeholder="Start Date" /> + + + + + End Date* + + + setEndDate(e.target.value)} + value={endDate} + placeholder="EndDate" /> + + {/* + + + + setLocation(e.target.value)} + value={location} + placeholder="Location" /> + */} + + + + {/* */} + + + +
+ +
+ + +
+
+
+
+
+
+
+
+
+ + + ) +} + +export default AddBanner \ No newline at end of file diff --git a/src/views/Banners/Banner.js b/src/views/Banners/Banner.js new file mode 100644 index 0000000..928443d --- /dev/null +++ b/src/views/Banners/Banner.js @@ -0,0 +1,166 @@ + +import axios from "axios"; +import React, { useEffect, useState, useCallback, useMemo } from "react"; +import { Link } from "react-router-dom"; +import swal from 'sweetalert'; +// import { API } from "../../data"; +import { isAutheticated } from "../../auth"; + +function banner() { + const [banner, setBanner] = useState([]) + + const { token } = isAutheticated(); + + const getEvent = useCallback(async () => { + let res = await axios.get( + `/api/banner/getAll`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + console.log(res.data) + setBanner(res.data.banner) + + + }, [token]); + + useEffect(() => { + getEvent(); + }, [getEvent]); + + + const handleDelete = async (id) => { + let status = window.confirm("Do you want to delete"); + if (!status) return; + + let res = await axios.delete(`/api/banner/delete/${id}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + console.log(res) + if (res.data.success == true) { + swal("success!", "Banner Deleted Successfully!", "success"); + window.location.reload(); + } + }; + + + //change time formate + function formatAMPM(date) { + var hours = new Date(date).getHours(); + var minutes = new Date(date).getMinutes(); + var ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? '0' + minutes : minutes; + var strTime = hours + ':' + minutes + ' ' + ampm; + return strTime; + } + + + return ( +
+
+
+ {/* */} +
+
+
+

CMP-BANNER

+ + {/*
+
    +
  1. + CMD-App +
  2. +
  3. CMD-Category
  4. +
+
*/} +
+
+
+ {/* */} + +
+
+
+
+
+ +
+
+ + + + + + + + + + + + {banner && banner.map((item, index) => + + + + + + + + + + )} + +
TitleImageSectionAdded OnAction
{item?.title} + {item?.section} + {/* {item?.addedOn} */} + {new Date(`${item?.addedOn}`).toDateString()} , {`${formatAMPM(item?.addedOn)}`} + + + + + + + + + + + +
+
+ + + {/* */} +
+
+
+
+
+ {/* */} +
+
+ ); +} + +export default banner; diff --git a/src/views/Banners/EditBanner.js b/src/views/Banners/EditBanner.js new file mode 100644 index 0000000..69c2974 --- /dev/null +++ b/src/views/Banners/EditBanner.js @@ -0,0 +1,238 @@ + + +import axios from "axios"; +import React, { useCallback, useEffect, useState } from "react"; +import { API } from "../../data"; +import { isAutheticated } from "../../auth"; +import ClipLoader from "react-spinners/ClipLoader"; +import { useHistory } from "react-router-dom"; +import swal from 'sweetalert'; +import { useParams } from "react-router-dom"; + +import { + CButton, + CCard, + CCardBody, + CCol, + CContainer, + CForm, + CFormInput, + CInputGroup, + CInputGroupText, + CRow, +} from '@coreui/react' +import CIcon from '@coreui/icons-react' +import { cilPencil, cilNotes, cilCalendar } from '@coreui/icons' +const EditBanner = () => { + const { id } = useParams(); + const { token } = isAutheticated(); + let history = useHistory(); + const [image, setImage] = useState(""); + const [title, setTitle] = useState(""); + const [subTitle, setSubTitle] = useState(""); + const [section, setSection] = useState(""); + + const [startDate, setStartDate] = useState(""); + const [endDate, setEndDate] = useState(""); + + + const [loading, setLoading] = useState(false); + //fetch one Offer + useEffect(async () => { + const res = await axios.get(`/api/banner/getOne/${id}`, { + // headers: { + // Authorization: `Bearer ${token}`, + // }, + }); + // console.log(res.data.banner) + // console.log(res.data.banner.startDate) + setTitle(res.data.banner.title) + setSubTitle(res.data.banner.subTitle) + setSection(res.data.banner.section) + setStartDate(new Date(res.data.banner.startDate).toLocaleDateString()) + setEndDate(new Date(res.data.banner.endDate).toLocaleDateString()) + + }, [id]); + + const handleSubmit = async () => { + const myForm = new FormData(); + + myForm.set("title", title); + myForm.set("subTitle", subTitle); + myForm.set("section", section); + myForm.set("startDate", startDate); + myForm.set("endDate", endDate); + myForm.set("image", image); + setLoading({ loading: true }); + // console.log(image) + let res = await axios.put( + `/api/banner/update/${id}`, myForm, + { + headers: { + "Content-Type": 'multipart/form-data', + Authorization: `Bearer ${token}`, + }, + } + ); + // console.log(res.data) + if (res.data) { + swal("success!", "Banner Updated Successfully!", "success"); + history.goBack(); + } + + setLoading(false); + }; + const handleImage = (e) => { + const files = e.target.files[0]; + // console.log(files) + setImage(files); + + }; + // + const onCancel = () => { + // window.location = "/comproducts"; + history.goBack() + + }; + + return ( + <> +
+ + + + + + +

Edit Banner

+
+
+ + + + + setTitle(e.target.value)} + value={title} + placeholder="Title" /> + + + + + + setSubTitle(e.target.value)} + value={subTitle} + placeholder="sub title" /> + + + + + + + + + + + + + Start Date* + + + {/* */} + + setStartDate(e.target.value)} + value={startDate} + placeholder="Start Date" /> + + + + + End Date* + + + setEndDate(e.target.value)} + value={endDate} + placeholder="EndDate" /> + + {/* + + + + setLocation(e.target.value)} + value={location} + placeholder="Location" /> + */} + + + + {/* */} + + + +
+ +
+ + +
+
+
+
+
+
+
+
+
+ + + ) +} + +export default EditBanner \ No newline at end of file diff --git a/src/views/Banners/ViewBanner.js b/src/views/Banners/ViewBanner.js new file mode 100644 index 0000000..7d7944a --- /dev/null +++ b/src/views/Banners/ViewBanner.js @@ -0,0 +1,128 @@ + + + + +import axios from "axios"; +import React, { useEffect, useState, useCallback, useMemo } from "react"; +import swal from 'sweetalert'; +// import { API } from "../../data"; +import { Link, useParams } from "react-router-dom"; +import { isAutheticated } from "../../auth"; + +function ViewBanner() { + const [banner, setBanner] = useState([]) + const { id } = useParams(); + // console.log(id) + const { token } = isAutheticated(); + + const getBanner = useCallback(async () => { + let res = await axios.get( + `/api/banner/getOne/${id}`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + + setBanner(res.data.banner) + + + }, [token]); + + useEffect(() => { + getBanner(); + }, [getBanner]); + + + + + + //change time formate + function formatAMPM(date) { + var hours = new Date(date).getHours(); + var minutes = new Date(date).getMinutes(); + var ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? '0' + minutes : minutes; + var strTime = hours + ':' + minutes + ' ' + ampm; + return strTime; + } + + + return ( +
+
+
+ {/* */} +
+
+
+

CMP-BANNER

+ + {/*
+
    +
  1. + CMD-App +
  2. +
  3. CMD-Category
  4. +
+
*/} +
+
+
+ {/* */} + +
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
Id{banner?._id}
Title{banner?.title}
Sub Title{banner?.subTitle}
Image + +
Section{banner?.section}
Start Date + {new Date(`${banner?.startDate}`).toDateString()} +
End Date + {new Date(`${banner?.endDate}`).toDateString()}
Added On + {new Date(`${banner?.addedOn}`).toDateString()} , {`${formatAMPM(banner?.addedOn)}`} +
Updated At + {new Date(`${banner?.updatedAt}`).toDateString()} , {`${formatAMPM(banner?.updatedAt)}`} +
+
+ + + {/* */} +
+
+
+
+
+ {/* */} +
+
+ ); +} + +export default ViewBanner; diff --git a/src/views/CMS/EditCms.js b/src/views/CMS/EditCms.js new file mode 100644 index 0000000..36d919f --- /dev/null +++ b/src/views/CMS/EditCms.js @@ -0,0 +1,125 @@ +import axios from "axios"; +import React, { useEffect, useState, useCallback } from "react"; + +import { isAutheticated } from "../../auth"; +import ClipLoader from "react-spinners/ClipLoader"; +import swal from 'sweetalert'; +import { Link, useParams } from "react-router-dom"; +import { useHistory } from "react-router-dom"; +const EditCms = () => { + const { id } = useParams() + const token = isAutheticated(); + // console.log(token, id) + let history = useHistory(); + const [state, setState] = useState({ + About_Us: "", + Terms_and_Conditions: "", + Privacy_Policy: "", + + loading: false, + + }); + const { loading } = state; + const changeState = (newState) => + setState((prevState) => ({ ...prevState, ...newState })); + + + const handleChange = (e) => { + changeState({ ...state, [e.target.name]: e.target.value }) + + } + const fetchRestriction = useCallback(async () => { + const res = await axios.get(`/api/restriction/getOne/${id}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + + // console.log(res.data.CmpRes) + setState(res.data.CmpRestriction) + changeState({ loading: false }); + if (res.status === 200) changeState({ ...res.data }); + }, [token]); + + useEffect(() => { + fetchRestriction(); + }, [fetchRestriction]); + + + const handleSubmit = async () => { + + changeState({ loading: true }); + let res = await axios.put( + `/api/restriction/update/${id}`, + { + ...state, + }, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + //if (res.status === 200) window.location.reload(); + // console.log(res.data) + // console.log(res.status == 200) + if (res.data.success == true) { + changeState({ loading: false }); + swal("Edit CMP-Condition successfully!"); + history.goBack() + } + }; + const onCancel = () => { + // window.location = "/comproducts"; + history.goBack() + + }; + + return ( + <> +
+
+

EDIT-CMS

+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+ + ) +} + +export default EditCms \ No newline at end of file diff --git a/src/views/CMS/ViewCms.js b/src/views/CMS/ViewCms.js new file mode 100644 index 0000000..311395e --- /dev/null +++ b/src/views/CMS/ViewCms.js @@ -0,0 +1,127 @@ + +import axios from "axios"; +import React, { useEffect, useState, useCallback, useMemo } from "react"; +import swal from 'sweetalert'; +// import { API } from "../../data"; +import { Link, useParams } from "react-router-dom"; +import { isAutheticated } from "../../auth"; + +function ViewOffer() { + const [cmsRes, setCmsRes] = useState([]) + const { id } = useParams(); + // console.log(id) + const token = isAutheticated(); + + const getOffer = useCallback(async () => { + let res = await axios.get( + `/api/restriction/getOne/${id}`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + //console.log(res.data) + setCmsRes(res.data.CmpRestriction) + + + }, [token]); + + useEffect(() => { + getOffer(); + }, [getOffer]); + + + + + + //change time formate + function formatAMPM(date) { + var hours = new Date(date).getHours(); + var minutes = new Date(date).getMinutes(); + var ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? '0' + minutes : minutes; + var strTime = hours + ':' + minutes + ' ' + ampm; + return strTime; + } + + + return ( +
+
+
+ {/* */} +
+
+
+

CMP-CMS

+ {/* */} + {/*
+
    +
  1. + CMD-App +
  2. +
  3. CMD-Category
  4. +
+
*/} +
+
+
+ {/* */} + +
+
+
+
+
+ +
+
+ + + + {/* */} + + + + + + + + + + + + + + + + + + + + +
Id
About Us{cmsRes?.About_Us}
Terms and Conditions{cmsRes?.Terms_and_Conditions}
Privacy Policy{cmsRes?.Privacy_Policy}
Added On + {new Date(`${cmsRes?.createdAt}`).toDateString()} , {`${formatAMPM(cmsRes?.createdAt)}`} +
Updated At + {new Date(`${cmsRes?.updatedAt}`).toDateString()} , {`${formatAMPM(cmsRes?.updatedAt)}`} +
+
+ + + {/* */} +
+
+
+
+
+ {/* */} +
+
+ ); +} + +export default ViewOffer; + diff --git a/src/views/CMS/cms.js b/src/views/CMS/cms.js new file mode 100644 index 0000000..0f2bb58 --- /dev/null +++ b/src/views/CMS/cms.js @@ -0,0 +1,245 @@ + +import axios from "axios"; +import React, { useEffect, useState, useCallback, useMemo } from "react"; +import { Link } from "react-router-dom"; +import swal from 'sweetalert'; +// import { API } from "../../data"; +import { isAutheticated } from "../../auth"; + +function cms() { + const [cmsRes, setCmsRes] = useState([]) + + const token = isAutheticated(); + + const getRestriction = useCallback(async () => { + let res = await axios.get( + `/api/restriction/getAll`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + // console.log(res.data.CmpRestriction[0]) + setCmsRes(res.data.CmpRestriction[0]) + + + }, [token]); + + useEffect(() => { + getRestriction(); + }, [getRestriction]); + + + // console.log(cmsRes) + + return ( +
+
+
+ {/* */} +
+
+
+

CMP-CMS

+ {/* */} + {/*
+
    +
  1. + CMD-App +
  2. +
  3. CMD-Category
  4. +
+
*/} +
+
+
+ {/* */} + +
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
About UsTerms and ConditionsPrivacy PolicyAction
{cmsRes?.About_Us}{cmsRes?.Terms_and_Conditions}{cmsRes?.Privacy_Policy} + + + + + + + + + {/* */} +
+
+ + {/* second table */} + + {/*
+ + + + + + + + + + + + + + + + + + + + +
Terms and ConditionsAction
{cmsRes?.Terms_and_Conditions} + + + + + + + + + {/* */} + {/*
+
*/} + + + + + {/* end second table */} + + {/* third table */} + {/*
+ + + + + + + + + + + + + + + + + + + + +
Privacy PolicyAction
{cmsRes?.Privacy_Policy} + + + + + + + + + {/* */} + {/*
+
*/} + + + {/* end third table */} + {/* */} +
+
+
+
+
+ {/* */} +
+
+ ); +} + +export default cms; diff --git a/src/views/Category/Category.js b/src/views/Category/Category.js index 44d8e82..36e0ad8 100644 --- a/src/views/Category/Category.js +++ b/src/views/Category/Category.js @@ -142,7 +142,7 @@ function Products() { @@ -150,7 +150,7 @@ function Products() { - {/*
+ return ( + <> +
+
+
+ {/* */} +
+
+
+

Bisuness-Directory

+ + {/*
  1. Dating App @@ -84,17 +84,17 @@ const Bisuness = () => {
  2. Commerce - Products
*/} -
-
-
- {/* */} +
+
+
+ {/* */} -
-
-
-
-
- {/*
+
+
+
+
+
+ {/*
*/} - {/*
+ {/* */} -
-
- - - - - - - - - - - - {bisuness.map((item) => + +
+
NameCategoryCityStatusActions
+ + + + + + + + + + + {bisuness.map((item) => - - - - - - + + + + + - + + + + + - )} - -
NameCategoryCityStatusActions
{item?.name} {item?.category}{item?.city} - - {status ? "Live" : "Suspended"} - - - - +
{item?.name} {item?.category}{item?.city} + + {status ? "Live" : "Suspended"} + + + + - - + + - + - - - -
-
+ )} + + +
- {/*
+ {/*
{
*/} - {/* */} -
-
-
-
-
- {/* */} + {/* */} +
+
- - ) +
+ {/* */} +
+
+ + ) } export default Bisuness \ No newline at end of file diff --git a/src/views/Directory/EditBisuness.js b/src/views/Directory/EditBisuness.js index 9018459..f60eef1 100644 --- a/src/views/Directory/EditBisuness.js +++ b/src/views/Directory/EditBisuness.js @@ -10,7 +10,8 @@ import { useHistory } from "react-router-dom"; const EditBisuness = () => { const [categoryName, setCategoryName] = useState([]); - const { token } = isAutheticated(); + const [image, setImage] = useState(); + const token = isAutheticated(); let history = useHistory(); const [state, setState] = useState({ @@ -93,19 +94,34 @@ const EditBisuness = () => { const handleSubmit = async () => { - if (!(name || description || phone || email || Bname || Sname || city)) { - alert("Please fill required field "); - return; - } + const myForm = new FormData(); + myForm.set('name', state.name) + myForm.set('phone', state.phone) + myForm.set('email', state.email) + myForm.set('Building_Name', state.Building_Name) + myForm.set('Street_Name', state.Street_Name) + myForm.set('country', state.country) + myForm.set('city', state.city) + myForm.set('description', state.description) + + myForm.set('category', state.category) + + myForm.set('status', state.status) + + myForm.set('Glocation', state.Glocation) + myForm.set('LinkedinUrl', state.Glocation) + myForm.set('FacebookUrl', state.FacebookUrl) + myForm.set('InstagramUrl', state.InstagramUrl) + myForm.set("image", image); + changeState({ loading: true }); let res = await axios.put( `/api/directory/update/${id}`, - { - ...state, - }, + myForm, { headers: { + "content-Type": 'multipart/form-data', Authorization: `Bearer ${token}`, }, } @@ -125,7 +141,7 @@ const EditBisuness = () => { - // console.log(state) + console.log(image) return ( <>
@@ -332,6 +348,29 @@ const EditBisuness = () => {
+
+
+
+ + setImage(e.target.files[0])} + placeholder="Bisuness Image" + /> +
+
+
diff --git a/src/views/Directory/View_Bisuness.js b/src/views/Directory/View_Bisuness.js index 1dc08c1..1538321 100644 --- a/src/views/Directory/View_Bisuness.js +++ b/src/views/Directory/View_Bisuness.js @@ -25,7 +25,7 @@ const View_Bisuness = () => { }, } ); - console.log(res.data.directory.name) + console.log(res.data.directory) setBisuness(res.data.directory) // changeState({ // ...res.data, @@ -66,52 +66,37 @@ const View_Bisuness = () => {
- - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - diff --git a/src/views/Events/AddEvent.js b/src/views/Events/AddEvent.js new file mode 100644 index 0000000..8a3f908 --- /dev/null +++ b/src/views/Events/AddEvent.js @@ -0,0 +1,164 @@ + +import axios from "axios"; +import React, { useCallback, useEffect, useState } from "react"; +import { API } from "../../data"; +import { isAutheticated } from "../../auth"; +import ClipLoader from "react-spinners/ClipLoader"; +import { useHistory } from "react-router-dom"; +import swal from 'sweetalert'; + +import { + CButton, + CCard, + CCardBody, + CCol, + CContainer, + CForm, + CFormInput, + CInputGroup, + CInputGroupText, + CRow, +} from '@coreui/react' +import CIcon from '@coreui/icons-react' +import { cilPencil, cilSettings, cilLockLocked, cilUser, cilBell, cilLocationPin, cilAudioDescription } from '@coreui/icons' +const AddEvent = () => { + const { token } = isAutheticated(); + let history = useHistory(); + const [image, setImage] = useState(""); + const [title, setTitle] = useState(""); + const [description, setDescription] = useState(""); + const [location, setLocation] = useState(""); + + const [loading, setLoading] = useState(false); + + + const handleSubmit = async () => { + const myForm = new FormData(); + + myForm.set("title", title); + myForm.set("description", description); + myForm.set("location", location); + myForm.set("image", image); + setLoading({ loading: true }); + // console.log(image) + let res = await axios.post( + `/api/event/create`, myForm, + { + headers: { + "Content-Type": 'multipart/form-data', + Authorization: `Bearer ${token}`, + }, + } + ); + // console.log(res.data) + if (res.data) { + swal("success!", "Event Added Successfully!", "success"); + history.goBack(); + } + + setLoading(false); + }; + const handleImage = (e) => { + const files = e.target.files[0]; + // console.log(files) + setImage(files); + + }; + // + const onCancel = () => { + // window.location = "/comproducts"; + history.goBack() + + }; + + return ( + <> +
+ + + + + + +

Add Event

+
+
+ + + + + setTitle(e.target.value)} + value={title} + placeholder="Title" /> + + + + + + + setDescription(e.target.value)} + value={description} + placeholder="Description" /> + + + + + + setLocation(e.target.value)} + value={location} + placeholder="Location" /> + + + + + {/* */} + + + +
+ +
+ + +
+
+
+
+
+
+
+
+
+ + + ) +} + +export default AddEvent \ No newline at end of file diff --git a/src/views/Events/EditEvent.js b/src/views/Events/EditEvent.js new file mode 100644 index 0000000..0c15dbb --- /dev/null +++ b/src/views/Events/EditEvent.js @@ -0,0 +1,178 @@ + +import axios from "axios"; +import React, { useCallback, useEffect, useState } from "react"; +import { API } from "../../data"; +import { isAutheticated } from "../../auth"; +import ClipLoader from "react-spinners/ClipLoader"; +import { useHistory } from "react-router-dom"; +import { Link, useParams } from "react-router-dom"; +import swal from 'sweetalert'; + +import { + CButton, + CCard, + CCardBody, + CCol, + CContainer, + CForm, + CFormInput, + CInputGroup, + CInputGroupText, + CRow, +} from '@coreui/react' +import CIcon from '@coreui/icons-react' +import { cilPencil, cilSettings, cilLockLocked, cilUser, cilBell, cilLocationPin, cilAudioDescription } from '@coreui/icons' +const EditEvent = () => { + const { id } = useParams(); + // console.log(id) + const { token } = isAutheticated(); + let history = useHistory(); + const [image, setImage] = useState(""); + const [title, setTitle] = useState(""); + const [description, setDescription] = useState(""); + const [location, setLocation] = useState(""); + const [loading, setLoading] = useState(false); + + //fetch one image + useEffect(async () => { + const res = await axios.get(`/api/event/getOne/${id}`, { + // headers: { + // Authorization: `Bearer ${token}`, + // }, + }); + // console.log(res.data) + setTitle(res.data.Event.title) + setDescription(res.data.Event.description) + setLocation(res.data.Event.location) + + }, [id]); + + const handleSubmit = async () => { + const myForm = new FormData(); + + myForm.set("title", title); + myForm.set("description", description); + myForm.set("location", location); + myForm.set("image", image); + setLoading({ loading: true }); + // console.log(image) + let res = await axios.put( + `/api/event/update/${id}`, myForm, + { + headers: { + "Content-Type": 'multipart/form-data', + Authorization: `Bearer ${token}`, + }, + } + ); + // console.log(res.data) + if (res.data) { + swal("success!", "Event Edit Successfully!", "success"); + history.goBack(); + } + + setLoading(false); + }; + const handleImage = (e) => { + const files = e.target.files[0]; + // console.log(files) + setImage(files); + + }; + // + const onCancel = () => { + // window.location = "/comproducts"; + history.goBack() + + }; + + return ( + <> +
+ + + + + + +

Edit Event

+
+
+ + + + + setTitle(e.target.value)} + value={title} + placeholder="Title" /> + + + + + + setDescription(e.target.value)} + value={description} + placeholder="Description" /> + + + + + + setLocation(e.target.value)} + value={location} + placeholder="Location" /> + + + + + {/* */} + + + +
+ +
+ + +
+
+
+
+
+
+
+
+
+ + + ) +} + +export default EditEvent \ No newline at end of file diff --git a/src/views/Events/Event.js b/src/views/Events/Event.js new file mode 100644 index 0000000..cf7cab8 --- /dev/null +++ b/src/views/Events/Event.js @@ -0,0 +1,166 @@ + +import axios from "axios"; +import React, { useEffect, useState, useCallback, useMemo } from "react"; +import { Link } from "react-router-dom"; +import swal from 'sweetalert'; +// import { API } from "../../data"; +import { isAutheticated } from "../../auth"; + +function Event() { + const [event, setEvent] = useState([]) + + const { token } = isAutheticated(); + + 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(() => { + getEvent(); + }, [getEvent]); + + + const handleDelete = async (id) => { + let status = window.confirm("Do you want to delete"); + if (!status) return; + + let res = await axios.delete(`/api/event/delete/${id}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + console.log(res) + if (res.data.success == true) { + swal("success!", "Event Deleted Successfully!", "success"); + window.location.reload(); + } + }; + + + //change time formate + function formatAMPM(date) { + var hours = new Date(date).getHours(); + var minutes = new Date(date).getMinutes(); + var ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? '0' + minutes : minutes; + var strTime = hours + ':' + minutes + ' ' + ampm; + return strTime; + } + + + return ( +
+
+
+ {/* */} +
+
+
+

CMP-Event

+ + {/*
+
    +
  1. + CMD-App +
  2. +
  3. CMD-Category
  4. +
+
*/} +
+
+
+ {/* */} + +
+
+
+
+
+ +
+
+
NameCategoryemailphoneBuilding_NameStreet_NamecitydescriptionStatusGoogle LocationLinkedinUrlFacebookUrlintagramUrl
Name{bisuness?.name}
Bisuness image + +
Category{bisuness?.category}
email {bisuness?.email}
phone {bisuness?.phone}
Building_Name{bisuness?.Building_Name}
Street_Name{bisuness?.Street_Name}
city {bisuness?.city}
description {bisuness?.description}
Status + + {bisuness?.status ? "Live" : "Suspended"} + +
Google Location{bisuness?.Glocation}
LinkedinUrl {bisuness?.LinkedinUrl}
FacebookUrl{bisuness?.FacebookUrl}
intagramUrl {bisuness?.InstagramUrl}
{bisuness?.name} {bisuness?.category}{bisuness?.email}{bisuness?.phone}{bisuness?.Building_Name}{bisuness?.Street_Name}{bisuness?.city}{bisuness?.description} - - {bisuness?.status ? "Live" : "Suspended"} - - {bisuness?.Glocation}{bisuness?.LinkedinUrl}{bisuness?.FacebookUrl}{bisuness?.InstagramUrl} - -
+ + + + + + + + + + + {event && event.map((item, index) => + + + + + + + + + + )} + +
TitleImageLocationAdded OnAction
{item?.title} + {item?.location} + {/* {item?.addedOn} */} + {new Date(`${item?.addedOn}`).toDateString()} , {`${formatAMPM(item?.addedOn)}`} + + + + + + + + + + + +
+
+ + + {/* */} +
+
+
+
+
+ {/* */} +
+ + ); +} + +export default Event; diff --git a/src/views/Events/ViewEvent.js b/src/views/Events/ViewEvent.js new file mode 100644 index 0000000..4f89caa --- /dev/null +++ b/src/views/Events/ViewEvent.js @@ -0,0 +1,122 @@ + +import axios from "axios"; +import React, { useEffect, useState, useCallback, useMemo } from "react"; +import swal from 'sweetalert'; +// import { API } from "../../data"; +import { Link, useParams } from "react-router-dom"; +import { isAutheticated } from "../../auth"; + +function ViewEvent() { + const [event, setEvent] = useState([]) + const { id } = useParams(); + console.log(id) + const token = isAutheticated(); + + const getEvent = useCallback(async () => { + let res = await axios.get( + `/api/event/getOne/${id}`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + // console.log(res.data.Event) + setEvent(res.data.Event) + + + }, [token]); + + useEffect(() => { + getEvent(); + }, [getEvent]); + + + + + + //change time formate + function formatAMPM(date) { + var hours = new Date(date).getHours(); + var minutes = new Date(date).getMinutes(); + var ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? '0' + minutes : minutes; + var strTime = hours + ':' + minutes + ' ' + ampm; + return strTime; + } + + + return ( +
+
+
+ {/* */} +
+
+
+

CMP-Event

+ + {/*
+
    +
  1. + CMD-App +
  2. +
  3. CMD-Category
  4. +
+
*/} +
+
+
+ {/* */} + +
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
Id {event?._id}
Title {event?.title}
Image + +
Description{event?.description}
Location{event?.location}
Added On + {new Date(`${event?.addedOn}`).toDateString()} , {`${formatAMPM(event?.addedOn)}`} +
Updated At + {new Date(`${event?.updatedAt}`).toDateString()} , {`${formatAMPM(event?.updatedAt)}`} +
+
+ + + {/* */} +
+
+
+
+
+ {/* */} +
+
+ ); +} + +export default ViewEvent; diff --git a/src/views/Feedback/Pagination.js b/src/views/Feedback/Pagination.js new file mode 100644 index 0000000..92a8292 --- /dev/null +++ b/src/views/Feedback/Pagination.js @@ -0,0 +1,25 @@ +import React from 'react'; +import { Link } from "react-router-dom"; +const Pagination = ({ postsPerPage, totalPosts, paginate }) => { + const pageNumbers = []; + + for (let i = 1; i <= Math.ceil(totalPosts / postsPerPage); i++) { + pageNumbers.push(i); + } + + return ( + + ); +}; + +export default Pagination; \ No newline at end of file diff --git a/src/views/Feedback/ViewFeedback.js b/src/views/Feedback/ViewFeedback.js new file mode 100644 index 0000000..7cd90bd --- /dev/null +++ b/src/views/Feedback/ViewFeedback.js @@ -0,0 +1,123 @@ + +import axios from "axios"; +import React, { useEffect, useState, useCallback, useMemo } from "react"; +import swal from 'sweetalert'; +// import { API } from "../../data"; +import { Link, useParams } from "react-router-dom"; +import { isAutheticated } from "../../auth"; + +function ViewFeedback() { + const [user, setUser] = useState([]) + + + const [feedback, setFeedback] = useState([]) + const { id } = useParams(); + // console.log(id) + const token = isAutheticated(); + + const getFeedback = useCallback(async () => { + let res = await axios.get( + `/api/feedback/getOne/${id}`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + setFeedback(res.data.feedback) + + let resp = await axios.get( + `/api/v1/admin/user/${feedback.user}`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + setUser(resp.data.user) + + + }, [token, feedback.user]); + + useEffect(() => { + getFeedback(); + }, [getFeedback]); + + + + + + //change time formate + function formatAMPM(date) { + var hours = new Date(date).getHours(); + var minutes = new Date(date).getMinutes(); + var ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? '0' + minutes : minutes; + var strTime = hours + ':' + minutes + ' ' + ampm; + return strTime; + } + + + return ( +
+
+
+ {/* */} +
+
+
+

CMP-Customer feedback

+
+
+
+ {/* */} + +
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
User_Id{user?._id}
Name{feedback?.name}
email{user?.email}
Image + +
Description{feedback?.description}
Pnone No.{user?.phone}
Feedback Given At + {new Date(`${feedback?.createdAt}`).toDateString()} , {`${formatAMPM(feedback?.createdAt)}`} +
+
+ + + {/* */} +
+
+
+
+
+ {/* */} +
+
+ ); +} + +export default ViewFeedback; diff --git a/src/views/Feedback/feedback.js b/src/views/Feedback/feedback.js new file mode 100644 index 0000000..9f305df --- /dev/null +++ b/src/views/Feedback/feedback.js @@ -0,0 +1,146 @@ + +import axios from "axios"; +import React, { useEffect, useState, useCallback, useMemo } from "react"; +import Pagination from "./Pagination"; +import { Link } from "react-router-dom"; +import swal from 'sweetalert'; +// import { API } from "../../data"; +import { isAutheticated } from "../../auth"; + +function feedback() { + const [feedback, setFeedback] = useState([]) + + + const [currentPage, setCurrentPage] = useState(1); + const [postsPerPage] = useState(10); + const token = isAutheticated(); + + const getRestriction = useCallback(async () => { + let res = await axios.get( + `/api/feedback/getAll`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + // console.log(res.data.feedback) + setFeedback(res.data.feedback) + + + }, [token]); + + useEffect(() => { + getRestriction(); + }, [getRestriction]); + + + // console.log(cmsRes) + + // Get current posts + //pagination + const indexOfLastPost = currentPage * postsPerPage; + const indexOfFirstPost = indexOfLastPost - postsPerPage; + const currentPosts = feedback.slice(indexOfFirstPost, indexOfLastPost); + + // Change page + const paginate = pageNumber => setCurrentPage(pageNumber); + + //change time formate + function formatAMPM(date) { + var hours = new Date(date).getHours(); + var minutes = new Date(date).getMinutes(); + var ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? '0' + minutes : minutes; + var strTime = hours + ':' + minutes + ' ' + ampm; + return strTime; + } + + + + return ( + <> +
+
+
+ {/* */} +
+
+
+

CMP-Feedback

+ +
+
+
+ {/* */} + +
+
+
+
+
+ +
+
+ + + + + + + + + + + + {currentPosts && currentPosts.map((item, index) => + + + + + + + + + + + + )} + +
NameDescriptionGiven AtAction
{item?.name}{item?.description} + + {new Date(`${item?.createdAt}`).toDateString()} , {`${formatAMPM(item?.createdAt)}`} + + + + + + + + +
+
+ {/* */} +
+
+
+
+
+ {/* */} +
+
+ + + ); +} + +export default feedback; diff --git a/src/views/News/EditNews.js b/src/views/News/EditNews.js index a494cd4..9379dd0 100644 --- a/src/views/News/EditNews.js +++ b/src/views/News/EditNews.js @@ -39,7 +39,6 @@ const EditNews = () => { // Authorization: `Bearer ${token}`, // }, }); - // console.log(res.data.news.title) setTitle(res.data.news.title) setDescription(res.data.news.description) diff --git a/src/views/News/News.js b/src/views/News/News.js index 1fcaf72..d0553cb 100644 --- a/src/views/News/News.js +++ b/src/views/News/News.js @@ -119,7 +119,7 @@ function News() { @@ -128,7 +128,7 @@ function News() { @@ -136,7 +136,7 @@ function News() { + + + + + + + + + + + + + ) +} + +export default AddOffer \ No newline at end of file diff --git a/src/views/Offers/EditOffer.js b/src/views/Offers/EditOffer.js new file mode 100644 index 0000000..3a74d85 --- /dev/null +++ b/src/views/Offers/EditOffer.js @@ -0,0 +1,224 @@ + +import axios from "axios"; +import React, { useCallback, useEffect, useState } from "react"; +import { API } from "../../data"; +import { isAutheticated } from "../../auth"; +import ClipLoader from "react-spinners/ClipLoader"; +import { useHistory } from "react-router-dom"; +import swal from 'sweetalert'; +import { Link, useParams } from "react-router-dom"; +import { + CButton, + CCard, + CCardBody, + CCol, + CContainer, + CForm, + CFormInput, + CInputGroup, + CInputGroupText, + CRow, +} from '@coreui/react' +import CIcon from '@coreui/icons-react' +import { cilPencil, cilSettings, cilLockLocked, cilUser, cilBell, cilLocationPin, cilAudioDescription } from '@coreui/icons' +const EditOffer = () => { + const { id } = useParams(); + const token = isAutheticated(); + // console.log(token) + let history = useHistory(); + const [image, setImage] = useState(""); + const [title, setTitle] = useState(""); + const [bisunessName, setBisunessName] = useState([]); + const [sendBisunessName, setSendBisunessName] = useState(''); + + const [description, setDescription] = useState(""); + const [location, setLocation] = useState(""); + + const [loading, setLoading] = useState(false); + + + //fetch one Offer + useEffect(async () => { + const res = await axios.get(`/api/offer/getOne/${id}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + // console.log(res.data) + setTitle(res.data.offer.title) + setDescription(res.data.offer.description) + setLocation(res.data.offer.location) + setSendBisunessName(res.data.offer.bisunessName) + + }, [id]); + const fetchBusuness = useCallback(async () => { + const res = await axios.get(`/api/directory/getAll`, { + // headers: { + // Authorization: `Bearer ${token}`, + // }, + }); + + // console.log(res.data.directory); + setBisunessName(res.data.directory) + + }, [token]); + + useEffect(async () => { + fetchBusuness(); + + }, [fetchBusuness]); + + + + const handleSubmit = async () => { + const myForm = new FormData(); + + myForm.set("title", title); + myForm.set("description", description); + myForm.set("bisunessName", sendBisunessName); + myForm.set("location", location); + myForm.set("image", image); + setLoading({ loading: true }); + // console.log(image) + let res = await axios.put( + `/api/offer/update/${id}`, myForm, + { + headers: { + "Content-Type": 'multipart/form-data', + Authorization: `Bearer ${token}`, + }, + } + ); + // console.log(res.data) + if (res.data) { + swal("success!", "Event Added Successfully!", "success"); + history.goBack(); + } + + setLoading(false); + }; + const handleImage = (e) => { + const files = e.target.files[0]; + // console.log(files) + setImage(files); + + }; + // + const onCancel = () => { + // window.location = "/comproducts"; + history.goBack() + + }; + // console.log(bisunessName) + return ( + <> +
+ + + + + + +

Edit Offer

+
+
+ + + + + setTitle(e.target.value)} + value={title} + placeholder="Title" /> + + + + + + + setDescription(e.target.value)} + value={description} + placeholder="Description" /> + + + + + + + + + + + + + setLocation(e.target.value)} + value={location} + placeholder="Location" /> + + + + + {/* */} + + + +
+ +
+ + +
+
+
+
+
+
+
+
+
+ + + ) +} + +export default EditOffer \ No newline at end of file diff --git a/src/views/Offers/Offer.js b/src/views/Offers/Offer.js new file mode 100644 index 0000000..a85902d --- /dev/null +++ b/src/views/Offers/Offer.js @@ -0,0 +1,162 @@ + +import axios from "axios"; +import React, { useEffect, useState, useCallback, useMemo } from "react"; +import { Link } from "react-router-dom"; +import swal from 'sweetalert'; +// import { API } from "../../data"; +import { isAutheticated } from "../../auth"; + +function Offer() { + const [offer, setOffer] = useState([]) + + const token = isAutheticated(); + + 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]); + + useEffect(() => { + getOffer(); + }, [getOffer]); + + + const handleDelete = async (id) => { + let status = window.confirm("Do you want to delete"); + if (!status) return; + + let res = await axios.delete(`/api/offer/delete/${id}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + console.log(res) + if (res.data.success == true) { + swal("success!", "Offer Deleted Successfully!", "success"); + window.location.reload(); + } + }; + + + //change time formate + function formatAMPM(date) { + var hours = new Date(date).getHours(); + var minutes = new Date(date).getMinutes(); + var ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? '0' + minutes : minutes; + var strTime = hours + ':' + minutes + ' ' + ampm; + return strTime; + } + + + return ( +
+
+
+ {/* */} +
+
+
+

CMP-Offers

+ + +
+
+
+ {/* */} + +
+
+
+
+
+ +
+
+ + + + + + + + + + + + + {offer && offer.map((item, index) => + + + + + + + + + + + + )} + +
TitleImageBusiness NameLocationAdded OnAction
{item?.title} + {item?.bisunessName}{item?.location} + {/* {item?.addedOn} */} + {new Date(`${item?.addedOn}`).toDateString()} , {`${formatAMPM(item?.addedOn)}`} + + + + + + + + + + + +
+
+ + + {/* */} +
+
+
+
+
+ {/* */} +
+
+ ); +} + +export default Offer; diff --git a/src/views/Offers/ViewOffer.js b/src/views/Offers/ViewOffer.js new file mode 100644 index 0000000..c57f42b --- /dev/null +++ b/src/views/Offers/ViewOffer.js @@ -0,0 +1,137 @@ + +import axios from "axios"; +import React, { useEffect, useState, useCallback, useMemo } from "react"; +import swal from 'sweetalert'; +// import { API } from "../../data"; +import { Link, useParams } from "react-router-dom"; +import { isAutheticated } from "../../auth"; + +function ViewOffer() { + const [offer, setOffer] = useState([]) + const { id } = useParams(); + console.log(id) + const token = isAutheticated(); + + const getOffer = useCallback(async () => { + let res = await axios.get( + `/api/offer/getOne/${id}`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + + setOffer(res.data.offer) + + + }, [token]); + + useEffect(() => { + getOffer(); + }, [getOffer]); + + + + + + //change time formate + function formatAMPM(date) { + var hours = new Date(date).getHours(); + var minutes = new Date(date).getMinutes(); + var ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? '0' + minutes : minutes; + var strTime = hours + ':' + minutes + ' ' + ampm; + return strTime; + } + + + return ( +
+
+
+ {/* */} +
+
+
+

CMP-Offers

+ + {/*
+
    +
  1. + CMD-App +
  2. +
  3. CMD-Category
  4. +
+
*/} +
+
+
+ {/* */} + +
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Id{offer?._id}
Title{offer?.title}
Image + +
Bisuness Name {offer?.bisunessName}
Description{offer?.description}
Location{offer?.location}
Added On + {new Date(`${offer?.addedOn}`).toDateString()} , {`${formatAMPM(offer?.addedOn)}`} +
Updated At + {new Date(`${offer?.updatedAt}`).toDateString()} , {`${formatAMPM(offer?.updatedAt)}`} +
+
+ + + {/* */} +
+
+
+
+
+ {/* */} +
+
+ ); +} + +export default ViewOffer; diff --git a/src/views/Users/Pagination.js b/src/views/Users/Pagination.js new file mode 100644 index 0000000..55b2c76 --- /dev/null +++ b/src/views/Users/Pagination.js @@ -0,0 +1,25 @@ +import React from 'react'; +import { Link } from "react-router-dom"; +const Pagination = ({ userPerPage, totalUsers, paginate }) => { + const pageNumbers = []; + + for (let i = 1; i <= Math.ceil(totalUsers / userPerPage); i++) { + pageNumbers.push(i); + } + + return ( + + ); +}; + +export default Pagination; \ No newline at end of file diff --git a/src/views/Users/ViewUsers.js b/src/views/Users/ViewUsers.js new file mode 100644 index 0000000..7fd6ba8 --- /dev/null +++ b/src/views/Users/ViewUsers.js @@ -0,0 +1,131 @@ + +import axios from "axios"; +import React, { useEffect, useState, useCallback, useMemo } from "react"; +import swal from 'sweetalert'; +// import { API } from "../../data"; +import { Link, useParams } from "react-router-dom"; +import { isAutheticated } from "../../auth"; + +function ViewUsers() { + const [user, setUser] = useState([]) + const { id } = useParams(); + // console.log(id) + const token = isAutheticated(); + + const getUserDetails = useCallback(async () => { + + + let resp = await axios.get( + `/api/v1/admin/user/${id}`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + setUser(resp.data.user) + + + }, [token]); + + useEffect(() => { + getUserDetails(); + }, [getUserDetails]); + + + + + + //change time formate + function formatAMPM(date) { + var hours = new Date(date).getHours(); + var minutes = new Date(date).getMinutes(); + var ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? '0' + minutes : minutes; + var strTime = hours + ':' + minutes + ' ' + ampm; + return strTime; + } + + + return ( +
+
+
+ {/* */} +
+
+
+

CMP-User Details

+
+
+
+ {/* */} + +
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + {/* */} + + + + + + + + + + + + + + +
User_Id{user?._id}
Name{user?.name}
email{user?.email}
Image + +
Description
Pnone No.{user?.phone}
Role{user?.role}
Register At + {new Date(`${user?.createdAt}`).toDateString()} , {`${formatAMPM(user?.createdAt)}`} +
Profile Updated At + {new Date(`${user?.updatedAt}`).toDateString()} , {`${formatAMPM(user?.updatedAt)}`} +
+
+ + + {/* */} +
+
+
+
+
+ {/* */} +
+
+ ); +} + +export default ViewUsers; + diff --git a/src/views/Users/users.js b/src/views/Users/users.js new file mode 100644 index 0000000..57c1bd9 --- /dev/null +++ b/src/views/Users/users.js @@ -0,0 +1,153 @@ + +import axios from "axios"; +import React, { useEffect, useState, useCallback, useMemo } from "react"; +import Pagination from "./Pagination"; +import { Link } from "react-router-dom"; +import swal from 'sweetalert'; +// import { API } from "../../data"; +import { isAutheticated } from "../../auth"; + +function users() { + const [users, setUsers] = useState([]) + + + const [currentPage, setCurrentPage] = useState(1); + const [userPerPage] = useState(10); + 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]); + + useEffect(() => { + getAllUsers(); + }, [getAllUsers]); + + + // console.log(cmsRes) + + // Get current posts + //pagination + const indexOfLastUser = currentPage * userPerPage; + const indexOfFirstUser = indexOfLastUser - userPerPage; + const currentUser = users.slice(indexOfFirstUser, indexOfLastUser); + + // Change page + const paginate = pageNumber => setCurrentPage(pageNumber); + + //change time formate + function formatAMPM(date) { + var hours = new Date(date).getHours(); + var minutes = new Date(date).getMinutes(); + var ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? '0' + minutes : minutes; + var strTime = hours + ':' + minutes + ' ' + ampm; + return strTime; + } + + + + return ( + <> +
+
+
+ {/* */} +
+
+
+

CMP - All Users

+ +
+
+
+ {/* */} + +
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + {currentUser && currentUser.map((item, index) => + + + + + + + + + + + + + + + )} + +
NameemailProfile ImagePhone No.Register AtAction
{item?.name}{item?.email} + + {item?.phone} + + {new Date(`${item?.createdAt}`).toDateString()} , {`${formatAMPM(item?.createdAt)}`} + + + + + + + + +
+
+ {/* */} +
+
+
+
+
+ {/* */} +
+
+ + + ); +} + +export default users; diff --git a/src/views/pages/login/Login.js b/src/views/pages/login/Login.js index ca5ddaf..1973ebd 100644 --- a/src/views/pages/login/Login.js +++ b/src/views/pages/login/Login.js @@ -15,11 +15,13 @@ import { } from '@coreui/react' import CIcon from '@coreui/icons-react' import { cilLockLocked, cilUser } from '@coreui/icons' +import ClipLoader from "react-spinners/ClipLoader"; import { useState } from 'react' import axios from 'axios' import { useHistory } from 'react-router-dom' const Login = () => { + const [loading, setLoading] = useState(false); const [auth, setAuth] = useState({ email: "", password: "" @@ -31,24 +33,19 @@ const Login = () => { }; const Login = async () => { - const res = await axios.post("/api/user/login/", auth); + setLoading({ loading: true }) + const res = await axios.post("/api/v1/user/login/", auth); if (res.data.success == true) { localStorage.setItem("authToken", res.data.token) - console.log(res.data) - localStorage.setItem("auth", JSON.stringify({ - user: res.data.user, - token: res.data.token, - - - })); history.push('/dashboard') + setLoading(false); + window.location.reload() + } else { - if (res.data.status === "blocked") - alert(res.data.message) - else - alert("Invalid Credentials"); + alert("Invalid Credentials"); + setLoading(false); } } return ( @@ -82,7 +79,9 @@ const Login = () => { - Login + + {!loading && "Login"} + diff --git a/src/views/pages/register/Change_password.js b/src/views/pages/register/Change_password.js index a386109..d505333 100644 --- a/src/views/pages/register/Change_password.js +++ b/src/views/pages/register/Change_password.js @@ -13,6 +13,7 @@ import { } from '@coreui/react' import CIcon from '@coreui/icons-react' import { cilLockLocked, cilUser } from '@coreui/icons' +import ClipLoader from "react-spinners/ClipLoader"; import axios from 'axios' import { isAutheticated } from 'src/auth' import Swal from 'sweetalert2' @@ -22,15 +23,16 @@ const Register = () => { const [oldPassword, setOldPassword] = useState(); const [newPassword, setNewPassword] = useState(); const [confirmPassword, setConfirmPassword] = useState(); + const [loading, setLoading] = useState(false); const history = useHistory(); const handleSubmit = async () => { const token = localStorage.getItem("authToken") - //console.log(token) + setLoading({ loading: true }) if (newPassword == confirmPassword) { - let res = await axios.put('/api/user/update/password', + let res = await axios.put('/api/v1/user/password/update', { oldPassword , newPassword, @@ -40,8 +42,9 @@ const Register = () => { Authorization: `Bearer ${token}`, } }) - console.log(res) - if (res) { + + // console.log(res.data.success) + if (res.data.success == true) { Swal.fire({ title: 'Done', text: 'Password Changed', @@ -52,10 +55,12 @@ const Register = () => { }).then(() => { history.push('/dashboard') }); - } + } + setLoading(false); } else { alert('new password and confirm password are not matched') + setLoading(false); } } @@ -98,7 +103,10 @@ const Register = () => { />
- Submit + + + {!loading && "Submit"} +