From 1f4050fbe3a576fd753848963e98d16afacebce5 Mon Sep 17 00:00:00 2001 From: MD ARIF KHAN <55360458+arifthehappy@users.noreply.github.com> Date: Tue, 18 Apr 2023 10:09:44 +0530 Subject: [PATCH] add appointment view --- package.json | 1 + src/_nav.js | 116 +-- src/index.js | 40 +- src/routes.js | 300 +++++--- src/scss/_custom.scss | 28 +- src/views/Appointments/AddNewAppointment.js | 397 ++++++++++ src/views/Appointments/Appointments.js | 507 +++++++++++++ src/views/Appointments/EditAppointment.js | 443 +++++++++++ src/views/Appointments/ViewAppointment.js | 153 ++++ src/views/Business/AddBusiness.js | 603 ++++++++------- src/views/Business/Businesses.js | 710 +++++++++--------- src/views/Business/EditBusiness.js | 641 ++++++++-------- src/views/Business/multiform/Contacts.js | 504 ++++++------- src/views/Business/multiform/DoctorInfo.js | 338 +++++++++ .../Business/multiform/SelectBusiness.js | 258 +++---- .../Business/multiform/selectLanguage.js | 280 ++++--- 16 files changed, 3624 insertions(+), 1695 deletions(-) create mode 100644 src/views/Appointments/AddNewAppointment.js create mode 100644 src/views/Appointments/Appointments.js create mode 100644 src/views/Appointments/EditAppointment.js create mode 100644 src/views/Appointments/ViewAppointment.js create mode 100644 src/views/Business/multiform/DoctorInfo.js diff --git a/package.json b/package.json index e4ac57f..951214c 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "@coreui/react-chartjs": "^2.0.0", "@coreui/utils": "^1.3.1", "@material-ui/core": "^4.12.4", + "@material-ui/data-grid": "^4.0.0-alpha.37", "@mui/material": "^5.11.12", "@reduxjs/toolkit": "^1.9.2", "@wojtekmaj/enzyme-adapter-react-17": "^0.6.5", diff --git a/src/_nav.js b/src/_nav.js index 63b8c6a..19a245d 100644 --- a/src/_nav.js +++ b/src/_nav.js @@ -1,5 +1,5 @@ -import React from 'react' -import CIcon from '@coreui/icons-react' +import React from "react"; +import CIcon from "@coreui/icons-react"; import { cilAddressBook, cilAirplaneMode, @@ -7,6 +7,7 @@ import { cilBell, cilBrush, cilCalculator, + cilCalendar, cilCart, cilChartPie, cilClipboard, @@ -36,25 +37,22 @@ import { cilTennisBall, cilText, cilUser, - - -} from '@coreui/icons' -import { CNavGroup, CNavItem, CNavTitle } from '@coreui/react' +} from "@coreui/icons"; +import { CNavGroup, CNavItem, CNavTitle } from "@coreui/react"; const _nav = [ { component: CNavItem, - name: 'Dashboard', - to: '/dashboard', + name: "Dashboard", + to: "/dashboard", icon: , - }, { component: CNavItem, - name: 'Products', + name: "Products", icon: , - to: '/products', + to: "/products", }, // { // component: CNavItem, @@ -64,15 +62,15 @@ const _nav = [ // }, { component: CNavItem, - name: 'Testimonials', + name: "Testimonials", icon: , - to: '/testimonials', + to: "/testimonials", }, { component: CNavItem, - name: 'Contact Requests', + name: "Contact Requests", icon: , - to: '/contact/request', + to: "/contact/request", }, // { @@ -84,78 +82,83 @@ const _nav = [ { component: CNavItem, - name: 'Businesses', + name: "Appointments", + icon: , + to: "/appointments", + }, + + { + component: CNavItem, + name: "HealthCare Providers", icon: , - to: '/businesses', + to: "/healthcare/providers", }, { component: CNavGroup, - name: 'Franchisee Orders', + name: "Franchisee Orders", icon: , items: [ { component: CNavItem, - name: 'New', + name: "New", icon: , - to: '/orders/new', + to: "/orders/new", }, { component: CNavItem, - name: 'Paid', + name: "Paid", icon: , - to: '/orders/returned', + to: "/orders/returned", }, { component: CNavItem, - name: 'Processing', + name: "Processing", icon: , - to: '/orders/processing', + to: "/orders/processing", }, { component: CNavItem, - name: 'Dispatched', + name: "Dispatched", icon: , - to: '/orders/dispatched', + to: "/orders/dispatched", }, { component: CNavItem, - name: 'Delivered', + name: "Delivered", icon: , - to: '/orders/delivered', + to: "/orders/delivered", }, { component: CNavItem, - name: 'Cancelled', + name: "Cancelled", icon: , - to: '/orders/cancelled', + to: "/orders/cancelled", }, - ], }, - { component: CNavItem, - name: 'Users', + name: "Users", icon: , - to: '/users', + to: "/users", }, { component: CNavGroup, - name: 'Configuration', + name: "Configuration", icon: , items: [ { component: CNavItem, - name: 'Purpose', + name: "Purpose", icon: , - to: '/purpose', + to: "/purpose", }, { component: CNavItem, - name: 'Business Type', + name: "Business Type", icon: , - to: '/business_type', + to: "/business_type", }, // { @@ -190,52 +193,49 @@ const _nav = [ // }, { component: CNavItem, - name: 'Languages', + name: "Languages", icon: , - to: '/languages', + to: "/languages", }, { component: CNavItem, - name: 'Policies', + name: "Policies", icon: , - to: '/policies', + to: "/policies", }, { component: CNavItem, - name: 'Social Media', + name: "Social Media", icon: , - to: '/socialmedia', + to: "/socialmedia", }, { component: CNavItem, - name: 'Application Name', + name: "Application Name", icon: , - to: '/application/name', + to: "/application/name", }, { component: CNavItem, - name: 'Address', + name: "Address", icon: , - to: '/address', + to: "/address", }, { component: CNavItem, - name: 'Logos', + name: "Logos", icon: , - to: '/logo', + to: "/logo", }, { component: CNavItem, - name: 'Copyright Message', + name: "Copyright Message", icon: , - to: '/copyright/message', + to: "/copyright/message", }, ], }, +]; - - -] - -export default _nav +export default _nav; diff --git a/src/index.js b/src/index.js index a43b94d..9f9488f 100644 --- a/src/index.js +++ b/src/index.js @@ -1,23 +1,23 @@ -import '@coreui/coreui/dist/css/coreui.min.css'; -import 'bootstrap/dist/css/bootstrap.min.css'; -import 'react-app-polyfill/stable' -import 'core-js' -import React from 'react' -import ReactDOM from 'react-dom' -import App from './App' -import * as serviceWorker from './serviceWorker' -import { Provider } from 'react-redux' -import axios from 'axios' -import { store } from './redux/store'; -import { cibGmail } from '@coreui/icons'; +import "@coreui/coreui/dist/css/coreui.min.css"; +import "bootstrap/dist/css/bootstrap.min.css"; +import "react-app-polyfill/stable"; +import "core-js"; +import React from "react"; +import ReactDOM from "react-dom"; +import App from "./App"; +import * as serviceWorker from "./serviceWorker"; +import { Provider } from "react-redux"; +import axios from "axios"; +import { store } from "./redux/store"; +import { cibGmail } from "@coreui/icons"; const setupAxios = () => { - axios.defaults.baseURL = 'https://bolo-api.checkapp.one/' - //axios.defaults.baseURL = 'http://localhost:5000' + //axios.defaults.baseURL = 'https://bolo-api.checkapp.one/' + axios.defaults.baseURL = "http://localhost:5000"; axios.defaults.headers = { - 'Cache-Control': 'no-cache,no-store', - 'Pragma': 'no-cache', - 'Expires': '0', + "Cache-Control": "no-cache,no-store", + Pragma: "no-cache", + Expires: "0", }; }; @@ -27,10 +27,10 @@ ReactDOM.render( , - document.getElementById('root'), -) + document.getElementById("root") +); // If you want your app to work offline and load faster, you can change // unregister() to register() below. Note this comes with some pitfalls. // Learn more about service workers: http://bit.ly/CRA-PWA -serviceWorker.unregister() +serviceWorker.unregister(); diff --git a/src/routes.js b/src/routes.js index d804437..8f4f062 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1,177 +1,241 @@ -import React from 'react' - +import React from "react"; // DashBoard -const Change_Password = React.lazy(() => import('./views/pages/register/Change_password')) +const Change_Password = React.lazy(() => + import("./views/pages/register/Change_password") +); - -import Profile from './views/Profile/Profile' -import EditProfile from './views/Profile/EditProfile' -const Dashboard = React.lazy(() => import('./views/dashboard/Dashboard')) +import Profile from "./views/Profile/Profile"; +import EditProfile from "./views/Profile/EditProfile"; +const Dashboard = React.lazy(() => import("./views/dashboard/Dashboard")); /// //Cities -import Cities from './views/configuration/Purpose/Purpose.js' -import AddCity from './views/configuration/Purpose/AddPurpose.js' -import EditCity from './views/configuration/Purpose/EditPurpose.js' +import Cities from "./views/configuration/Purpose/Purpose.js"; +import AddCity from "./views/configuration/Purpose/AddPurpose.js"; +import EditCity from "./views/configuration/Purpose/EditPurpose.js"; //states -import EditState from './views/configuration/states/EditStates.js' -import AddState from './views/configuration/states/AddState.js' -import States from './views/configuration/states/States.js' +import EditState from "./views/configuration/states/EditStates.js"; +import AddState from "./views/configuration/states/AddState.js"; +import States from "./views/configuration/states/States.js"; //social media,address,logo -import Socialmedia from './views/configuration/Socialmedia.js' -import Address from './views/configuration/Address.js' -import Logo from './views/configuration/Logo.js' -import Login from './views/pages/login/Login' +import Socialmedia from "./views/configuration/Socialmedia.js"; +import Address from "./views/configuration/Address.js"; +import Logo from "./views/configuration/Logo.js"; +import Login from "./views/pages/login/Login"; + +// Appointments +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' +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' -import EditProduct from './views/Products/EditProduct' -import ViewProduct from './views/Products/ViewProduct' +import AddProduct from "./views/Products/AddProduct"; +import EditProduct from "./views/Products/EditProduct"; +import ViewProduct from "./views/Products/ViewProduct"; //Order Management -import NewOrders from './views/orders/NewOrders.js' -import ProcessingOrders from './views/orders/ProcessingOrders.js' -import DispatchedOrders from './views/orders/DispatchedOrders.js' -import DeliveredOrders from './views/orders/DeliveredOrders.js' -import CancelledOrders from './views/orders/CancelledOrders.js' -import ReturnedOrders from './views/orders/ReturnedOrders.js' -import ViewOrder from './views/orders/ViewOrder' -import AddOrder from './views/orders/AddOrder' +import NewOrders from "./views/orders/NewOrders.js"; +import ProcessingOrders from "./views/orders/ProcessingOrders.js"; +import DispatchedOrders from "./views/orders/DispatchedOrders.js"; +import DeliveredOrders from "./views/orders/DeliveredOrders.js"; +import CancelledOrders from "./views/orders/CancelledOrders.js"; +import ReturnedOrders from "./views/orders/ReturnedOrders.js"; +import ViewOrder from "./views/orders/ViewOrder"; +import AddOrder from "./views/orders/AddOrder"; //Taxes -import Tax from './views/configuration/tax/Tax' -import Addtax from './views/configuration/tax/Addtax' -import Edittax from './views/configuration/tax/Edittax' -import EditOrder from './views/orders/EditOrder' -import ViewOrders from './views/orders/ViewOrders' -import Departures from './views/Departures/Departures' -import AddDeparture from './views/Departures/AddDeparture' -import Informations from './views/Informations/Informations' -import AddInformations from './views/Informations/AddInformations' +import Tax from "./views/configuration/tax/Tax"; +import Addtax from "./views/configuration/tax/Addtax"; +import Edittax from "./views/configuration/tax/Edittax"; +import EditOrder from "./views/orders/EditOrder"; +import ViewOrders from "./views/orders/ViewOrders"; +import Departures from "./views/Departures/Departures"; +import AddDeparture from "./views/Departures/AddDeparture"; +import Informations from "./views/Informations/Informations"; +import AddInformations from "./views/Informations/AddInformations"; -import ApplicationName from './views/configuration/ApplicationName' -import CopyrightMessage from './views/configuration/CopyrightMessage' -import ContactRequests from './views/ContactRequests/ContactRequests' -import AddContactRequest from './views/ContactRequests/AddContactRequest' -import Testimonials from './views/Testimonials/Testimonials' -import AddTestimonial from './views/Testimonials/AddTestimonial' -import ViewTestimonial from './views/Testimonials/ViewTestimonial' -import Policies from './views/configuration/Policies/Policies' +import ApplicationName from "./views/configuration/ApplicationName"; +import CopyrightMessage from "./views/configuration/CopyrightMessage"; +import ContactRequests from "./views/ContactRequests/ContactRequests"; +import AddContactRequest from "./views/ContactRequests/AddContactRequest"; +import Testimonials from "./views/Testimonials/Testimonials"; +import AddTestimonial from "./views/Testimonials/AddTestimonial"; +import ViewTestimonial from "./views/Testimonials/ViewTestimonial"; +import Policies from "./views/configuration/Policies/Policies"; ////purpose -import Purpose from './views/configuration/Purpose/Purpose' -import AddPurpose from './views/configuration/Purpose/AddPurpose' +import Purpose from "./views/configuration/Purpose/Purpose"; +import AddPurpose from "./views/configuration/Purpose/AddPurpose"; //language -import Languages from './views/configuration/Language/Languages' -import AddLanguage from './views/configuration/Language/AddLanguage' -import EditLanguage from './views/configuration/Language/EditLanguage' +import Languages from "./views/configuration/Language/Languages"; +import AddLanguage from "./views/configuration/Language/AddLanguage"; +import EditLanguage from "./views/configuration/Language/EditLanguage"; //BusinessType -import BusinessType from './views/configuration/Business_Type/Business' -import AddBusinessType from './views/configuration/Business_Type/AddBusiness' -import EditBusinessType from './views/configuration/Business_Type/EditLanguage' -import EditPurpose from './views/configuration/Purpose/EditPurpose.js' +import BusinessType from "./views/configuration/Business_Type/Business"; +import AddBusinessType from "./views/configuration/Business_Type/AddBusiness"; +import EditBusinessType from "./views/configuration/Business_Type/EditLanguage"; +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"; const routes = [ - - { path: '/', exact: true, name: 'Home' }, - { path: '/change_password', name: 'Change Password', element: Change_Password }, - { path: '/profile/edit', name: 'Edit Profile', element: EditProfile }, + { path: "/", exact: true, name: "Home" }, + { + path: "/change_password", + name: "Change Password", + element: Change_Password, + }, + { path: "/profile/edit", name: "Edit Profile", element: EditProfile }, // { path: '/profile', name: 'Profile', element: Profile }, - //Product - { path: '/products', name: 'products', element: Products }, - { path: '/product/add', name: 'Add products', element: AddProduct }, - { path: '/product/edit/:id', name: 'Edit products', element: EditProduct }, - { path: '/product/view/:id', name: 'view products', element: ViewProduct }, + { path: "/products", name: "products", element: Products }, + { path: "/product/add", name: "Add products", element: AddProduct }, + { path: "/product/edit/:id", name: "Edit products", element: EditProduct }, + { path: "/product/view/:id", name: "view products", element: ViewProduct }, //Departure - { path: '/departures', name: 'Departures', element: Departures }, - { path: '/departure/add', name: 'Add Departure', element: AddDeparture }, - { path: '/product/edit/:id', name: 'Edit products', element: EditProduct }, - { path: '/product/view/:id', name: 'view products', element: ViewProduct }, - //Franchisee - { path: '/businesses', name: 'business', element: Businesses }, - { path: '/business/add', name: 'Add business', element: AddBusiness }, - { path: '/business/edit/:id', name: 'Edit business', element: EditBusiness }, + { path: "/departures", name: "Departures", element: Departures }, + { path: "/departure/add", name: "Add Departure", element: AddDeparture }, + { path: "/product/edit/:id", name: "Edit products", element: EditProduct }, + { path: "/product/view/:id", name: "view products", element: ViewProduct }, + + // Appointments + { path: "/appointments", name: "Appointments", element: Appointments }, + { + path: "/appointment/view/:id", + name: "View Appointment", + element: ViewAppointment, + }, + { + path: "/appointment/edit/:id", + name: "Edit Appointment", + element: EditAppointment, + }, + { + path: "/appointment/new", + name: "Add Appointment", + element: AddNewAppointment, + }, + + // health care providers + { + path: "//healthcare/providers", + name: "healthcare providers", + element: Businesses, + }, + { + path: "//healthcare/providers/add", + name: "Add healthcare providers", + element: AddBusiness, + }, + { + path: "/healthcare/providers/edit/:id", + name: "Edit healthcare providers", + element: EditBusiness, + }, + // { path: '/franchisee/view/:id', name: 'view franchisee', element: ViewFra }, //Contact Requests - { path: '/contact/request', name: 'Contact Requests', element: ContactRequests }, - { path: '/contact/request/new', name: 'AddContact Request', element: AddContactRequest }, + { + path: "/contact/request", + name: "Contact Requests", + element: ContactRequests, + }, + { + path: "/contact/request/new", + name: "AddContact Request", + element: AddContactRequest, + }, // { path: '/complaint/view/:id', name: 'view Complain', element: ViewComplaint }, //Complaints - { path: '/testimonials', name: 'Testimonials', element: Testimonials }, - { path: '/testimonial/new', name: 'AddTestimonial', element: AddTestimonial }, - { path: '/testimonial/view/:id', name: 'ViewTestimonial', element: ViewTestimonial }, + { path: "/testimonials", name: "Testimonials", element: Testimonials }, + { path: "/testimonial/new", name: "AddTestimonial", element: AddTestimonial }, + { + path: "/testimonial/view/:id", + name: "ViewTestimonial", + element: ViewTestimonial, + }, //informations - { path: '/informations', name: 'Informations', element: Informations }, - { path: '/information/new', name: 'Add Informations', element: AddInformations }, + { path: "/informations", name: "Informations", element: Informations }, + { + path: "/information/new", + name: "Add Informations", + element: AddInformations, + }, //Order Management - - { path: '/orders/new', name: 'New Orders', element: NewOrders }, - { path: '/order/add', name: 'add Order', element: AddOrder }, - { path: '/orders/edit/:id', name: 'Edit Order', element: EditOrder }, - { path: '/orders/view/:id', name: 'View Order', element: ViewOrders }, + { path: "/orders/new", name: "New Orders", element: NewOrders }, + { path: "/order/add", name: "add Order", element: AddOrder }, + { path: "/orders/edit/:id", name: "Edit Order", element: EditOrder }, + { path: "/orders/view/:id", name: "View Order", element: ViewOrders }, // { path: '/orders/processing', name: 'Processing Orders', element: ProcessingOrders }, // { path: '/orders/dispatched', name: 'Dispatched Orders', element: DispatchedOrders }, // { path: '/orders/delivered', name: 'Delivered Orders', element: DeliveredOrders }, // { path: '/orders/cancelled', name: 'Cancelled Orders', element: CancelledOrders }, // { path: '/orders/returned', name: 'Returned Orders', element: ReturnedOrders }, - { path: '/order/:status/:id', name: 'View Order', element: ViewOrder }, - - - + { path: "/order/:status/:id", name: "View Order", element: ViewOrder }, //dashboard - { path: '/dashboard', name: 'Dashboard', element: Dashboard }, + { path: "/dashboard", name: "Dashboard", element: Dashboard }, //------------settings------------------------// - { path: '/policies', name: 'Policies', element: Policies }, + { path: "/policies", name: "Policies", element: Policies }, - { path: '/socialmedia', name: 'Social Media', element: Socialmedia }, - { path: '/purpose', name: 'Purpose', element: Purpose }, - { path: '/purpose/add', name: 'Add Purpose', element: AddPurpose }, + { path: "/socialmedia", name: "Social Media", element: Socialmedia }, + { path: "/purpose", name: "Purpose", element: Purpose }, + { path: "/purpose/add", name: "Add Purpose", element: AddPurpose }, //languge - { path: '/languages', name: 'languages', element: Languages }, - { path: '/language/add', name: 'Add languages', element: AddLanguage }, - { path: '/language/edit/:id', name: 'Edit languages', element: EditLanguage }, + { path: "/languages", name: "languages", element: Languages }, + { path: "/language/add", name: "Add languages", element: AddLanguage }, + { path: "/language/edit/:id", name: "Edit languages", element: EditLanguage }, //business Type - { path: '/business_type', name: 'business', element: BusinessType }, - { path: '/business_type/add', name: 'Add business', element: AddBusinessType }, - { path: '/business_type/edit/:id', name: 'Edit business', element: EditBusinessType }, + { path: "/business_type", name: "business", element: BusinessType }, + { + path: "/business_type/add", + name: "Add business", + element: AddBusinessType, + }, + { + path: "/business_type/edit/:id", + name: "Edit business", + element: EditBusinessType, + }, //purpose - { path: '/purpose', name: 'purpose', element: Purpose }, - { path: '/purpose/add', name: 'Add purpose', element: AddPurpose }, - { path: '/purpose/edit/:id', name: 'Edit purpose', element: EditPurpose }, + { path: "/purpose", name: "purpose", element: Purpose }, + { path: "/purpose/add", name: "Add purpose", element: AddPurpose }, + { path: "/purpose/edit/:id", name: "Edit purpose", element: EditPurpose }, //languge - { path: '/application/name', name: 'ApplicationName', element: ApplicationName }, - { path: '/copyright/message', name: 'Copyright Message', element: CopyrightMessage }, + { + path: "/application/name", + name: "ApplicationName", + element: ApplicationName, + }, + { + path: "/copyright/message", + name: "Copyright Message", + element: CopyrightMessage, + }, - - { path: '/address', name: 'Address', element: Address }, - { path: '/logo', name: 'Logo', element: Logo }, + { path: "/address", name: "Address", element: Address }, + { path: "/logo", name: "Logo", element: Logo }, //Taxes - { path: '/tax', name: 'Tax Rates', element: Tax }, - { path: '/tax/add', name: 'Add Tax', element: Addtax }, - { path: '/tax/edit/:id', name: 'Edit Tax', element: Edittax }, + { path: "/tax", name: "Tax Rates", element: Tax }, + { path: "/tax/add", name: "Add Tax", element: Addtax }, + { path: "/tax/edit/:id", name: "Edit Tax", element: Edittax }, // -------------------------------------------// - // +]; - -] - -export default routes +export default routes; diff --git a/src/scss/_custom.scss b/src/scss/_custom.scss index 4ad4f56..53c33f4 100644 --- a/src/scss/_custom.scss +++ b/src/scss/_custom.scss @@ -1,9 +1,23 @@ // Here you can add other styles -$a-tags: 'a, a:active, a:hover, a:visited'; +$a-tags: "a, a:active, a:hover, a:visited"; #{$a-tags} { - text-decoration: none; - } - .overflow-table { display: block; max-width: -moz-fit-content; max-width: fit-content; overflow-x: auto; white-space: nowrap; } - .edit_text{ - width: 22%; - } \ No newline at end of file + text-decoration: none; +} +.overflow-table { + display: block; + max-width: -moz-fit-content; + max-width: fit-content; + overflow-x: auto; + white-space: nowrap; +} +.edit_text { + width: 22%; +} + +.highlighted-row { + background-color: yellow; +} + +.past-row { + background-color: #f2f2f2; +} diff --git a/src/views/Appointments/AddNewAppointment.js b/src/views/Appointments/AddNewAppointment.js new file mode 100644 index 0000000..3688d30 --- /dev/null +++ b/src/views/Appointments/AddNewAppointment.js @@ -0,0 +1,397 @@ +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 { CFormSelect, CInputGroup } from "@coreui/react"; +import DatePicker from "react-datepicker"; + +import "react-datepicker/dist/react-datepicker.css"; + +const AddNewAppointment = () => { + const token = isAutheticated(); + const navigate = useNavigate(); + const [doctors, setDoctors] = useState([]); + const [data, setData] = useState({ + doctorId: "", + doctorName: "", + date: "", + time: "", + patientName: "", + patientPhone: "", + }); + + const [loading, setLoading] = useState(false); + + const getDoctors = () => { + axios + .get("/api/specialist/getall") + .then((res) => { + setDoctors(res.data.specialist); + }) + .catch((err) => { + swal("Error", "Could not get data", "error"); + }); + }; + + useEffect(() => { + getDoctors(); + }, []); + + // doctor options with placeholder select doctor + const doctorOptions = [ + ...doctors.map((doctor) => ({ + label: doctor.specialistName, + value: doctor._id, + })), + ]; + + // reusable to get weekdays from index and vice-versa + const weekdays = [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + ]; + const getWeekday = (index) => { + return weekdays[index]; + }; + const getWeekdayIndex = (day) => { + return weekdays.indexOf(day); + }; + + const [availableDays, setAvailableDays] = useState([]); + + const [filterDay, setFilterDay] = useState([]); + + const [perPatientTime, setPerPatientTime] = useState(); + + // handle doctor change + const handleDoctorChange = (e) => { + const doctorId = e.target.value; + const doctor = doctors.find((doctor) => doctor._id === doctorId); + //filter available days for selected Doctor + const availableDays = doctor.daysAvailable.filter( + (day) => day.available === true + ); + // filter day number with available days for Date picker + const filterDay = availableDays.map((day) => { + return getWeekdayIndex(day.label); + }); + setFilterDay(filterDay); + setPerPatientTime(doctor.perPatientTime); + setAvailableDays(availableDays); + setData((prev) => ({ + ...prev, + doctorId: doctorId, + doctorName: doctor.specialistName, + date: "", + time: "", + })); + }; + + // find selected day from available days + const findSelectedDay = (day) => { + const selectedDay = availableDays.filter((days) => days.label === day); + return selectedDay; + }; + + const [timeOptions, setTimeOptions] = useState([]); + + // create time options with label and value from timeSlots array + // const createTimeOptions = (timeSlots, patientTime) => { + // // create time interval of perPatientTime min from start time to end time and push it to timeOptions array with label and value + // }; + + const createTimeOptions = (timeSlots, patientTime) => { + const timeOptions = []; + + timeSlots.forEach((timeSlot) => { + const startTime = new Date(`January 1, 2022 ${timeSlot.startTime}`); + const endTime = new Date(`January 1, 2022 ${timeSlot.endTime}`); + + // Create time intervals of 'patientTime' minutes from start time to end time + let intervalTime = startTime; + while (intervalTime < endTime) { + const intervalEnd = new Date( + intervalTime.getTime() + patientTime * 60000 + ); + const timeLabel = `${intervalTime.toLocaleTimeString([], { + hour: "2-digit", + minute: "2-digit", + })} - ${intervalEnd.toLocaleTimeString([], { + hour: "2-digit", + minute: "2-digit", + })}`; + const timeValue = intervalTime.toISOString(); + timeOptions.push({ label: timeLabel, value: timeValue }); + intervalTime = intervalEnd; + } + }); + + return timeOptions; + }; + + // handle date change + const handleDateChange = async (date) => { + const day = getWeekday(date.getDay()); + const selectedDay = findSelectedDay(day); + + const timeOptions = await createTimeOptions( + selectedDay[0].timeSlots, + perPatientTime + ); + await setTimeOptions(timeOptions); + setData((prev) => ({ + ...prev, + date: date, + time: "", + })); + }; + + // 0 + // : + // endTime + // : + // "20:39" + // startTime + // : + // "18:37" + // _id + // : + // "642a9679d243d8ac7d51fa75 + + const handleChange = (e) => { + setData((prev) => ({ ...prev, [e.target.id]: e.target.value })); + }; + + const handleSubmit = () => { + if ( + data.doctorName.trim() === "" || + data.date === "" || + data.time === "" || + data.patientName.trim() === "" || + data.patientPhone.trim() === "" + ) { + swal({ + title: "Warning", + text: "Fill all mandatory fields", + icon: "error", + button: "Close", + dangerMode: true, + }); + return; + } + setLoading(true); + const formData = new FormData(); + formData.set("doctorId", data.doctorId); + formData.set("doctorName", data.doctorName); + formData.set("date", data.date); + formData.set("time", data.time); + formData.set("patientName", data.patientName); + formData.set("patientPhone", data.patientPhone); + + axios + .post(`/api/appointment/new/`, formData, { + headers: { + Authorization: `Bearer ${token}`, + "Content-Type": "multipart/formdata", + "Access-Control-Allow-Origin": "*", + }, + }) + .then((res) => { + swal({ + title: "Added", + text: "appointment added successfully!", + icon: "success", + button: "ok", + }); + setLoading(false); + navigate("/appointments", { 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 ( +
+
+
+
+
+ New Appointment +
+
+

+
+ +
+ + + + +
+
+
+
+
+
+
+
+
+ + + +
+ + {data.doctorId && ( +
+ + handleDateChange(e)} + dateFormat="dd/MM/yyyy" + minDate={new Date()} + placeholderText="Select a date" + filterDate={(date) => { + return filterDay.includes(date.getDay()); + }} + /> +
+ )} + + {data.date && ( +
+ + +
+ )} + +
+ + handleChange(e)} + > + {data.patientName ? ( + <> + + {100 - data.patientName.length} characters left + + + ) : ( + <> + )} +
+
+ + handleChange(e)} + > +
+
+
+
+
+
+ ); +}; + +export default AddNewAppointment; diff --git a/src/views/Appointments/Appointments.js b/src/views/Appointments/Appointments.js new file mode 100644 index 0000000..55a2046 --- /dev/null +++ b/src/views/Appointments/Appointments.js @@ -0,0 +1,507 @@ +import axios from "axios"; +import React from "react"; +import { useEffect } from "react"; +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { isAutheticated } from "../../auth"; +import Button from "@material-ui/core/Button"; +import { Link } from "@material-ui/core"; +import { + DataGrid, + GridCellProps, + GridRenderCellParams, +} from "@material-ui/data-grid"; +import CIcon from "@coreui/icons-react"; +import { cilTrash } from "@coreui/icons"; + +const Appointments = () => { + const token = isAutheticated(); + const navigate = useNavigate(); + const [loading, setLoading] = useState(true); + const [success, setSuccess] = useState(true); + const [AppointmentData, setAppointmentData] = useState([]); + + const [currentPage, setCurrentPage] = useState(1); + const [itemPerPage, setItemPerPage] = useState(10); + const [showData, setShowData] = useState(AppointmentData); + + const handleShowEntries = (e) => { + setCurrentPage(1); + setItemPerPage(e.target.value); + }; + + const getAppointmentData = async () => { + axios + .get(`/api/appointment/getAll/`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }) + .then((res) => { + // convert date from utc to local + + const appointments = res.data.appointments; + + appointments.forEach((item) => { + //convert date from utc to local and make it in dd/mm/yyyy format month is in short form like jan,feb and add 0 before single digit date like 01,02 + item.date = new Date(item.date).toLocaleDateString("en-IN", { + day: "numeric", + month: "short", + year: "numeric", + }); + + // add leading zeros to single digit dates + item.date = item.date.replace( + /(\d{1,2})\s(\w{3})\s(\d{4})/, + function (match, day, month, year) { + return `${day.padStart(2, "0")} ${month} ${year}`; + } + ); + + //convert time from utc to local till minutes + item.time = new Date(item.time).toLocaleTimeString("en-IN", { + hour: "2-digit", + minute: "2-digit", + }); + }); + + // sort by date + // appointments.sort((a, b) => { + // return new Date(b.date) - new Date(a.date); + // }); + + // sort by date in descending order + appointments.sort((a, b) => { + const dateA = new Date(a.date); + const dateB = new Date(b.date); + return dateB.getTime() - dateA.getTime(); + }); + + setAppointmentData(appointments); + + setLoading(false); + }) + + .catch((err) => { + setLoading(false); + }); + }; + + // create columns for data grid table from appointment data + const columns = [ + { + field: "doctorName", + headerName: "Doctor Name", + minWidth: 180, + flex: 1, + editable: false, + }, + { + field: "patientName", + headerName: "Patient Name", + minWidth: 150, + flex: 1, + editable: false, + }, + { + field: "patientPhone", + headerName: "Patient Phone", + minWidth: 150, + flex: 1, + editable: false, + }, + { + field: "date", + headerName: "Date", + minWidth: 120, + flex: 1, + editable: false, + }, + { + field: "time", + headerName: "Time", + minWidth: 110, + flex: 1, + editable: false, + }, + + { + field: "action", + headerName: "Action", + minWidth: 180, + flex: 1, + // view edit and delete + renderCell: (params) => { + return ( +
+ +
+ ); + }, + }, + ]; + + useEffect(() => { + getAppointmentData(); + }, [success]); + + useEffect(() => { + const loadData = () => { + const indexOfLastPost = currentPage * itemPerPage; + const indexOfFirstPost = indexOfLastPost - itemPerPage; + setShowData(AppointmentData.slice(indexOfFirstPost, indexOfLastPost)); + }; + loadData(); + }, [currentPage, itemPerPage, AppointmentData]); + + // create rows for data grid table from appointment data + const rows = showData.map((item, index) => { + return { + id: index + 1, + appointmentNumber: item.appointmentNumber, + _id: item._id, + doctorName: item.doctorName, + date: item.date, + time: item.time, + patientName: item.patientName, + patientPhone: item.patientPhone, + }; + }); + + const handleDelete = (id) => { + swal({ + title: "Are you sure?", + icon: "error", + buttons: { + Yes: { text: "Yes", value: true }, + Cancel: { text: "Cancel", value: "cancel" }, + }, + }).then((value) => { + if (value === true) { + axios + .delete(`/api/appointment/delete/${id}`, { + headers: { + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + }) + .then((res) => { + swal({ + title: "Success", + text: "Appointment deleted successfully!", + icon: "success", + button: "Ok", + }); + setSuccess((prev) => !prev); + }) + .catch((err) => { + swal({ + title: "Warning", + text: "Something went wrong!", + icon: "error", + button: "Retry", + dangerMode: true, + }); + }); + } + }); + }; + + const handleView = (id) => { + navigate(`/appointment/view/${id}`); + }; + + const handleEdit = (id) => { + navigate(`/appointment/edit/${id}`); + }; + + const handleSearch = (e) => { + const searchValue = e.target.value; + const filteredData = AppointmentData.filter((item) => { + return ( + item.appointmentNumber + .toLowerCase() + .includes(searchValue.toLowerCase()) || + item.doctorName.toLowerCase().includes(searchValue.toLowerCase()) || + item.patientName.toLowerCase().includes(searchValue.toLowerCase()) || + item.patientPhone.toLowerCase().includes(searchValue.toLowerCase()) || + item.date.toLowerCase().includes(searchValue.toLowerCase()) + ); + }); + setShowData(filteredData); + }; + + // const handlePageChange = (e, page) => { + // setCurrentPage(page); + // }; + + function compareDates(a, b) { + const dateA = new Date(a.date); + const dateB = new Date(b.date); + if (dateA < dateB) { + return -1; + } + if (dateA > dateB) { + return 1; + } + return 0; + } + + const initialSortModel = [ + { + field: "date", + sort: "asc", + }, + ]; + + const getRowClassName = (params) => { + // get row date and current date in same format and compare + const rowDate = new Date(params.row.date); + const currentDate = new Date().setHours(0, 0, 0, 0); + + if (rowDate < currentDate) { + return "past-row"; + } + + // if (params.row.id === 2) { + // return "highlighted-row"; + // } + return ""; + }; + + return ( +
+
+
+
+
+
+
+ Appointments +
+ + {/*
+ +
+ */} +
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+ + {!loading ? ( +
+
+
+ +
+
+
+ ) : null} + +
+ "auto"} + columns={columns} + rows={rows} + pageSize={itemPerPage} + rowCount={AppointmentData.length} + className="table-responsive" + getRowClassName={getRowClassName} + sx={{ + "& .MuiDataGrid-cell": { + display: "block", + }, + ".MuiDataGrid-root .MuiDataGrid-cell": { + whiteSpace: "normal", + wordWrap: "breakWord", + }, + }} + initialState={{ + ...rows.initialState, + sorting: { + ...rows.initialState?.sorting, + sortModel: [ + { + field: "date", + sort: "desc", + }, + ], + sortComparator: { compareDates }, + }, + }} + {...rows} + /> +
+ +
+
+
+ Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "} + {Math.min( + currentPage * itemPerPage, + AppointmentData.length + )}{" "} + of {AppointmentData.length} entries +
+
+ +
+
+
    +
  • + setCurrentPage((prev) => prev - 1)} + > + Previous + +
  • + + {!(currentPage - 1 < 1) && ( +
  • + + setCurrentPage((prev) => prev - 1) + } + > + {currentPage - 1} + +
  • + )} + +
  • + + {currentPage} + +
  • + + {!( + (currentPage + 1) * itemPerPage - itemPerPage > + AppointmentData.length - 1 + ) && ( +
  • + { + setCurrentPage((prev) => prev + 1); + }} + > + {currentPage + 1} + +
  • + )} + +
  • + AppointmentData.length - 1 + ) + ? "paginate_button page-item next" + : "paginate_button page-item next disabled" + } + > + setCurrentPage((prev) => prev + 1)} + > + Next + +
  • +
