diff --git a/package.json b/package.json index 2f909ca..d4d6b74 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@reduxjs/toolkit": "^1.9.2", "axios": "^0.25.0", "bootstrap": "^5.1.3", - "country-state-city": "^3.1.2", + "country-state-city": "^3.2.1", "md5": "^2.3.0", "prop-types": "^15.7.2", "quill": "^1.3.7", @@ -66,7 +66,8 @@ "simplebar-react": "^2.3.6", "styled-components": "^6.0.8", "sweetalert": "^2.1.2", - "sweetalert2": "^11.4.0" + "sweetalert2": "^11.4.0", + "uuid": "^9.0.1" }, "devDependencies": { "auto-changelog": "~2.3.0", diff --git a/src/App.js b/src/App.js index 705bff4..9ac68a8 100644 --- a/src/App.js +++ b/src/App.js @@ -1,33 +1,35 @@ -import React, { Component, Suspense } from 'react' -import axios from 'axios'; -import { Router, Route, Routes, HashRouter } from 'react-router-dom' -import { useState, useEffect } from 'react'; +import React, { Component, Suspense } from "react"; +import axios from "axios"; +import { Router, Route, Routes, HashRouter } from "react-router-dom"; +import { useState, useEffect } from "react"; import { Toaster } from "react-hot-toast"; -import './scss/style.scss' -import ForgotPassword from './views/pages/register/ForgotPassword' -import NewRegister from './views/pages/register/NewRegister' -import ProtectedRoute from './components/ProtectedRoute'; -import { isAutheticated } from './auth'; - +import "./scss/style.scss"; +import ForgotPassword from "./views/pages/register/ForgotPassword"; +import NewRegister from "./views/pages/register/NewRegister"; +// import ProtectedRoute from './components/ProtectedRoute'; +import { isAutheticated } from "./auth"; const loading = (
-) +); // import EditProducts from './views/Commerce/Editproducts' // Containers -const DefaultLayout = React.lazy(() => import('./layout/DefaultLayout')) +const DefaultLayout = React.lazy(() => import("./layout/DefaultLayout")); // Pages -const Login = React.lazy(() => import('./views/pages/login/Login')) -const Register = React.lazy(() => import('./views/pages/register/Change_password')) -const Page404 = React.lazy(() => import('./views/pages/register/page404/Page404')) -const Page500 = React.lazy(() => import('./views/pages/page500/Page500')) +const Login = React.lazy(() => import("./views/pages/login/Login")); +const Register = React.lazy(() => + import("./views/pages/register/Change_password") +); +const Page404 = React.lazy(() => + import("./views/pages/register/page404/Page404") +); +const Page500 = React.lazy(() => import("./views/pages/page500/Page500")); const App = () => { - - const [userdata, setUserData] = useState(null) + const [userdata, setUserData] = useState(null); const token = isAutheticated(); useEffect(() => { @@ -35,7 +37,7 @@ const App = () => { let existanceData = localStorage.getItem("authToken"); if (!existanceData) { // console.log(existanceData.userData) - setUserData(false) + setUserData(false); } else { try { // console.log('requesting user data from server') @@ -43,50 +45,62 @@ const App = () => { headers: { Authorization: `Bearer ${token}`, }, - }) + }); // console.log(response.data) - const data = response.data - if (data.success && data.user.role === 'admin') { - + const data = response.data; + if (data.success && data.user.role === "admin") { setUserData(data.user); } else { - setUserData(false) + setUserData(false); } - - } - catch (err) { - setUserData(false) + } catch (err) { + setUserData(false); console.log(err); - }; + } } - - } - getUser() - }, []) + }; + getUser(); + }, []); return ( - } /> - } /> - } /> + } + /> + } + /> } /> } /> - - : - userdata === false ? :
} /> - + + ) : userdata === false ? ( + + ) : ( +
+ ) + } + /> } />
-
- - ) -} -export default App + ); +}; +export default App; diff --git a/src/_nav.js b/src/_nav.js index 55acafa..bc0958f 100644 --- a/src/_nav.js +++ b/src/_nav.js @@ -33,7 +33,7 @@ const _nav = [ component: CNavItem, name: "Users", icon: , - to: "/users", + to: "/users-address", }, { component: CNavItem, diff --git a/src/routes.js b/src/routes.js index 1f9d7e0..e27b4ab 100644 --- a/src/routes.js +++ b/src/routes.js @@ -27,9 +27,7 @@ import Login from "./views/pages/login/Login"; import Appointments from "./views/Appointments/Appointments"; //Businesses -import Businesses from "./views/Business/Businesses.js"; -import AddBusiness from "./views/Business/AddBusiness.js"; -import EditBusiness from "./views/Business/EditBusiness.js"; + import Products from "./views/Products/Products"; //product import AddProduct from "./views/Products/AddProduct"; @@ -79,7 +77,7 @@ import EditPurpose from "./views/configuration/Purpose/EditPurpose.js"; import ViewAppointment from "./views/Appointments/ViewAppointment"; import EditAppointment from "./views/Appointments/EditAppointment"; import AddNewAppointment from "./views/Appointments/AddNewAppointment"; -import ViewHealthCareProvider from "./views/Business/ViewHealthCareProvider"; + import Campaign from "./views/Campaigns/Campaign.js"; import AddCampaign from "./views/Campaigns/AddCampaign.js"; import Categories from "./views/Categories/categories"; @@ -88,6 +86,11 @@ import Content from "./views/Content/content"; import EditPrivacyPolicy from "./views/Content/editPrivacyPolicy"; import EditTermsConditions from "./views/Content/editTermsConditions"; import EditShippingPolicy from "./views/Content/editShippingPolicy"; + +import UserTable from "./views/UserAddress/userTable"; +import EditUserAddress from "./views/UserAddress/editUserAddress"; +import AddUserAddress from "./views/UserAddress/addUserAddress"; +import ViewAddress from "./views/UserAddress/viewAddress"; const routes = [ { path: "/", exact: true, name: "Home" }, { @@ -127,27 +130,48 @@ const routes = [ element: AddNewAppointment, }, + { + path: "/users-address", + name: "User Table", + element: UserTable, + }, + { + path: "/users-address/add", + name: "User Address", + element: AddUserAddress, + }, + { + path: "/users-address/edit/:id", + name: "Edit user address", + element: EditUserAddress, + }, + { + path: "/users-address/view/:id", + name: "view address", + element: ViewAddress, + }, + // health care providers - { - path: "//users", - name: "healthcare providers", - element: Businesses, - }, - { - path: "//users/add", - name: "Add healthcare providers", - element: AddBusiness, - }, - { - path: "/users/edit/:id", - name: "Edit healthcare providers", - element: EditBusiness, - }, - { - path: "/users/view/:id", - name: "view healthcare providers", - element: ViewHealthCareProvider, - }, + // { + // path: "//users", + // name: "healthcare providers", + // element: Businesses, + // }, + // { + // path: "//users/add", + // name: "Add healthcare providers", + // element: AddBusiness, + // }, + // { + // path: "/users/edit/:id", + // name: "Edit healthcare providers", + // element: EditBusiness, + // }, + // { + // path: "/users/view/:id", + // name: "view healthcare providers", + // element: ViewHealthCareProvider, + // }, // Categories { path: "//categories", @@ -164,16 +188,16 @@ const routes = [ name: "Add Campaigns", element: AddCampaign, }, - { - path: "/campaigns/edit/:id", - name: "Edit healthcare providers", - element: EditBusiness, - }, - { - path: "/campaigns/view/:id", - name: "view healthcare providers", - element: ViewHealthCareProvider, - }, + // { + // path: "/campaigns/edit/:id", + // name: "Edit healthcare providers", + // element: EditBusiness, + // }, + // { + // path: "/campaigns/view/:id", + // name: "view healthcare providers", + // element: ViewHealthCareProvider, + // }, // { path: '/franchisee/view/:id', name: 'view franchisee', element: ViewFra }, //Contact Requests diff --git a/src/views/Business/AddBusiness.js b/src/views/Business/AddBusiness.js deleted file mode 100644 index a5a0510..0000000 --- a/src/views/Business/AddBusiness.js +++ /dev/null @@ -1,339 +0,0 @@ -import React, { useState, useEffect } from "react"; -// import { Button } from '@mui/material' -import axios from "axios"; - -import { Link, useNavigate } from "react-router-dom"; -import { - CCard, - CCardBody, - CCardGroup, - CCol, - CContainer, - CRow, -} from "@coreui/react"; -import SelectPurpose from "./multiform/SelectPurpose.js"; -import SelectBusiness from "./multiform/SelectBusiness.js"; -import SelectLanguage from "./multiform/selectLanguage.js"; -import Contacts from "./multiform/Contacts.js"; -import BAddress from "./multiform/BAddress.js"; -import Button from "@material-ui/core/Button"; - -import { isAutheticated } from "src/auth"; -import DoctorInfo from "./multiform/DoctorInfo.js"; - -const AddBusiness = () => { - const token = isAutheticated(); - const [productId, setProductId] = useState(""); - const [viewState, setViewState] = useState(1); - // const [WebsiteURL, setWebsiteURL] = useState('https://bolo.ai.in/') - - const navigate = useNavigate(); - const [loading, setLoading] = useState(false); - - const [data, setData] = useState({ - WebsiteURL: "https://bolo.ai.in/", - userType: "", - purpose: "", - - language: [], - country: "", - state: "", - city: "", - address_Line_1: "", - address_Line_2: "", - pincode: "", - //contacts - image: "", - imageURL: "", - userName: "", - email: "", - - short_url: "", - contact_Number: "", - contact_Person_Name: "", - - specialization: "", - }); - - // console.log(data) - - const handleView = (n) => { - if (viewState === n) return; - setViewState(n); - }; - const handleSubmit = () => { - if ( - data.address_Line_1.trim() === "" || - data.address_Line_2.trim() === "" || - data.userType === "" || - data.language === "" || - data.country === "" || - data.state === "" || - data.city === "" || - data.pincode.trim() === "" || - //Contacts - // data.image === '' || - // data.imageURL.trim() === '' || - (data.userName.trim() === "" - // && - // (data.contact_Person_Name.trim() === "" || - // data.specialization === "") - ) || - data.email.trim() === "" || - // data.short_url.trim() === "" || - data.contact_Number === "" - // || data.contact_Person_Name.trim() === "" - ) { - swal({ - title: "Warning", - text: "Fill all mandatory fields", - icon: "error", - button: "Close", - dangerMode: true, - }); - return; - } - setLoading(true); - const formData = new FormData(); - formData.set("address_Line_1", data.address_Line_1); - formData.set("address_Line_2", data.address_Line_2); - - formData.set("purpose", data.purpose); - formData.set("userType", data.userType); - // formData.set("language", data.language); - - formData.set("country", data.country); - formData.set("city", data.city); - formData.set("state", data.state); - - formData.set("pincode", data.pincode); - //contacts - formData.set("userName", data.userName); - formData.set("email", data.email); - - formData.set("contact_Number", data.contact_Number); - formData.set("contact_Person_Name", data.contact_Person_Name); - - formData.set("specialization", data.specialization); - - formData.set("url", data.WebsiteURL); - formData.set("short_url", data.short_url); - - axios - .post(`/api/businesses/add`, formData, { - headers: { - Authorization: `Bearer ${token}`, - "Content-Type": "multipart/formdata", - "Access-Control-Allow-Origin": "*", - }, - }) - .then((res) => { - swal({ - title: "Added", - text: res?.data?.message - ? res?.data?.message - : "Business added successfully!", - icon: "success", - button: "Return", - }); - setLoading(false); - navigate("/users", { replace: true }); - }) - .catch((err) => { - setLoading(false); - const message = err.response?.data?.message || "Something went wrong!"; - swal({ - title: "Warning", - text: message, - icon: "error", - button: "Retry", - dangerMode: true, - }); - }); - }; - console.log(data); - - return ( - - - -
-
- Add User -
-
-
- -
-
-
-
-
- - - - - - {viewState === 1 && ( - - )} - {viewState === 2 && ( - - )} - - {viewState === 3 && - (data.business === "Doctor (Individual Practitioner)" ? ( - - ) : ( - - ))} - - {/* {viewState === 4 && ( - - )} */} - {viewState === 4 && ( - - )} - - - - - - - - -
- - {/**/} - - -
-
-
-
-
-
-
- ); -}; - -export default AddBusiness; diff --git a/src/views/Business/EditBusiness.js b/src/views/Business/EditBusiness.js deleted file mode 100644 index 3a07a0b..0000000 --- a/src/views/Business/EditBusiness.js +++ /dev/null @@ -1,367 +0,0 @@ -import React, { useState, useEffect } from "react"; -// import { Button } from '@mui/material' -import axios from "axios"; - -import { Link, useNavigate, useParams } from "react-router-dom"; -import { - CCard, - CCardBody, - CCardGroup, - CCol, - CContainer, - CRow, -} from "@coreui/react"; - -import SelectPurpose from "./multiform/SelectPurpose.js"; -import SelectBusiness from "./multiform/SelectBusiness.js"; -import SelectLanguage from "./multiform/selectLanguage.js"; -import BAddress from "./multiform/BAddress.js"; -import Button from "@material-ui/core/Button"; - -import { isAutheticated } from "src/auth"; -import Contacts from "./multiform/Contacts.js"; -import DoctorInfo from "./multiform/DoctorInfo.js"; - -const EditBusiness = () => { - const token = isAutheticated(); - const id = useParams()?.id; - const [productId, setProductId] = useState(""); - const [viewState, setViewState] = useState(1); - - const navigate = useNavigate(); - const [loading, setLoading] = useState(false); - - const [data, setData] = useState({ - WebsiteURL: "https://bolo.ai.in/", - business: "", - purpose: "", - - language: [], - country: "", - state: "", - city: "", - address_Line_1: "", - address_Line_2: "", - pincode: "", - //contacts - image: "", - imageURL: "", - business_name: "", - email: "", - - short_url: "", - contact_Number: "", - contact_Person_Name: "", - - specialization: "", - }); - - // console.log(data) - - const handleView = (n) => { - if (viewState === n) return; - setViewState(n); - }; - - //get business - // console.log(id) - const getbusinesses = () => { - axios - .get(`/api/businesses/get/${id}`, { - headers: { - "Access-Control-Allow-Origin": "*", - Authorization: `Bearer ${token}`, - }, - }) - .then((res) => { - // console.log(res.data.businesses) - // setBusinessesData(res.data?.businesses) - setData((prev) => ({ - ...prev, - ...res.data?.businesses, - })); - setLoading(false); - }) - - .catch((err) => { - console.log(err); - setLoading(false); - }); - }; - - useEffect(() => { - getbusinesses(); - }, []); - // console.log(data) - const handleSubmit = () => { - if ( - data.address_Line_1.trim() === "" || - data.address_Line_2.trim() === "" || - data.business === "" || - data.language === "" || - data.country === "" || - data.state === "" || - data.city === "" || - data.pincode === "" || - //Contacts - // data.image === '' || - // data.imageURL.trim() === '' || - (data.business_name.trim() === "" && - (data.contact_Person_Name.trim() === "" || - data.specialization === "")) || - data.email.trim() === "" || - data.short_url.trim() === "" || - data.contact_Number === "" || - data.contact_Person_Name.trim() === "" - ) { - swal({ - title: "Warning", - text: "Fill all mandatory fields", - icon: "error", - button: "Close", - dangerMode: true, - }); - return; - } - setLoading(true); - const formData = new FormData(); - formData.set("address_Line_1", data.address_Line_1); - formData.set("address_Line_2", data.address_Line_2); - - formData.set("business", data.business); - formData.set("language", data.language); - - formData.set("country", data.country); - formData.set("city", data.city); - formData.set("state", data.state); - - formData.set("pincode", data.pincode); - //contacts - formData.set("business_name", data.business_name); - formData.set("email", data.email); - - formData.set("contact_Number", data.contact_Number); - formData.set("contact_Person_Name", data.contact_Person_Name); - - formData.set("specialization", data.specialization); - - formData.set("url", data.WebsiteURL); - formData.set("short_url", data.short_url); - - axios - .patch(`/api/businesses/update/${id}`, formData, { - headers: { - Authorization: `Bearer ${token}`, - "Content-Type": "multipart/formdata", - "Access-Control-Allow-Origin": "*", - }, - }) - .then((res) => { - swal({ - title: "Updated", - text: res?.data?.message - ? res?.data?.message - : "Business added successfully!", - icon: "success", - button: "Return", - }); - setLoading(false); - navigate("/users", { replace: true }); - }) - .catch((err) => { - setLoading(false); - const message = err.response?.data?.message || "Something went wrong!"; - swal({ - title: "Warning", - text: message, - icon: "error", - button: "Retry", - dangerMode: true, - }); - }); - }; - - return ( - - - -
-
- Edit Healthcare Provider -
-
-
- -
-
-
-
-
- - - - - - {viewState === 1 && ( - - )} - - {/*viewState === 2 && ( - - )*/} - - {viewState === 3 && - (data.business === "Doctor (Individual Practitioner)" ? ( - - ) : ( - - ))} - - {viewState === 4 && ( - - )} - {viewState === 5 && ( - - )} - - - - - - - - -
- - - - - -
-
-
-
-
-
-
- ); -}; - -export default EditBusiness; diff --git a/src/views/Business/OverLayButton.js b/src/views/Business/OverLayButton.js deleted file mode 100644 index 2a49a68..0000000 --- a/src/views/Business/OverLayButton.js +++ /dev/null @@ -1,29 +0,0 @@ -import React, { useState, useRef } from 'react' -import Button from 'react-bootstrap/Button' -import Overlay from 'react-bootstrap/Overlay' -import Tooltip from 'react-bootstrap/Tooltip' - -function OverLayButton(props) { - const { url } = props?.data || '' - const [show, setShow] = useState(false) - const target = useRef(null) - - return ( - - - - {(props) => ( - - - {url} - - - )} - - - ) -} - -export default OverLayButton diff --git a/src/views/Business/ViewHealthCareProvider.js b/src/views/Business/ViewHealthCareProvider.js deleted file mode 100644 index d7448f8..0000000 --- a/src/views/Business/ViewHealthCareProvider.js +++ /dev/null @@ -1,146 +0,0 @@ -import axios from "axios"; -import React from "react"; -import { useState } from "react"; -import { useEffect } from "react"; -import { useNavigate, useParams } from "react-router-dom"; -import Button from "@material-ui/core/Button"; -import { isAutheticated } from "src/auth"; - -const ViewHealthCareProvider = () => { - const [HealthCareData, setHealthCareData] = useState(); - const token = isAutheticated(); - - const [loading, setLoading] = useState(false); - - const { id } = useParams(); - - const getHealthCareProvider = () => { - setLoading(true); - axios - .get(`/api/businesses/get/${id}`, { - headers: { - Authorization: `Bearer ${token}`, - }, - }) - - .then(async (res) => { - console.log(res.data); - setHealthCareData(res.data.businesses); - setLoading(false); - }) - .catch((err) => { - swal("Error", "Could not get data", "error"); - setLoading(false); - }); - }; - - useEffect(() => { - getHealthCareProvider(); - }, []); - - const navigate = useNavigate(); - - return ( -
-
-
-
- HealthCare Provider Details -
- -
- -
-
-
- - {loading &&
Loading...
} - {!loading && !HealthCareData &&
No data found
} - {!loading && HealthCareData && ( -
- - - - - - - - - - - - {HealthCareData?.business_name ? ( - - {" "} - - - - ) : ( - - - - - )} - - - - - - - - - - - - - - - - - - - - - - -
HealthCare Provider ID{HealthCareData?._id}
Provider Type{HealthCareData?.business}
HealthCare Name{HealthCareData?.business_name}
Specialization{HealthCareData?.specialization}
Contact Person Name{HealthCareData?.contact_Person_Name}
Phone{HealthCareData?.contact_Number}
Email{HealthCareData?.email}
Url - {HealthCareData?.url ? ( - HealthCareData?.url - ) : ( - Not Set - )} -
Address - {HealthCareData?.address_Line_1}
- {HealthCareData?.address_Line_2} -
- {HealthCareData?.city}, {HealthCareData?.state}
- {HealthCareData?.country}
- {HealthCareData?.pincode} -
-
- )} -
- ); -}; - -export default ViewHealthCareProvider; diff --git a/src/views/Business/multiform/BAddress.js b/src/views/Business/multiform/BAddress.js deleted file mode 100644 index f606ef9..0000000 --- a/src/views/Business/multiform/BAddress.js +++ /dev/null @@ -1,431 +0,0 @@ - -import React, { useEffect, useState } from 'react' -import Button from '@material-ui/core/Button' -import { Link, useNavigate } from 'react-router-dom' -import swal from 'sweetalert' -import axios from 'axios' -import { isAutheticated } from 'src/auth' -// import { WebsiteURL } from '../WebsiteURL' -import { Country, State, City } from 'country-state-city'; - - -const BAddress = (props) => { - const token = isAutheticated() - const navigate = useNavigate() - - const { data, setData } = props.data - - const { loading, setLoading } = props.loading - // const categories = props?.categories || [] - - const handleChange = (e) => { - // if (e.target.id === 'master_price' && /^\D+$/.test(e.target.value)) return - // if (e.target.id === 'discontinue_on') { - // if (new Date(e.target.value) < new Date()) { - // return setData((prev) => ({ - // ...prev, - // [e.target.id]: new Date().toISOString().slice(0, 10), - // })) - // } - // } - setData((prev) => ({ ...prev, [e.target.id]: e.target.value })) - } - - // const [data, setData] = useState({ - // image: '', - // imageURL: '', - // address_Line_1: '', - // address_Line_2: '', - // address_line_1: '', - // address_line_2: '', - // city: '', - // state_name: '', - // short_url: '', - // contact_Number: '', - // contact_Person_Name: '', - // price_Lable: '', - // pin_Code: '' - // }) - - // const [cities, setCities] = useState([]) - - // const [loading, setLoading] = useState(false) - const [validForm, setValidForm] = useState(false) - - - const [limiter, setLimiter] = useState({ - address_Line_1: 100, - nameHas: 100, - }) - - - - //country, city and state - const [countryCode, setCountryCode] = useState(); - - const [stateCode, setStateCode] = useState(); - const country = Country.getAllCountries() - - useEffect(() => { - - country.map(item => { - - - if (item.name === data.country) { - setCountryCode(item.isoCode) - // console.log(data.state) - } - }) - - }, [data.country]) - const state = State.getStatesOfCountry(countryCode) - useEffect(() => { - - state.map(item => { - - - if (item.name === data.state) { - setStateCode(item.isoCode) - // console.log(data.state) - } - }) - - }, [data.state]) - - - const handleSubmit = () => { - if ( - data.address_Line_1.trim() === '' || - data.address_Line_2.trim() === '' || - data.contact_Number === '' || - - data.contact_Person_Name === '' || - data.address_line_1.trim() === '' || - data.address_line_2.trim() === '' || - data.price_Lable.trim() === '' || - data.city === '' || - data.pin_Code.trim() === '' || - data.short_url === '' || - data.state_name === '' - // data.imageURL.trim() === '' - ) { - swal({ - title: 'Warning', - text: 'Fill all mandatory fields', - icon: 'error', - button: 'Close', - dangerMode: true, - }) - return - } - setLoading(true) - const formData = new FormData() - formData.set('address_Line_1', data.address_Line_1) - formData.set('address_Line_2', data.address_Line_2) - - formData.set('address_line_1', data.address_line_1) - formData.set('address_line_2', data.address_line_2) - formData.set('city', data.city) - formData.set('state_name', data.state_name) - formData.set('contact_Number', data.contact_Number) - formData.set('contact_Person_Name', data.contact_Person_Name) - - formData.set('price_Lable', data.price_Lable) - formData.set('pin_Code', data.pin_Code) - formData.set('url', WebsiteURL + data.short_url + '/login') - formData.set('short_url', data.short_url) - - formData.append('image', data.image) - axios - .post(`/api/franchisee/`, formData, { - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'multipart/formdata', - 'Access-Control-Allow-Origin': '*', - }, - }) - .then((res) => { - swal({ - title: 'Added', - text: res?.data?.message ? res?.data?.message : 'Franchisee added successfully!', - icon: 'success', - button: 'Return', - }) - setLoading(false) - navigate('/franchisees', { replace: true }) - }) - .catch((err) => { - setLoading(false) - const message = err.response?.data?.message || 'Something went wrong!' - swal({ - title: 'Warning', - text: message, - icon: 'error', - button: 'Retry', - dangerMode: true, - }) - }) - } - - return ( -
-
-
-
-
- Address -
-
-