+
+
+
+
+
+
+
+
+
+
+ ); +}; + +export default Appointments; diff --git a/src/views/Appointments/EditAppointment.js b/src/views/Appointments/EditAppointment.js new file mode 100644 index 0000000..533f085 --- /dev/null +++ b/src/views/Appointments/EditAppointment.js @@ -0,0 +1,443 @@ +import React, { useEffect, useState } from "react"; +import Button from "@material-ui/core/Button"; +import { Link, useNavigate, useParams } from "react-router-dom"; +import swal from "sweetalert"; +import axios from "axios"; +import { isAutheticated } from "src/auth"; +import { CFormSelect, CInputGroup } from "@coreui/react"; +import DatePicker from "react-datepicker"; + +import "react-datepicker/dist/react-datepicker.css"; + +const EditAppointment = () => { + const token = isAutheticated(); + const navigate = useNavigate(); + const [doctors, setDoctors] = useState([]); + const [data, setData] = useState({ + doctorId: "", + doctorName: "", + date: "", + time: "", + patientName: "", + patientPhone: "", + }); + + const [loading, setLoading] = useState(false); + + const getDoctors = () => { + axios + .get("/api/specialist/getall") + .then((res) => { + setDoctors(res.data.specialist); + }) + .catch((err) => { + swal("Error", "Could not get data", "error"); + }); + }; + + useEffect(() => { + getDoctors(); + }, []); + + // doctor options with placeholder select doctor + const doctorOptions = [ + ...doctors.map((doctor) => ({ + label: doctor.specialistName, + value: doctor._id, + })), + ]; + + // reusable to get weekdays from index and vice-versa + const weekdays = [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + ]; + const getWeekday = (index) => { + return weekdays[index]; + }; + const getWeekdayIndex = (day) => { + return weekdays.indexOf(day); + }; + + const [availableDays, setAvailableDays] = useState([]); + + const [filterDay, setFilterDay] = useState([]); + + const [perPatientTime, setPerPatientTime] = useState(); + + const [currentAppointment, setCurrentAppointment] = useState({}); + + const { id } = useParams(); + + // get appointment by id + const getAppointment = () => { + setLoading(true); + axios + .get(`/api/appointment/get/${id}`) + .then((res) => { + const appointment = res.data.appointment; + + appointment.date = new Date(appointment.date).toISOString("en-IN"); + appointment.time = new Date(appointment.time).toLocaleTimeString( + "en-IN", + { + hour: "2-digit", + minute: "2-digit", + } + ); + + setCurrentAppointment(appointment); + setLoading(false); + }) + .catch((err) => { + swal("Error", "Could not get data", "error"); + setLoading(false); + }); + }; + + useEffect(() => { + getAppointment(); + }, []); + + useEffect(() => { + setData((prev) => ({ + ...prev, + //doctorId: currentAppointment.doctorId, + //doctorName: currentAppointment.doctorName, + //date: currentAppointment.date, + ///time: currentAppointment.time, + patientName: currentAppointment.patientName, + patientPhone: currentAppointment.patientPhone, + })); + }, [currentAppointment]); + + // handle doctor change + const handleDoctorChange = (e) => { + const doctorId = e.target.value; + const doctor = doctors.find((doctor) => doctor._id === doctorId); + //filter available days for selected Doctor + const availableDays = doctor.daysAvailable.filter( + (day) => day.available === true + ); + // filter day number with available days for Date picker + const filterDay = availableDays.map((day) => { + return getWeekdayIndex(day.label); + }); + setFilterDay(filterDay); + setPerPatientTime(doctor.perPatientTime); + setAvailableDays(availableDays); + setData((prev) => ({ + ...prev, + doctorId: doctorId, + doctorName: doctor.specialistName, + date: "", + time: "", + })); + }; + + // find selected day from available days + const findSelectedDay = (day) => { + const selectedDay = availableDays.filter((days) => days.label === day); + return selectedDay; + }; + + const [timeOptions, setTimeOptions] = useState([]); + + // create time options with label and value from timeSlots array + // const createTimeOptions = (timeSlots, patientTime) => { + // // create time interval of perPatientTime min from start time to end time and push it to timeOptions array with label and value + // }; + + const createTimeOptions = (timeSlots, patientTime) => { + const timeOptions = []; + + timeSlots.forEach((timeSlot) => { + const startTime = new Date(`January 1, 2022 ${timeSlot.startTime}`); + const endTime = new Date(`January 1, 2022 ${timeSlot.endTime}`); + + // Create time intervals of 'patientTime' minutes from start time to end time + let intervalTime = startTime; + while (intervalTime < endTime) { + const intervalEnd = new Date( + intervalTime.getTime() + patientTime * 60000 + ); + const timeLabel = `${intervalTime.toLocaleTimeString([], { + hour: "2-digit", + minute: "2-digit", + })} - ${intervalEnd.toLocaleTimeString([], { + hour: "2-digit", + minute: "2-digit", + })}`; + const timeValue = intervalTime.toISOString(); + timeOptions.push({ label: timeLabel, value: timeValue }); + intervalTime = intervalEnd; + } + }); + + return timeOptions; + }; + + // handle date change + const handleDateChange = async (date) => { + const day = getWeekday(date.getDay()); + const selectedDay = findSelectedDay(day); + + const timeOptions = await createTimeOptions( + selectedDay[0].timeSlots, + perPatientTime + ); + await setTimeOptions(timeOptions); + setData((prev) => ({ + ...prev, + date: date, + time: "", + })); + }; + + // 0 + // : + // endTime + // : + // "20:39" + // startTime + // : + // "18:37" + // _id + // : + // "642a9679d243d8ac7d51fa75 + + const handleChange = (e) => { + setData((prev) => ({ ...prev, [e.target.id]: e.target.value })); + }; + + const handleSubmit = () => { + if ( + data.doctorName.trim() === "" || + data.date === "" || + data.time === "" || + data.patientName.trim() === "" || + data.patientPhone.trim() === "" + ) { + swal({ + title: "Warning", + text: "Fill all mandatory fields", + icon: "error", + button: "Close", + dangerMode: true, + }); + return; + } + setLoading(true); + const formData = new FormData(); + formData.set("doctorId", data.doctorId); + formData.set("doctorName", data.doctorName); + formData.set("date", data.date); + formData.set("time", data.time); + formData.set("patientName", data.patientName); + formData.set("patientPhone", data.patientPhone); + + axios + .patch(`/api/appointment/update/${id}`, formData, { + headers: { + Authorization: `Bearer ${token}`, + "Content-Type": "multipart/formdata", + "Access-Control-Allow-Origin": "*", + }, + }) + .then((res) => { + swal({ + title: "Updated", + text: "appointment updated successfully!", + icon: "success", + button: "ok", + }); + setLoading(false); + navigate("/appointments", { 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 Appointment +
+
+

+
+ +
+ + + + +
+
+
+
+
+
+
+
+
+ + + +
+ + {data.doctorId && ( +
+ + handleDateChange(e)} + dateFormat="dd/MM/yyyy" + minDate={new Date()} + placeholderText="Select a date" + filterDate={(date) => { + return filterDay.includes(date.getDay()); + }} + /> +
+ )} + + {data.date && ( +
+ + +
+ )} + +
+ + handleChange(e)} + > + {data.patientName ? ( + <> + + {100 - data.patientName.length} characters left + + + ) : ( + <> + )} +
+
+ + handleChange(e)} + > +
+
+
+
+
+
+ ); +}; + +export default EditAppointment; diff --git a/src/views/Appointments/ViewAppointment.js b/src/views/Appointments/ViewAppointment.js new file mode 100644 index 0000000..ddd0079 --- /dev/null +++ b/src/views/Appointments/ViewAppointment.js @@ -0,0 +1,153 @@ +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"; + +const ViewAppointment = () => { + const [appointmentData, setAppointmentData] = useState(); + + const [loading, setLoading] = useState(false); + + const { id } = useParams(); + + const getAppointment = () => { + setLoading(true); + axios + .get(`/api/appointment/get/${id}`) + .then(async (res) => { + res.data.appointment.date = await new Date( + res.data.appointment?.date + ).toLocaleDateString("en-IN", { + day: "numeric", + month: "short", + year: "numeric", + }); + + // add leading zeros to single digit dates + res.data.appointment.date = await res.data.appointment.date.replace( + /(\d{1,2})\s(\w{3})\s(\d{4})/, + function (match, day, month, year) { + return `${day.padStart(2, "0")} ${month} ${year}`; + } + ); + setAppointmentData(res.data.appointment); + setLoading(false); + }) + .catch((err) => { + swal("Error", "Could not get data", "error"); + setLoading(false); + }); + }; + + useEffect(() => { + getAppointment(); + }, []); + + const navigate = useNavigate(); + + return ( +
+
+
+
+ Appointment +
+ +
+ +
+
+
+ + {loading &&
Loading...
} + {!loading && !appointmentData &&
No data found
} + {!loading && appointmentData && ( +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Appointment ID{appointmentData?._id}
Appointment Number{appointmentData?.appointmentNumber}
Patient Name{appointmentData?.patientName}
Patient Phone{appointmentData?.patientPhone}
Doctor Name{appointmentData?.doctorName}
Appointment Date + {appointmentData?.date ? ( + appointmentData?.date + ) : ( + Not Set + )} +
Appointment Time + {new Date(appointmentData?.time).toLocaleTimeString("en-IN", { + hour: "2-digit", + minute: "2-digit", + })}{" "} +
Appointment Created + {new Date(appointmentData?.createdAt).toLocaleDateString( + "en-IN", + { + day: "numeric", + month: "short", + year: "numeric", + + hour: "2-digit", + minute: "2-digit", + } + )} +
+
+ )} +
+ ); +}; + +export default ViewAppointment; diff --git a/src/views/Business/AddBusiness.js b/src/views/Business/AddBusiness.js index 45d7846..bac05de 100644 --- a/src/views/Business/AddBusiness.js +++ b/src/views/Business/AddBusiness.js @@ -1,316 +1,345 @@ -import React, { useState, useEffect } from 'react' +import React, { useState, useEffect } from "react"; // import { Button } from '@mui/material' -import axios from 'axios' +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 { 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 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 navigate = useNavigate() - const [loading, setLoading] = useState(false) + const [data, setData] = useState({ + WebsiteURL: "https://bolo.ai.in/", + business: "", + purpose: "", - 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: "", - language: [], - country: '', - state: '', - city: '', - address_Line_1: '', - address_Line_2: '', - pincode: '', - //contacts - image: '', - imageURL: '', - business_name: '', - email: '', + short_url: "", + contact_Number: "", + contact_Person_Name: "", - short_url: '', - contact_Number: '', - contact_Person_Name: '', - }) + specialization: "", + }); + // console.log(data) - - // console.log(data) - - const handleView = (n) => { - if (viewState === n) return - setViewState(n) + const handleView = (n) => { + if (viewState === n) return; + setViewState(n); + }; + 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.trim() === "" || + //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; } - const handleSubmit = () => { - if ( - data.address_Line_1.trim() === '' || - data.address_Line_2.trim() === '' || + setLoading(true); + const formData = new FormData(); + formData.set("address_Line_1", data.address_Line_1); + formData.set("address_Line_2", data.address_Line_2); - data.business === '' || - data.purpose.trim() === '' || - data.language === '' || - data.country === '' || - data.state === '' || - data.city === '' || - data.pincode.trim() === '' || - //Contacts - // data.image === '' || - // data.imageURL.trim() === '' || - data.business_name.trim() === '' || - data.email.trim() === '' || + formData.set("purpose", data.purpose); + formData.set("business", data.business); + formData.set("language", data.language); - data.short_url.trim() === '' || - data.contact_Number === '' || - data.contact_Person_Name.trim() === '' + formData.set("country", data.country); + formData.set("city", data.city); + formData.set("state", data.state); - ) { - 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("pincode", data.pincode); + //contacts + formData.set("business_name", data.business_name); + formData.set("email", data.email); - formData.set('purpose', data.purpose) - formData.set('business', data.business) - formData.set('language', data.language) + formData.set("contact_Number", data.contact_Number); + formData.set("contact_Person_Name", data.contact_Person_Name); - formData.set('country', data.country) - formData.set('city', data.city) - formData.set('state', data.state) + formData.set("specialization", data.specialization); + formData.set("url", data.WebsiteURL); + formData.set("short_url", data.short_url); - formData.set('pincode', data.pincode) - //contacts - formData.set('business_name', data.business_name) - formData.set('email', data.email) + 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("/healthcare/providers", { 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, + }); + }); + }; - - formData.set('contact_Number', data.contact_Number) - formData.set('contact_Person_Name', data.contact_Person_Name) - - - formData.set('url', data.WebsiteURL + data.short_url + '/login') - 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('/businesses', { 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 ( - - - -
+ +
-
- Add Business -
-
-
- +
+
+
+
+ + + + + + + {viewState === 1 && ( + + )} + {viewState === 2 && ( + + )} - }} - disabled={data.address_Line_1.trim() === '' || - data.address_Line_2.trim() === '' || + {viewState === 3 && + (data.business === "Doctor (Individual Practitioner)" ? ( + + ) : ( + + ))} - data.business === '' || - data.purpose.trim() === '' || - data.language === '' || - data.country === '' || - data.state === '' || - data.city === '' || - data.pincode.trim() === '' || - data.business_name.trim() === '' || - data.email.trim() === '' || + {viewState === 4 && ( + + )} + {viewState === 5 && ( + + )} + + + + + + + + +
+ + {/**/} + + + +
+
+
+
+
+
+ + ); +}; - data.short_url.trim() === '' || - data.contact_Number === '' || - data.contact_Person_Name.trim() === ''} - > - {loading ? 'Loading' : 'Add Now'} - -
- - -
-
- - - - - - {viewState === 1 && ( - - )} - {viewState === 2 && ( - - )} - - - - {viewState === 3 && ( - - )} - {viewState === 4 && ( - - )} - {viewState === 5 && ( - - )} - - - - - - - - -
- - - - - -
-
-
-
-
-
-
- ) -} - -export default AddBusiness \ No newline at end of file +export default AddBusiness; diff --git a/src/views/Business/Businesses.js b/src/views/Business/Businesses.js index 6ac463d..a9d2da9 100644 --- a/src/views/Business/Businesses.js +++ b/src/views/Business/Businesses.js @@ -1,243 +1,255 @@ - -import React, { useEffect } from 'react' -import Button from '@material-ui/core/Button' -import { useState } from 'react' -import { Link } from 'react-router-dom' -import axios from 'axios' -import swal from 'sweetalert' -import OverLayButton from './OverLayButton.js' -import { isAutheticated } from 'src/auth.js' +import React, { useEffect } from "react"; +import Button from "@material-ui/core/Button"; +import { useState } from "react"; +import { Link } from "react-router-dom"; +import axios from "axios"; +import swal from "sweetalert"; +import OverLayButton from "./OverLayButton.js"; +import { isAutheticated } from "src/auth.js"; const Businesses = () => { - const token = isAutheticated() - const [loading, setLoading] = useState(true) - const [success, setSuccess] = useState(true) - const [BusinessesData, setBusinessesData] = useState([]) + const token = isAutheticated(); + const [loading, setLoading] = useState(true); + const [success, setSuccess] = useState(true); + const [BusinessesData, setBusinessesData] = useState([]); - const [currentPage, setCurrentPage] = useState(1) - const [itemPerPage, setItemPerPage] = useState(10) - const [showData, setShowData] = useState(BusinessesData) + const [currentPage, setCurrentPage] = useState(1); + const [itemPerPage, setItemPerPage] = useState(10); + const [showData, setShowData] = useState(BusinessesData); - const handleShowEntries = (e) => { - setCurrentPage(1) - setItemPerPage(e.target.value) - } + const handleShowEntries = (e) => { + setCurrentPage(1); + setItemPerPage(e.target.value); + }; - const getbusinesses = () => { + const getbusinesses = () => { + axios + .get(`/api/businesses/getall`, { + headers: { + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + }) + .then((res) => { + console.log(res.data); + setBusinessesData(res.data?.businesses); + setLoading(false); + }) + .catch((err) => { + console.log(err); + setLoading(false); + }); + }; + + useEffect(() => { + getbusinesses(); + }, [success]); + + useEffect(() => { + const loadData = () => { + const indexOfLastPost = currentPage * itemPerPage; + const indexOfFirstPost = indexOfLastPost - itemPerPage; + setShowData(BusinessesData.slice(indexOfFirstPost, indexOfLastPost)); + }; + loadData(); + }, [currentPage, itemPerPage, BusinessesData]); + + // 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?", + icon: "error", + buttons: { + Yes: { text: "Yes", value: true }, + Cancel: { text: "Cancel", value: "cancel" }, + }, + }).then((value) => { + if (value === true) { axios - .get(`/api/businesses/getall`, { - headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` }, - }) - .then((res) => { - console.log(res.data) - setBusinessesData(res.data?.businesses) - setLoading(false) - }) - .catch((err) => { - console.log(err) - setLoading(false) - }) - } + .delete(`/api/businesses/delete/${id}`, { + headers: { + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + }) + .then((res) => { + setSuccess((prev) => !prev); + }) + .catch((err) => { + swal({ + title: "Warning", + text: "Something went wrong!", + icon: "error", + button: "Retry", + dangerMode: true, + }); + }); + } + }); + }; - useEffect(() => { - getbusinesses() - }, [success]) - - useEffect(() => { - const loadData = () => { - const indexOfLastPost = currentPage * itemPerPage - const indexOfFirstPost = indexOfLastPost - itemPerPage - setShowData(BusinessesData.slice(indexOfFirstPost, indexOfLastPost)) - } - loadData() - }, [currentPage, itemPerPage, BusinessesData]) - - - // 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?', - icon: 'error', - buttons: { Yes: { text: 'Yes', value: true }, Cancel: { text: 'Cancel', value: 'cancel' } }, - }).then((value) => { - if (value === true) { - axios - .delete(`/api/businesses/delete/${id}`, { - headers: { - 'Access-Control-Allow-Origin': '*', - Authorization: `Bearer ${token}`, - }, - }) - .then((res) => { - setSuccess((prev) => !prev) - }) - .catch((err) => { - swal({ - title: 'Warning', - text: 'Something went wrong!', - icon: 'error', - button: 'Retry', - dangerMode: true, - }) - }) - } - }) - } - - return ( -
-
-
-
-
-
+
+
+
+
+
-
- Businesses -
+ > +
+ Health Care Providers +
-
- - - -
-
-
-
-
-
-
-
-
-
-
- -
-
-
+ > + + + + + + entries + +
+
+
-
- - - - - {/* */} - - - {/* */} - - - - - {!loading && showData.length === 0 && ( - - - - )} - {loading ? ( - - - - ) : ( - showData.map((i, idx) => { - return ( - - - {/* {i.banner && i.banner ? +
+
Business LogoPurpose Created OnStatusActions
-
No Data Available
-
- Loading... -
{i.business}
+ + + + {/* */} + + + {/* */} + + + + + {console.log(showData, "showData")} + + {!loading && showData.length === 0 && ( + + + + )} + {loading ? ( + + + + ) : ( + showData.map((i, idx) => { + return ( + + + {/* {i.banner && i.banner ? :

No image!

} */} - + - - {/* + {/* */} - - - ) - }) - )} - -
HealthCare Provider LogoName Created OnStatusActions
+
No Data Available
+
+ Loading... +
{i.business} No Image {i?.purpose}{i?.short_url} - {new Date(i.createdAt).toLocaleString('en-IN', { - month: '2-digit', - day: 'numeric', - year: 'numeric', - // hour: 'numeric', - // minute: 'numeric', - // hour12: true, - })} - + + {new Date(i.createdAt).toLocaleString( + "en-IN", + { + month: "2-digit", + day: "numeric", + year: "numeric", + // hour: 'numeric', + // minute: 'numeric', + // hour12: true, + } + )} + - {/* + + {/* */} - - - - -
-
+ onClick={() => { + handleDelete(i._id); + }} + > + Delete + + + + ); + }) + )} + + +
-
-
-
- Showing {currentPage * itemPerPage - itemPerPage + 1} to{' '} - {Math.min(currentPage * itemPerPage, BusinessesData.length)} of{' '} - {BusinessesData.length} entries -
-
- -
-
-
    -
  • - setCurrentPage((prev) => prev - 1)} - > - Previous - -
  • - - {!(currentPage - 1 < 1) && ( -
  • - setCurrentPage((prev) => prev - 1)} - > - {currentPage - 1} - -
  • - )} - -
  • - - {currentPage} - -
  • - - {!( - (currentPage + 1) * itemPerPage - itemPerPage > - BusinessesData.length - 1 - ) && ( -
  • - { - setCurrentPage((prev) => prev + 1) - }} - > - {currentPage + 1} - -
  • - )} - -
  • - BusinessesData.length - 1 - ) - ? 'paginate_button page-item next' - : 'paginate_button page-item next disabled' - } - > - setCurrentPage((prev) => prev + 1)} - > - Next - -
  • -
-
-
-
-
-
-
+
+
+
+ Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "} + {Math.min( + currentPage * itemPerPage, + BusinessesData.length + )}{" "} + of {BusinessesData.length} entries +
-
-
-
- ) -} -export default Businesses +
+
+
    +
  • + setCurrentPage((prev) => prev - 1)} + > + Previous + +
  • + + {!(currentPage - 1 < 1) && ( +
  • + + setCurrentPage((prev) => prev - 1) + } + > + {currentPage - 1} + +
  • + )} + +
  • + + {currentPage} + +
  • + + {!( + (currentPage + 1) * itemPerPage - itemPerPage > + BusinessesData.length - 1 + ) && ( +
  • + { + setCurrentPage((prev) => prev + 1); + }} + > + {currentPage + 1} + +
  • + )} + +
  • + BusinessesData.length - 1 + ) + ? "paginate_button page-item next" + : "paginate_button page-item next disabled" + } + > + setCurrentPage((prev) => prev + 1)} + > + Next + +
  • +
+
+
+
+
+
+ + + + + + ); +}; + +export default Businesses; diff --git a/src/views/Business/EditBusiness.js b/src/views/Business/EditBusiness.js index 2e527fe..96ad216 100644 --- a/src/views/Business/EditBusiness.js +++ b/src/views/Business/EditBusiness.js @@ -1,342 +1,367 @@ -import React, { useState, useEffect } from 'react' +import React, { useState, useEffect } from "react"; // import { Button } from '@mui/material' -import axios from 'axios' +import axios from "axios"; -import { Link, useNavigate, useParams } from 'react-router-dom' -import { CCard, CCardBody, CCardGroup, CCol, CContainer, CRow } from '@coreui/react' +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 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 token = isAutheticated(); + const id = useParams()?.id; + const [productId, setProductId] = useState(""); + const [viewState, setViewState] = useState(1); + const navigate = useNavigate(); + const [loading, setLoading] = useState(false); - const navigate = useNavigate() - const [loading, setLoading] = useState(false) + const [data, setData] = useState({ + WebsiteURL: "https://bolo.ai.in/", + business: "", + purpose: "", - 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: "", - language: [], - country: '', - state: '', - city: '', - address_Line_1: '', - address_Line_2: '', - pincode: '', - //contacts - image: '', - imageURL: '', - business_name: '', - email: '', + short_url: "", + contact_Number: "", + contact_Person_Name: "", - short_url: '', - contact_Number: '', - contact_Person_Name: '', - }) + specialization: "", + }); + // console.log(data) + const handleView = (n) => { + if (viewState === n) return; + setViewState(n); + }; - // console.log(data) + //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); + }) - const handleView = (n) => { - if (viewState === n) return - setViewState(n) + .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); - //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) - }) + 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); - .catch((err) => { - console.log(err) - setLoading(false) - }) - } + formData.set("pincode", data.pincode); + //contacts + formData.set("business_name", data.business_name); + formData.set("email", data.email); - useEffect(() => { - getbusinesses() - }, []) - // console.log(data) - const handleSubmit = () => { - if ( - data.address_Line_1.trim() === '' || - data.address_Line_2.trim() === '' || + formData.set("contact_Number", data.contact_Number); + formData.set("contact_Person_Name", data.contact_Person_Name); - data.business === '' || - data.purpose.trim() === '' || - data.language === '' || - data.country === '' || - data.state === '' || - data.city === '' || - data.pincode === '' || - //Contacts - // data.image === '' || - // data.imageURL.trim() === '' || - data.business_name.trim() === '' || - data.email.trim() === '' || + formData.set("specialization", data.specialization); - 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("url", data.WebsiteURL); + formData.set("short_url", data.short_url); - formData.set('purpose', data.purpose) - formData.set('business', data.business) - formData.set('language', data.language) + 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("/healthcare/providers", { 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, + }); + }); + }; - 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('url', data.WebsiteURL + data.short_url + '/login') - 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('/businesses', { 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 Business -
-
-
- +
+
+
+
+ + + + + + + {viewState === 1 && ( + + )} - }} - disabled={data.address_Line_1.trim() === '' || - data.address_Line_2.trim() === '' || + {/*viewState === 2 && ( + + )*/} - data.business === '' || - data.purpose.trim() === '' || - data.language === '' || - data.country === '' || - data.state === '' || - data.city === '' || - data.pincode === '' || - data.business_name.trim() === '' || - data.email.trim() === '' || + {viewState === 3 && + (data.business === "Doctor (Individual Practitioner)" ? ( + + ) : ( + + ))} - data.short_url.trim() === '' || - data.contact_Number === '' || - data.contact_Person_Name.trim() === ''} - > - {loading ? 'Loading' : 'Update Now'} - -
- - -
-
- - - - - - {viewState === 1 && ( - - )} - {viewState === 2 && ( - + )} + {viewState === 5 && ( + + )} + + + + + + + + +
+ - // productId={productId} - // data={{ varients, setVarients }} - // taxes={taxes} - // sizes={sizes} - loading={{ loading, setLoading }} - /> - )} - {viewState === 3 && ( - - )} - {viewState === 4 && ( - handleView(3)} + > + Contacts + + + +
+
+
+
+
+
+
+ ); +}; - // productId={productId} - // data={{ images, setImages }} - loading={{ loading, setLoading }} - /> - )} - {viewState === 5 && ( - - )} - - - - - - - - -
- - - - - -
-
-
-
-
- - - ) -} - -export default EditBusiness \ No newline at end of file +export default EditBusiness; diff --git a/src/views/Business/multiform/Contacts.js b/src/views/Business/multiform/Contacts.js index 869d482..e09a0f9 100644 --- a/src/views/Business/multiform/Contacts.js +++ b/src/views/Business/multiform/Contacts.js @@ -1,278 +1,272 @@ - - - -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 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' const Contacts = (props) => { - const token = isAutheticated() + const token = isAutheticated(); - const navigate = useNavigate() + const navigate = useNavigate(); - const { data, setData } = props.data + const { data, setData } = props.data; - const { loading, setLoading } = props.loading - // const [data, setData] = useState({ - // image: '', - // imageURL: '', - // name: '', - // email: '', + const { loading, setLoading } = props.loading; + // const [data, setData] = useState({ + // image: '', + // imageURL: '', + // name: '', + // email: '', - // short_url: '', - // contact_Number: '', - // contact_Person_Name: '', + // 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 [validForm, setValidForm] = useState(false) + 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 === "business_name") { + if (e.target.value.length < 0) return; - - 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 + setData((prev) => ({ + ...prev, + short_url: e.target.value.toLowerCase().replace(/\s+/g, "-"), + })); } - //cheking email and password - useEffect(() => { - if (validateForm()) { - setValidForm(true) - } else { - setValidForm(false) - } - }, [errors]) - - - const handleChange = (e) => { - if (e.target.id === 'business_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 })) + 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 ( -
-
-
-
+
+
+
-
- Contacts -
-
-

-
- -
- - - - -
-
-
+ > +
+ Contact Information +
+
+

-
-
-
-
-
- - 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}