-
- -
- {/* */} - - - -
-
-
-
- - - -
-
-
-
- - - - -
- - handleChange(e)} - /> -
-
- - handleChange(e)} - /> -
-
- - - -
-
- - -
-
- - -
- -
- - handleChange(e)} - /> - -
-
-
-
- {/*
-
-
- -
- - handleChange(e)} - /> -
-
- - handleChange(e)} - /> -
-
- -
- - {WebsiteURL} - - handleChange(e)} - /> -
-
- -
- -
- -
- - handleChange(e)} - /> -

Upload jpg, jpeg and png only*

-
-
- Uploaded Image will be shown here -
-
-
-
*/} -
-
- ) -} - -export default BAddress \ No newline at end of file diff --git a/src/views/Business/multiform/Contacts.js b/src/views/Business/multiform/Contacts.js deleted file mode 100644 index d7bbce0..0000000 --- a/src/views/Business/multiform/Contacts.js +++ /dev/null @@ -1,296 +0,0 @@ -import React, { useEffect, useState } from "react"; -import Button from "@material-ui/core/Button"; -import { Link, useNavigate } from "react-router-dom"; -import swal from "sweetalert"; -import axios from "axios"; -import { isAutheticated } from "src/auth"; -import toast from "react-hot-toast"; -// import { WebsiteURL } from '../WebsiteURL' - -const Contacts = (props) => { - const token = isAutheticated(); - - const navigate = useNavigate(); - - const { data, setData } = props.data; - - const { loading, setLoading } = props.loading; - // const [data, setData] = useState({ - // image: '', - // imageURL: '', - // name: '', - // email: '', - - // short_url: '', - // contact_Number: '', - // contact_Person_Name: '', - - // }) - - const [validForm, setValidForm] = useState(false); - - const [errors, setErrors] = useState({ - emailError: "", - phoneError: "", - }); - const validEmailRegex = RegExp( - /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i - ); - const validPhoneRegex = RegExp( - /^(\+\d{1,2}\s?)?1?\-?\.?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/ - ); - - const validateForm = () => { - let valid = true; - Object.values(errors).forEach((val) => { - if (val.length > 0) { - valid = false; - return false; - } - }); - Object.values(data.email).forEach((val) => { - if (val.length <= 0) { - valid = false; - return false; - } - }); - return valid; - }; - - //cheking email and password - useEffect(() => { - if (validateForm()) { - setValidForm(true); - } else { - setValidForm(false); - } - }, [errors]); - - const handleChange = (e) => { - if (e.target.id === "userName") { - if (e.target.value.length < 0) return; - - setData((prev) => ({ - ...prev, - short_url: e.target.value.toLowerCase().replace(/\s+/g, "-"), - })); - } - - if (e.target.id === "contact_Number") { - setErrors({ - ...errors, - phoneError: validPhoneRegex.test(e.target.value) - ? "" - : "Number is not valid!", - }); - } - if (e.target.id === "email") { - setErrors({ - ...errors, - emailError: validEmailRegex.test(e.target.value) - ? "" - : "Email is not valid!", - }); - } - - if (e.target.id === "image") { - if ( - e.target.files[0]?.type === "image/jpeg" || - e.target.files[0]?.type === "image/png" || - e.target.files[0]?.type === "image/jpg" - ) { - setData((prev) => ({ - ...prev, - imageURL: URL.createObjectURL(e.target.files[0]), - image: e.target.files[0], - })); - return; - } else { - swal({ - title: "Warning", - text: "Upload jpg, jpeg, png only.", - icon: "error", - button: "Close", - dangerMode: true, - }); - setData((prev) => ({ - ...prev, - imageURL: "", - image: "", - })); - e.target.value = null; - return; - } - } - setData((prev) => ({ ...prev, [e.target.id]: e.target.value })); - }; - - return ( -
-
-
-
-
- Basic Information -
-
-

-
- -
- - - -
-
-
-
-
-
-
-
-
- - handleChange(e)} - /> - {data.userName.length > 0 && ( -

- Remaining characters : {50 - data.userName.length} -

- )} -
- -
- - handleChange(e)} - /> - {errors.emailError && ( -

- {errors.emailError} -

- )} -
-
- - handleChange(e)} - /> - {errors.phoneError && ( -

- {errors.phoneError} -

- )} -
- - {/*
- -
- - {data.WebsiteURL} - - handleChange(e)} - /> -
-
*/} - - {/*
- - handleChange(e)} - /> -

Upload jpg, jpeg and png only*

-
-
- Uploaded Image will be shown here -
*/} -
-
-
-
-
- ); -}; - -export default Contacts; diff --git a/src/views/Business/multiform/DoctorInfo.js b/src/views/Business/multiform/DoctorInfo.js deleted file mode 100644 index 16e4d98..0000000 --- a/src/views/Business/multiform/DoctorInfo.js +++ /dev/null @@ -1,338 +0,0 @@ -import React, { useEffect, useState } from "react"; -import Button from "@material-ui/core/Button"; -import { Link, useNavigate } from "react-router-dom"; -import swal from "sweetalert"; -import axios from "axios"; -import { isAutheticated } from "src/auth"; -import { CFormLabel, CFormSelect } from "@coreui/react"; -// import { WebsiteURL } from '../WebsiteURL' - -const DcotorInfo = (props) => { - const token = isAutheticated(); - - const navigate = useNavigate(); - - const { data, setData } = props.data; - - const [categories, setCategories] = useState([]); - - const getCategories = () => { - axios.get("/api/config/specialty/getall").then((res) => { - setCategories(res.data.specialty); - }); - }; - - // create options from categories with placeholder select Specialization - const options = [ - { - label: "Select Specialization", - value: "", - }, - ...categories.map((category) => { - return { - label: category.name, - value: category.name, - }; - }), - ]; - - useEffect(() => { - getCategories(); - }, []); - - const { loading, setLoading } = props.loading; - // const [data, setData] = useState({ - // image: '', - // imageURL: '', - // name: '', - // email: '', - - // short_url: '', - // contact_Number: '', - // contact_Person_Name: '', - - // }) - - const [validForm, setValidForm] = useState(false); - - const [errors, setErrors] = useState({ - emailError: "", - phoneError: "", - }); - const validEmailRegex = RegExp( - /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i - ); - const validPhoneRegex = RegExp( - /^(\+\d{1,2}\s?)?1?\-?\.?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/ - ); - - const validateForm = () => { - let valid = true; - Object.values(errors).forEach((val) => { - if (val.length > 0) { - valid = false; - return false; - } - }); - Object.values(data.email).forEach((val) => { - if (val.length <= 0) { - valid = false; - return false; - } - }); - return valid; - }; - - //cheking email and password - useEffect(() => { - if (validateForm()) { - setValidForm(true); - } else { - setValidForm(false); - } - }, [errors]); - - const handleChange = (e) => { - if (e.target.id === "contact_Person_Name") { - if (e.target.value.length < 0) return; - - setData((prev) => ({ - ...prev, - short_url: e.target.value.toLowerCase().replace(/\s+/g, "-"), - })); - } - - if (e.target.id === "contact_Number") { - setErrors({ - ...errors, - phoneError: validPhoneRegex.test(e.target.value) - ? "" - : "Number is not valid!", - }); - } - if (e.target.id === "email") { - setErrors({ - ...errors, - emailError: validEmailRegex.test(e.target.value) - ? "" - : "Email is not valid!", - }); - } - - if (e.target.id === "image") { - if ( - e.target.files[0]?.type === "image/jpeg" || - e.target.files[0]?.type === "image/png" || - e.target.files[0]?.type === "image/jpg" - ) { - setData((prev) => ({ - ...prev, - imageURL: URL.createObjectURL(e.target.files[0]), - image: e.target.files[0], - })); - return; - } else { - swal({ - title: "Warning", - text: "Upload jpg, jpeg, png only.", - icon: "error", - button: "Close", - dangerMode: true, - }); - setData((prev) => ({ - ...prev, - imageURL: "", - image: "", - })); - e.target.value = null; - return; - } - } - setData((prev) => ({ ...prev, [e.target.id]: e.target.value })); - }; - - return ( -
-
-
-
-
- Doctor Information -
-
-