- )} -
-
- - handleChange(e)} - /> -
-
- -
- - {data.WebsiteURL} - - handleChange(e)} - /> -
-
+
+ + +
+
+
+
+
+
+
+
+
+ + 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} +

+ )} +
+
+ + handleChange(e)} + /> +
- {/*
+ {/*
+ +
+ + {data.WebsiteURL} + + handleChange(e)} + /> +
+
*/} + + {/*
@@ -292,18 +286,12 @@ const Contacts = (props) => { style={{ maxHeight: '200px', maxWidth: '100%' }} />
*/} - - - - - -
-
-
-
+
- ) -} +
+
+ ); +}; -export default Contacts +export default Contacts; diff --git a/src/views/Business/multiform/DoctorInfo.js b/src/views/Business/multiform/DoctorInfo.js new file mode 100644 index 0000000..16e4d98 --- /dev/null +++ b/src/views/Business/multiform/DoctorInfo.js @@ -0,0 +1,338 @@ +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 index a3ee44d..62685e7 100644 --- a/src/views/Business/multiform/SelectBusiness.js +++ b/src/views/Business/multiform/SelectBusiness.js @@ -1,163 +1,135 @@ - - - - -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 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 SelectBusiness = (props) => { - const token = isAutheticated() - const navigate = useNavigate() - console.log(props.handleView) + 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 { data, setData } = props.data; + const { loading, setLoading } = props.loading; + // const categories = props?.categories || [] - const handleChange = (e) => { + const handleChange = (e) => { + setData((prev) => ({ ...prev, [e.target.id]: e.target.value })); + }; - 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); + }); + }; - // const [loading, setLoading] = useState(false) + useEffect(() => { + getCategories(); + }, []); + const handleSubmit = () => {}; - - - 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 Business -
-
-

-
- -
- - - - - -
-
-
+ > +
+ Select Provider Type +
+
+

- - -
-
-
-
- - - - - -
- - - -
- - - - -
-
-
- +
+ + + +
+
- ) -} - -export default SelectBusiness +
+
+
+
+
+
+ + +
+
+
+
+
+
+ ); +}; +export default SelectBusiness; diff --git a/src/views/Business/multiform/selectLanguage.js b/src/views/Business/multiform/selectLanguage.js index 769dab6..6cb3f1d 100644 --- a/src/views/Business/multiform/selectLanguage.js +++ b/src/views/Business/multiform/selectLanguage.js @@ -1,162 +1,144 @@ - - - -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 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 token = isAutheticated(); + const navigate = useNavigate(); - const { data, setData } = props.data + 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 } = 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 [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(); + }, []); - 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 -
-
-

-
- -
- - - -
-
-
+ > +
+ Select Language +
+
+

+
+ + +
+
+
+
-
-
-
-
- - - - - -
- - {LanguagesData.length > 0 && LanguagesData.map((item, index) => - // -
- handleChange(e)} - /> - {/* {checked = { data.language.map(item => item === item?.language) }} */} - -
- )} - {/* handleChange(e)} + /> + {/* {checked = { data.language.map(item => item === item?.language) }} */} + +
+ ))} + {/* */} - -
- - - - -
-
-
- +
+
- ) -} +
+
+ ); +}; -export default selectLanguage \ No newline at end of file +export default selectLanguage;