-
- -
- - - -
-
-
-
-
-
-
-
-
- - handleChange(e)} - /> -
- -
- - Specialization * - - -
- - {/*
- - handleChange(e)} - /> - {data.business_name.length > 0 && ( -

- Remaining characters : {50 - data.business_name.length} -

- )} -
*/} - -
- - handleChange(e)} - /> - {errors.emailError && ( -

- {errors.emailError} -

- )} -
-
- - handleChange(e)} - /> - {errors.phoneError && ( -

- {errors.phoneError} -

- )} -
- - {/*
- -
- - {data.WebsiteURL} - - handleChange(e)} - /> -
-
*/} - - {/*
- - handleChange(e)} - /> -

Upload jpg, jpeg and png only*

-
-
- Uploaded Image will be shown here -
*/} -
-
-
-
-
- ); -}; - -export default DcotorInfo; diff --git a/src/views/Business/multiform/SelectBusiness.js b/src/views/Business/multiform/SelectBusiness.js deleted file mode 100644 index 43a55f1..0000000 --- a/src/views/Business/multiform/SelectBusiness.js +++ /dev/null @@ -1,142 +0,0 @@ -import React, { useEffect, useState } from "react"; -import Button from "@material-ui/core/Button"; -import { Link, useNavigate } from "react-router-dom"; -import swal from "sweetalert"; -import axios from "axios"; -import { isAutheticated } from "src/auth"; -import toast from "react-hot-toast"; - -const SelectBusiness = (props) => { - const token = isAutheticated(); - const navigate = useNavigate(); - console.log(props.handleView); - - const { data, setData } = props.data; - const { loading, setLoading } = props.loading; - // const categories = props?.categories || [] - - const handleChange = (e) => { - setData((prev) => ({ ...prev, [e.target.id]: e.target.value })); - }; - - // const [loading, setLoading] = useState(false) - - const [BusinessData, setBusinessData] = useState([]); - const getCategories = () => { - axios - .get(`/api/business`, { - headers: { - "Access-Control-Allow-Origin": "*", - Authorization: `Bearer ${token}`, - }, - }) - .then((res) => { - setBusinessData(res.data.data); - setLoading(false); - }) - .catch((err) => { - console.log(err); - setLoading(false); - }); - }; - - useEffect(() => { - getCategories(); - }, []); - - const handleSubmit = () => {}; - - return ( -
-
-
-
-
- Select User Type -
-
-

-
- -
- - - - -
-
-
-
- -
-
-
-
-
- -
-
-
-
-
-
- ); -}; - -export default SelectBusiness; diff --git a/src/views/Business/multiform/SelectPurpose.js b/src/views/Business/multiform/SelectPurpose.js deleted file mode 100644 index af21165..0000000 --- a/src/views/Business/multiform/SelectPurpose.js +++ /dev/null @@ -1,173 +0,0 @@ - -import React, { useEffect, useState } from 'react' -import Button from '@material-ui/core/Button' -import { Link, useNavigate } from 'react-router-dom' -import swal from 'sweetalert' -import axios from 'axios' -import { isAutheticated } from 'src/auth' - - - -const SelectPurpose = (props) => { - const token = isAutheticated() - const navigate = useNavigate() - - const { data, setData } = props.data - - const { loading, setLoading } = props.loading - // const categories = props?.categories || [] - - const handleChange = (e) => { - - setData((prev) => ({ ...prev, [e.target.id]: e.target.value })) - } - - - // const [loading, setLoading] = useState(false) - - - const [purposeData, setPurposeData] = useState([]) - - - const getCategories = () => { - axios - .get(`/api/purpose`, { - headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` }, - }) - .then((res) => { - // console.log(res.data) - setPurposeData(res.data?.data) - setLoading(false) - }) - .catch((err) => { - console.log(err) - setLoading(false) - }) - } - - useEffect(() => { - getCategories() - }, []) - - - - - const handleSubmit = () => { - - } - - return ( -
-
-
-
-
- Select Purpose -
-
-

-
- -
- {/* */} - - - - -
-
-
-
- - - -
-
-
-
- - - - - -
- - - -
- - - - -
-
-
- -
-
- ) -} - -export default SelectPurpose \ No newline at end of file diff --git a/src/views/Business/multiform/selectLanguage.js b/src/views/Business/multiform/selectLanguage.js deleted file mode 100644 index 6cb3f1d..0000000 --- a/src/views/Business/multiform/selectLanguage.js +++ /dev/null @@ -1,163 +0,0 @@ -import React, { useEffect, useState } from "react"; -import Button from "@material-ui/core/Button"; -import { Link, useNavigate } from "react-router-dom"; -import swal from "sweetalert"; -import axios from "axios"; -import { isAutheticated } from "src/auth"; - -const selectLanguage = (props) => { - const token = isAutheticated(); - const navigate = useNavigate(); - - const { data, setData } = props.data; - - const { loading, setLoading } = props.loading; - // const categories = props?.categories || [] - - const handleChange = (e) => { - if (data.language.length < 3) { - setData((prev) => ({ - ...prev, - language: [...data.language, e.target.value], - })); - } else { - swal({ - title: "Warning", - text: "please select Up to 3 languages!", - icon: "warning", - button: "ok", - dangerMode: true, - }); - } - }; - - // const [loading, setLoading] = useState(false) - - const [LanguagesData, setLanguagesData] = useState([]); - - const getCategories = () => { - axios - .get(`/api/language`, { - headers: { - "Access-Control-Allow-Origin": "*", - Authorization: `Bearer ${token}`, - }, - }) - .then((res) => { - setLanguagesData(res.data.data); - setLoading(false); - }) - .catch((err) => { - console.log(err); - setLoading(false); - }); - }; - - useEffect(() => { - getCategories(); - }, []); - - return ( -
-
-
-
-
- Select Language -
-
-

-
- -
- - - -
-
-
-
- -
-
-
-
-
- - {LanguagesData.length > 0 && - LanguagesData.map((item, index) => ( - // -
- handleChange(e)} - /> - {/* {checked = { data.language.map(item => item === item?.language) }} */} - -
- ))} - {/* */} -
-
-
-
-
-
- ); -}; - -export default selectLanguage; diff --git a/src/views/Categories/categories.js b/src/views/Categories/categories.js index a9342e0..27e59b1 100644 --- a/src/views/Categories/categories.js +++ b/src/views/Categories/categories.js @@ -13,10 +13,12 @@ import { import CloseIcon from "@mui/icons-material/Close"; import { ClipLoader } from "react-spinners"; import swal from "sweetalert"; +import CloudUploadIcon from "@mui/icons-material/CloudUpload"; +import DeleteSharpIcon from "@mui/icons-material/DeleteSharp"; const style = { position: "absolute", - top: "20%", + top: "50%", left: "50%", transform: "translate(-50%, -50%)", width: 400, @@ -34,21 +36,25 @@ const Categories = () => { const [saveLoding, setSaveLoading] = useState(true); const [edit, setEdit] = useState(false); const [categoryName, setCategoryName] = useState(""); - + const [categoryImage, setCategoryImage] = useState(""); + const [error, setError] = useState(""); const [categoryId, setCategoryId] = useState(""); const [category, setCategory] = useState([]); const [itemPerPage, setItemPerPage] = useState(10); const [page, setPage] = useState(1); const [open, setOpen] = useState(false); + const [olderCategoryName, setOlderCategoruName] = useState(""); + const [olderImage, setOlderImage] = useState(""); const handleOpen = () => setOpen(true); const handleClose = () => { setOpen(false); // setUpdating(true) + setCategoryName(""); setCategoryId(""); - // setUpdating(false); - // setIsUpdate(false); + setOlderImage(""); + setCategoryImage(""); }; const getCategories = async () => { @@ -78,34 +84,75 @@ const Categories = () => { getCategories(); }, [token, category]); - console.log(category.length); - const handleEditClick = (_id, categoryName) => { + const handleEditClick = (_id, categoryName, categoryImage) => { setOpen(true); - + setOlderImage(categoryImage); setCategoryName(categoryName); setCategoryId(_id); + setOlderCategoruName(categoryName); setEdit(true); // setUpdating(false); }; + const categoryNamesArray = []; + const setCategoryNamesArray = () => { + category && + category.map((category) => { + categoryNamesArray.push(category.categoryName.toLowerCase()); + }); + }; + setCategoryNamesArray(); const handleUpdate = () => { + const filteredArrayNames = categoryNamesArray.filter( + (item) => item !== olderCategoryName.toLowerCase() + ); + console.log(filteredArrayNames, "filter"); + const categoryExits = filteredArrayNames.includes( + categoryName.toLowerCase() + ); + if (categoryExits) { + swal({ + title: "Warning", + text: "Category already exists ", + icon: "error", + button: "Retry", + dangerMode: true, + }); + return; + } + + if (!categoryName || (!categoryImage && !olderImage)) { + swal({ + title: "Warning", + text: "Please fill all the required fields!", + icon: "error", + button: "Retry", + dangerMode: true, + }); + return; + } setUpdating(false); + const formData = new FormData(); + formData.append("categoryName", categoryName); + + formData.append("categoryImage", categoryImage); + + formData.append("olderImage", JSON.stringify(olderImage)); + axios - .patch( - `/api/category/update/${categoryId}`, - { categoryName }, - { - headers: { - Authorization: `Bearer ${token}`, - }, - } - ) + .patch(`/api/category/update/${categoryId}`, formData, { + headers: { + Authorization: `Bearer ${token}`, + }, + }) .then((res) => { // setUpdating(true); // setIsUpdate(false); handleClose(); setCategoryId(""); setCategoryName(""); + setCategoryImage(""); + setOlderImage(""); setUpdating(true); setEdit(false); swal({ @@ -119,11 +166,12 @@ const Categories = () => { .catch((err) => { swal({ title: "Sorry, please try again", - text: "Something went wrong!", + text: err, icon: "error", button: "Retry", dangerMode: true, }); + setUpdating(true); }); }; @@ -166,10 +214,23 @@ const Categories = () => { }; const handleSaveCategory = async () => { - if (!categoryName) { + const categoryExits = categoryNamesArray.includes( + categoryName.toLowerCase() + ); + if (categoryExits) { swal({ title: "Warning", - text: "Category name is empty. Please enter the category name!", + text: "Category Already exits.", + icon: "error", + button: "Retry", + dangerMode: true, + }); + return; + } + if (!categoryName || !categoryImage) { + swal({ + title: "Warning", + text: "Please fill all the required fields!", icon: "error", button: "Retry", dangerMode: true, @@ -178,23 +239,25 @@ const Categories = () => { } setSaveLoading(false); setLoading(true); + const formData = new FormData(); + formData.append("categoryName", categoryName); + formData.append("categoryImage", categoryImage); + axios - .post( - "/api/category/add", - { categoryName }, - { - headers: { - Authorization: `Bearer ${token}`, - "Content-Type": "application/json", - }, - } - ) + .post("/api/category/add", formData, { + headers: { + Authorization: `Bearer ${token}`, + "Content-Type": "multipart/formdata", + }, + }) .then((response) => { if (response.status === 201) { setOpen(false); setLoading(false); setSaveLoading(true); setCategoryName(""); + setCategoryImage(""); + setOlderImage(""); swal({ title: "Added", text: "New category added successfully!", @@ -218,6 +281,19 @@ const Categories = () => { const getPageCount = () => { return Math.max(1, Math.ceil(category.length / itemPerPage)); }; + + const handleFileChange = (e) => { + const files = e.target.files[0]; + + // Check file types and append to selectedFiles + const allowedTypes = ["image/jpeg", "image/png", "image/jpg"]; + if (allowedTypes.includes(files.type)) { + setCategoryImage(files); + } + }; + const handeldeleteImage = () => { + setCategoryImage(""); + }; return (
@@ -283,7 +359,12 @@ const Categories = () => { style={{ padding: "1rem", }} - onChange={(e) => setCategoryName(e.target.value)} + onChange={(e) => + setCategoryName( + e.target.value.charAt(0).toUpperCase() + + e.target.value.slice(1) + ) + } /> {categoryName ? ( <> @@ -294,6 +375,112 @@ const Categories = () => { ) : ( <> )} + + + + {categoryImage && ( + + categoryImage + handeldeleteImage()} + fontSize="small" + sx={{ + color: "white", + position: "absolute", + cursor: "pointer", + padding: "0.2rem", + background: "black", + borderRadius: "50%", + }} + /> + + )} + {olderImage && ( + + categoryImage + setOlderImage("")} + fontSize="small" + sx={{ + color: "white", + position: "absolute", + cursor: "pointer", + padding: "0.2rem", + background: "black", + borderRadius: "50%", + }} + /> + + )} + + + {error &&

{error}

} +

+ Upload jpg, jpeg and png only* +

+ { style={{ background: "rgb(140, 213, 213)" }} > + Image + Categories Name Action @@ -433,6 +622,15 @@ const Categories = () => { ) .map((item, i) => ( + + +
{}
+
{item.categoryName}
@@ -453,7 +651,8 @@ const Categories = () => { onClick={() => handleEditClick( item._id, - item.categoryName + item.categoryName, + item.categoryImage ) } > diff --git a/src/views/Products/Products.js b/src/views/Products/Products.js index ba189bc..a486b2f 100644 --- a/src/views/Products/Products.js +++ b/src/views/Products/Products.js @@ -229,14 +229,6 @@ const Products = () => { margin: "1rem 1rem 1rem 0rem", }} > - {/* setQuery(e.target.value)} - placeholder="Type your keywords..." - /> - {" "} */} { + const inputValue = e.target.value; + const numericValue = inputValue.replace(/[^0-9]/g, ""); + setPhno(numericValue); + if (numericValue.length > 10 || numericValue.length < 10) { + setPhnoError( + "Please enter a valid phone number with a maximum of 10 digits." + ); + } else { + setPhno(numericValue); + setPhnoError(""); + } + }; + + const handleEmailChange = (e) => { + const inputValue = e.target.value; + setEmail(inputValue); + // Regular expression for email validation + const emailRegex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i; + + if (!emailRegex.test(inputValue)) { + setEmailError("Please enter a valid email address."); + } else { + setEmail(inputValue); + setEmailError(""); + } + }; + + const handleNextClick = () => { + if (view === "0" && selectUserType !== "") { + setView("1"); + } else if ( + !emailError && + !phnoError && + name !== "" && + email !== "" && + phno !== "" && + view === "1" + ) { + setView("2"); + } else { + swal({ + title: "Please fill all the required fileds correctly", + icon: "error", + button: "Ok", + dangerMode: true, + }); + } + }; + + const handleBackClick = () => { + if (view === "1") { + setView("0"); + } else if (view === "2") { + setView("1"); + } + }; + const handleAddMoreAddress = () => { + setAddressess([ + ...addressess, + { + id: uuid(), + addressLine1: "", + addressLine2: "", + country: "", + state: "", + city: "", + zipcode: "", + }, + ]); + }; + console.log(addressess); + + const handleDelete = (id) => { + const filteredAddress = addressess.filter((item) => item.id != id); + setAddressess(filteredAddress); + }; + const handleAddressChange = (id, field, value) => { + // Find the address with the given ID + const updatedAddresses = addressess.map((address) => { + if (address.id === id) { + return { ...address, [field]: value }; + } + return address; + }); + + setAddressess(updatedAddresses); + }; + + const handleSaveClick = async () => { + if ( + !selectUserType || + !name || + !email || + !phno || + addressess.some(addressIsEmpty) + ) { + swal({ + title: "Please fill all the required fields correctly", + icon: "error", + button: "Ok", + dangerMode: true, + }); + } else { + const saveresponse = await axios.post( + "/api/user-address/addAddress", + { + userType: selectUserType, + name, + email, + phno, + addressess, + }, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + if (saveresponse.status === 201) { + swal({ + title: "Congratulations!!", + text: "Address stored successfully!", + icon: "success", + button: "OK", + }); + navigate("/users-address", { replace: true }); + } else { + swal({ + title: "Please try again !", + text: "something went wrong", + icon: "error", + button: "OK", + }); + } + } + }; + + const addressIsEmpty = (address) => { + return ( + address.addressLine1 === "" || + address.country === "" || + address.state === "" || + address.city === "" || + address.zipcode === "" + ); + }; + + // Get the address + // const getUserAddress = async () => { + // const address = await axios.get("/api/user-address/getAddress", { + // headers: { + // Authorization: `Bearer ${token}`, + // }, + // }); + // if (address.status === 200) { + // console.log(address); + // setSelectUserType(address?.data?.userAddress?.userType); + // setUpdateBtn(true); + // setEdit(true); + + // setName(address?.data?.userAddress?.name); + // setEmail(address?.data?.userAddress?.email); + // setPhno(address?.data?.userAddress?.phno); + // setAddressess(address?.data?.userAddress?.addressess); + // } + // }; + + // const handleUpdateAddress = async () => { + // const updatedresponse = await axios.patch( + // "/api/user-address/updateAddress", + // { + // userType: selectUserType, + // name, + // email, + // phno, + // addressess, + // }, + // { + // headers: { + // Authorization: `Bearer ${token}`, + // }, + // } + // ); + // if (updatedresponse.status === 200) { + // setEdit(true); + // swal({ + // title: "Congratulations!!", + // text: "Address updated successfully!", + // icon: "success", + // button: "OK", + // }); + // } else { + // swal({ + // title: "Please try again", + // text: "Cannot update something went wronge !", + // icon: "error", + // button: "OK", + // }); + // } + // }; + + // useEffect(() => { + // getUserAddress(); + // }, []); + + // console.log(selectUserType, name, email, phno, addressess); + return ( +
+ + + User Address + + + +
+ + + {/* {updateBtn && ( + + )} */} + {view !== "2" && ( + + )} + {view === "2" && ( + + )} + + + + + {/* {view === "2" && updateBtn && ( + + )} */} +
+ {view === "0" && ( +
+
+ + Select User Type + +
+ + + +
+ )} + {view === "1" && ( +
+ + User Basic Information + + + Name: + + setName(e.target.value)} + /> + + Email: + + + {emailError && ( + {emailError} + )} + + Contact number: + + + {phnoError && ( + {phnoError} + )} +
+ )} + {view === "2" && ( + + + {addressess.map((address, i) => ( + + + + Address {i + 1} + + {addressess.length > 1 && ( + + )} + + + + handleAddressChange(address.id, field, value) + } + /> + + ))} + + )} +
+
+
+ ); +} diff --git a/src/views/UserAddress/editUserAddress.js b/src/views/UserAddress/editUserAddress.js new file mode 100644 index 0000000..f341db6 --- /dev/null +++ b/src/views/UserAddress/editUserAddress.js @@ -0,0 +1,432 @@ +import { Typography } from "@material-ui/core"; +import { + Box, + Button, + FormControl, + MenuItem, + Select, + TextField, +} from "@mui/material"; +import React, { useEffect, useState } from "react"; +import swal from "sweetalert"; +import { v4 as uuid } from "uuid"; +import MainAddress from "./mainAddress"; +import axios from "axios"; +import { isAutheticated } from "src/auth"; +import { useNavigate, useParams } from "react-router-dom"; + +export default function EditUserAddress() { + const token = isAutheticated(); + + const [selectUserType, setSelectUserType] = useState(""); + const [name, setName] = useState(""); + const [email, setEmail] = useState(""); + const [phno, setPhno] = useState(""); + const [updateBtn, setUpdateBtn] = useState(false); + const [edit, setEdit] = useState(false); + const navigate = useNavigate(); + const id = useParams()?.id; + const [addressess, setAddressess] = useState([ + { + id: uuid(), + addressLine1: "", + addressLine2: "", + country: "", + state: "", + city: "", + zipcode: "", + }, + ]); + + const [view, setView] = useState("0"); + const [phnoError, setPhnoError] = useState(""); + const [emailError, setEmailError] = useState(""); + + const handlePhnoChange = (e) => { + const inputValue = e.target.value; + const numericValue = inputValue.replace(/[^0-9]/g, ""); + setPhno(numericValue); + if (numericValue.length > 10 || numericValue.length < 10) { + setPhnoError( + "Please enter a valid phone number with a maximum of 10 digits." + ); + } else { + setPhno(numericValue); + setPhnoError(""); + } + }; + + const handleEmailChange = (e) => { + const inputValue = e.target.value; + setEmail(inputValue); + // Regular expression for email validation + const emailRegex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i; + + if (!emailRegex.test(inputValue)) { + setEmailError("Please enter a valid email address."); + } else { + setEmail(inputValue); + setEmailError(""); + } + }; + + const handleNextClick = () => { + if (view === "0" && selectUserType !== "") { + setView("1"); + } else if ( + !emailError && + !phnoError && + name !== "" && + email !== "" && + phno !== "" && + view === "1" + ) { + setView("2"); + } else { + swal({ + title: "Please fill all the required fileds correctly", + icon: "error", + button: "Ok", + dangerMode: true, + }); + } + }; + + const handleBackClick = () => { + if (view === "1") { + setView("0"); + } else if (view === "2") { + setView("1"); + } + }; + const handleAddMoreAddress = () => { + setAddressess([ + ...addressess, + { + id: uuid(), + addressLine1: "", + addressLine2: "", + country: "", + state: "", + city: "", + zipcode: "", + }, + ]); + }; + + const handleDelete = (id) => { + const filteredAddress = addressess.filter((item) => item.id != id); + setAddressess(filteredAddress); + }; + const handleAddressChange = (id, field, value) => { + // Find the address with the given ID + const updatedAddresses = addressess.map((address) => { + if (address.id === id) { + return { ...address, [field]: value }; + } + return address; + }); + + setAddressess(updatedAddresses); + }; + + const getOneAddress = async () => { + axios + .get(`/api/user-address/getOneAddress/${id}`, { + headers: { + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + }) + .then((res) => { + setSelectUserType(res?.data?.address?.userType); + + setName(res?.data?.address?.name); + setEmail(res?.data?.address?.email); + setPhno(res?.data?.address?.phno); + setAddressess(res?.data?.address?.addressess); + }) + .catch((error) => { + swal({ + title: error, + text: " Can not fetch the Address ", + icon: "error", + button: "Retry", + dangerMode: true, + }); + }); + }; + const handleUpdateAddress = async () => { + if ( + !selectUserType || + !name || + !email || + !phno || + addressess.some(addressIsEmpty) + ) { + swal({ + title: "Please fill all the required fields correctly", + icon: "error", + button: "Ok", + dangerMode: true, + }); + } else { + const updatedresponse = await axios.patch( + `/api/user-address/updateAddress/${id}`, + { + userType: selectUserType, + name, + email, + phno, + addressess, + }, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + if (updatedresponse.status === 200) { + swal({ + title: "Congratulations!!", + text: "Address updated successfully!", + icon: "success", + button: "OK", + }); + navigate("/users-address", { replace: true }); + } else { + swal({ + title: "Please try again", + text: "Cannot update something went wronge !", + icon: "error", + button: "OK", + }); + } + } + }; + const addressIsEmpty = (address) => { + return ( + address.addressLine1 === "" || + address.country === "" || + address.state === "" || + address.city === "" || + address.zipcode === "" + ); + }; + + useEffect(() => { + getOneAddress(); + }, []); + + return ( +
+ + + User Address + + +
+ + + {view !== "2" && ( + + )} + + {view === "2" && ( + + )} +
+ {view === "0" && ( +
+
+ + Select User Type + +
+ + + +
+ )} + {view === "1" && ( +
+ + User Basic Information + + + Name: + + setName(e.target.value)} + /> + + Email: + + + {emailError && ( + {emailError} + )} + + Contact number: + + + {phnoError && ( + {phnoError} + )} +
+ )} + {view === "2" && ( + + + {addressess.map((address, i) => ( + + + + Address {i + 1} + + {addressess.length > 1 && ( + + )} + + + + handleAddressChange(address.id, field, value) + } + /> + + ))} + + )} +
+
+
+ ); +} diff --git a/src/views/UserAddress/mainAddress.js b/src/views/UserAddress/mainAddress.js new file mode 100644 index 0000000..24fa7d7 --- /dev/null +++ b/src/views/UserAddress/mainAddress.js @@ -0,0 +1,138 @@ +// MainAddress.js +import React from "react"; +import TextField from "@mui/material/TextField"; +import { Country, State, City } from "country-state-city"; +import { + FormControl, + InputLabel, + MenuItem, + Paper, + Select, +} from "@mui/material"; +import { Box, Typography } from "@material-ui/core"; + +export default function MainAddress({ address, onAddressChange, edit }) { + const { id, addressLine1, addressLine2, country, state, city, zipcode } = + address; + + const handleFieldChange = (field, value) => { + onAddressChange(field, value); + }; + const countries = Country.getAllCountries(); + const states = State.getStatesOfCountry(country); + const cities = City.getCitiesOfState(country, state); + + return ( +
+ handleFieldChange("addressLine1", e.target.value)} + /> + handleFieldChange("addressLine2", e.target.value)} + /> + {/* handleFieldChange("country", e.target.value)} + /> */} + Select Country* + + + + Select State* + + + + Select City* + + + + Zipcode* + handleFieldChange("zipcode", e.target.value)} + /> +
+ ); +} diff --git a/src/views/Business/Businesses.js b/src/views/UserAddress/userTable.js similarity index 59% rename from src/views/Business/Businesses.js rename to src/views/UserAddress/userTable.js index 286b82c..64d5b88 100644 --- a/src/views/Business/Businesses.js +++ b/src/views/UserAddress/userTable.js @@ -1,94 +1,76 @@ -import React, { useEffect } from "react"; -import Button from "@material-ui/core/Button"; -import { useState } from "react"; +import React, { useState, useEffect } from "react"; import { Link } from "react-router-dom"; +import Button from "@material-ui/core/Button"; +import { useNavigate } from "react-router-dom"; import axios from "axios"; +import { isAutheticated } from "src/auth"; import swal from "sweetalert"; -import OverLayButton from "./OverLayButton.js"; -import { isAutheticated } from "src/auth.js"; - -const Businesses = () => { +import { + Box, + FormControl, + IconButton, + InputLabel, + MenuItem, + Select, + TextField, +} from "@mui/material"; +import SearchIcon from "@mui/icons-material/Search"; +import Fuse from "fuse.js"; +import { Typography } from "@material-ui/core"; +const UserTable = () => { const token = isAutheticated(); + const [query, setQuery] = useState(""); + const navigate = useNavigate(); const [loading, setLoading] = useState(true); const [success, setSuccess] = useState(true); - const [BusinessesData, setBusinessesData] = useState([]); + const [userAddress, setUserAddress] = useState([]); const [currentPage, setCurrentPage] = useState(1); const [itemPerPage, setItemPerPage] = useState(10); - const [showData, setShowData] = useState(BusinessesData); + const [showData, setShowData] = useState(userAddress); const handleShowEntries = (e) => { setCurrentPage(1); setItemPerPage(e.target.value); }; - const getbusinesses = () => { + const getUserAddressess = async () => { axios - .get(`/api/businesses/getall`, { + .get(`/api/user-address/getAddressess`, { headers: { - "Access-Control-Allow-Origin": "*", Authorization: `Bearer ${token}`, }, }) .then((res) => { - setBusinessesData(res.data?.businesses); + setUserAddress(res.data?.userAddress); setLoading(false); }) - .catch((err) => { - console.log(err); + .catch((error) => { + swal({ + title: error, + text: "please login to access the resource or refresh the page ", + icon: "error", + button: "Retry", + dangerMode: true, + }); setLoading(false); }); }; useEffect(() => { - getbusinesses(); + getUserAddressess(); }, [success]); + console.log(userAddress); useEffect(() => { const loadData = () => { const indexOfLastPost = currentPage * itemPerPage; const indexOfFirstPost = indexOfLastPost - itemPerPage; - setShowData(BusinessesData.slice(indexOfFirstPost, indexOfLastPost)); + setShowData(userAddress.slice(indexOfFirstPost, indexOfLastPost)); }; loadData(); - }, [currentPage, itemPerPage, BusinessesData]); + }, [currentPage, itemPerPage, userAddress]); - // const handleVarification = (id) => { - // swal({ - // title: 'Are you sure?', - // icon: 'warning', - // buttons: { Yes: { text: 'Yes', value: true }, Cancel: { text: 'Cancel', value: 'cancel' } }, - // }).then((value) => { - // if (value === true) { - // axios - // .get(`/api/i/admin/verify/${id}`, { - // headers: { - // 'Access-Control-Allow-Origin': '*', - // Authorization: `Bearer ${token}`, - // }, - // }) - // .then((res) => { - // swal({ - // title: 'success', - // text: res.data.message ? res.data.message : 'Verified Successfully!', - // icon: 'success', - // button: 'ok', - // dangerMode: true, - // }) - // setSuccess((prev) => !prev) - // }) - // .catch((err) => { - // swal({ - // title: 'Failled', - // text: 'Something went wrong!', - // icon: 'error', - // button: 'Retry', - // dangerMode: true, - // }) - // }) - // } - // }) - // } const handleDelete = (id) => { swal({ title: "Are you sure?", @@ -100,13 +82,19 @@ const Businesses = () => { }).then((value) => { if (value === true) { axios - .delete(`/api/businesses/delete/${id}`, { + .delete(`/api/user-address/deleteAddress/${id}`, { headers: { "Access-Control-Allow-Origin": "*", Authorization: `Bearer ${token}`, }, }) .then((res) => { + swal({ + title: "Deleted", + text: "Address Deleted successfully!", + icon: "success", + button: "ok", + }); setSuccess((prev) => !prev); }) .catch((err) => { @@ -122,12 +110,6 @@ const Businesses = () => { }); }; - const formatDate = (inputDate) => { - const options = { year: 'numeric', month: 'short', day: 'numeric' }; - const date = new Date(inputDate); - return date.toLocaleDateString('en-US', options); - } - return (
@@ -147,28 +129,30 @@ const Businesses = () => {
- - - +
+
-
+
@@ -408,7 +370,7 @@ const Businesses = () => { {!( (currentPage + 1) * itemPerPage - itemPerPage > - BusinessesData.length - 1 + userAddress.length - 1 ) && (
  • { className={ !( (currentPage + 1) * itemPerPage - itemPerPage > - BusinessesData.length - 1 + userAddress.length - 1 ) ? "paginate_button page-item next" : "paginate_button page-item next disabled" @@ -455,4 +417,4 @@ const Businesses = () => { ); }; -export default Businesses; +export default UserTable; diff --git a/src/views/UserAddress/viewAddress.js b/src/views/UserAddress/viewAddress.js new file mode 100644 index 0000000..1d5e099 --- /dev/null +++ b/src/views/UserAddress/viewAddress.js @@ -0,0 +1,220 @@ +import { Typography } from "@material-ui/core"; +import { Box, Button, Paper } from "@mui/material"; +import axios from "axios"; +import React, { useEffect, useState } from "react"; +import { useNavigate, useParams } from "react-router-dom"; +import { isAutheticated } from "src/auth"; +import { Country, State, City } from "country-state-city"; + +const activeStyle = { + background: "black", + margin: "1rem", + textTransform: "unset", + color: "white", +}; +const inActive = { + background: "blue", + margin: "1rem", + textTransform: "unset", + color: "white", +}; + +export default function ViewAddress() { + const [selectUserType, setSelectUserType] = useState(""); + const [name, setName] = useState(""); + const [email, setEmail] = useState(""); + const [phno, setPhno] = useState(""); + const token = isAutheticated(); + const navigate = useNavigate(); + const id = useParams()?.id; + const [addressess, setAddressess] = useState([]); + + const getOneAddress = async () => { + axios + .get(`/api/user-address/getOneAddress/${id}`, { + headers: { + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + }) + .then((res) => { + setSelectUserType(res?.data?.address?.userType); + + setName(res?.data?.address?.name); + setEmail(res?.data?.address?.email); + setPhno(res?.data?.address?.phno); + setAddressess(res?.data?.address?.addressess); + }) + .catch((error) => { + swal({ + title: error, + text: " Can not fetch the Address ", + icon: "error", + button: "Retry", + dangerMode: true, + }); + }); + }; + useEffect(() => { + getOneAddress(); + }, []); + const [activeTab, setActiveTab] = useState("userType"); + return ( +
    + + + + + {activeTab === "userType" && ( + + + User Type :{" "} + {selectUserType} + + + )} + {activeTab === "basicInfo" && ( + + + User Basic Information + + User Name : {name} + + + User email : {email} + + + User phone number :{" "} + {phno} + + + + )} + {activeTab === "userAddress" && ( + + + User Address + {addressess.map((address, i) => ( + + + Address line 1 :{" "} + + {address.addressLine1 == "" + ? "not available" + : address.addressLine1} + + + + Address line 2 :{" "} + + {address.addressLine2 == "" + ? "not available" + : address.addressLine2} + + + + Country :{" "} + + {Country.getCountryByCode(address.country).name} + + + + State :{" "} + + { + State.getStateByCodeAndCountry( + address.state, + address.country + ).name + } + + + + City :{" "} + {address.city} + + + Zipcode :{" "} + + {address.zipcode} + + + + ))} + + + )} + +
    + ); +}