Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9684e7fcfa | |||
| d4eda11477 | |||
| 1d31507984 | |||
| a3dbc8cab1 | |||
| 29878e3ddf | |||
| 80a40da9df | |||
| 9f7f1b706b | |||
| d878d1d098 | |||
| 3a60d4e12c | |||
| c03c70b07e | |||
| 9d158fe1cb | |||
| ffd80d9888 | |||
| 384da476a6 | |||
| 3576e7f702 | |||
| 5ed94fee53 | |||
| dbf81a4cf5 | |||
| 0984d78f1e | |||
| ade91c4ed8 | |||
| 905e783f76 | |||
| 08665d51a7 | |||
| dff0bd72ed |
@@ -1,6 +1,6 @@
|
|||||||
SKIP_PREFLIGHT_CHECK=true
|
SKIP_PREFLIGHT_CHECK=true
|
||||||
REACT_APP_NODE_ENV="development"
|
REACT_APP_NODE_ENV="development"
|
||||||
REACT_APP_SOCKET_URL="https://dev-socket.mermsemr.com"
|
REACT_APP_SOCKET_URL="https://devsocket.mermsemr.com"
|
||||||
REACT_APP_MAIN_API="https://devapi.mermsemr.com"
|
REACT_APP_MAIN_API="https://devapi.mermsemr.com"
|
||||||
REACT_APP_MEDIA_SERVER="https://dev-media.mermsemr.com"
|
REACT_APP_MEDIA_SERVER="https://dev-media.mermsemr.com"
|
||||||
REACT_APP_MAIN_SOCKET="https://dev-socket.mermsemr.com"
|
REACT_APP_MAIN_SOCKET="https://dev-socket.mermsemr.com"
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
SKIP_PREFLIGHT_CHECK=true
|
SKIP_PREFLIGHT_CHECK=true
|
||||||
REACT_APP_NODE_ENV="development"
|
REACT_APP_NODE_ENV="development"
|
||||||
REACT_APP_SOCKET_URL="https://dev-socket.mermsemr.com"
|
REACT_APP_SOCKET_URL="https://devsocket.mermsemr.com"
|
||||||
REACT_APP_MAIN_API="https://devapi.mermsemr.com"
|
REACT_APP_MAIN_API="https://devapi.mermsemr.com"
|
||||||
REACT_APP_MEDIA_SERVER="https://dev-media.mermsemr.com"
|
REACT_APP_MEDIA_SERVER="https://dev-media.mermsemr.com"
|
||||||
REACT_APP_MAIN_SOCKET="https://dev-socket.mermsemr.com"
|
REACT_APP_MAIN_SOCKET="https://dev-socket.mermsemr.com"
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
SKIP_PREFLIGHT_CHECK=true
|
SKIP_PREFLIGHT_CHECK=true
|
||||||
REACT_APP_NODE_ENV="production"
|
REACT_APP_NODE_ENV="production"
|
||||||
REACT_APP_SOCKET_URL="https://socket.mermsemr.com"
|
REACT_APP_SOCKET_URL="https://socket.mermsemr.com"
|
||||||
REACT_APP_MAIN_API="https://api.mermsemr.com"
|
REACT_APP_MAIN_API="https://devapi.mermsemr.com"
|
||||||
REACT_APP_MEDIA_SERVER="https://media.mermsemr.com"
|
REACT_APP_MEDIA_SERVER="https://media.mermsemr.com"
|
||||||
|
|
||||||
# login footer links
|
# login footer links
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
merms-panel:
|
merms-panel:
|
||||||
# image: registry.chiefsoft.net/wrenchboard-users-wrench:latest
|
image: registry.chiefsoft.net/merms-panel-reactjs:latest
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: docker/Dockerfile
|
dockerfile: docker/Dockerfile
|
||||||
|
|||||||
+2
-1
@@ -33,7 +33,8 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start -e .env.development",
|
"start": "react-scripts start -e .env.development",
|
||||||
"build": "GENERATE_SOURCEMAP=false react-scripts build -e .env.production",
|
"build": "react-scripts start -e .env.development",
|
||||||
|
"build_real": "GENERATE_SOURCEMAP=false react-scripts build -e .env.production",
|
||||||
"test": "react-scripts test",
|
"test": "react-scripts test",
|
||||||
"eject": "react-scripts eject"
|
"eject": "react-scripts eject"
|
||||||
},
|
},
|
||||||
|
|||||||
+5
-1
@@ -10,8 +10,12 @@
|
|||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.register{
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.login-links{
|
.login-links{
|
||||||
margin-top: 40px;
|
margin-top: 50px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|||||||
+23
-20
@@ -2,6 +2,7 @@ import { Routes, Route } from 'react-router-dom';
|
|||||||
|
|
||||||
import UserExist from './component/authorization/UserExist';
|
import UserExist from './component/authorization/UserExist';
|
||||||
import AuthLayout from './component/auth/AuthLayout';
|
import AuthLayout from './component/auth/AuthLayout';
|
||||||
|
import BearerToken from './component/authorization/BearerToken';
|
||||||
import siteLinks from './links/siteLinks';
|
import siteLinks from './links/siteLinks';
|
||||||
|
|
||||||
import LoginPage from './views/LoginPage';
|
import LoginPage from './views/LoginPage';
|
||||||
@@ -22,27 +23,29 @@ function AppRouters() {
|
|||||||
return (
|
return (
|
||||||
<div className="">
|
<div className="">
|
||||||
<Routes>
|
<Routes>
|
||||||
{/* auth routes wrapper */}
|
<Route element={<BearerToken />}>
|
||||||
<Route element={<AuthLayout />}>
|
{/* auth routes wrapper */}
|
||||||
<Route path={siteLinks.home} element={<LoginPage />} />
|
<Route element={<AuthLayout />}>
|
||||||
<Route path={siteLinks.login} element={<LoginPage />} />
|
<Route path={siteLinks.home} element={<LoginPage />} />
|
||||||
<Route path={siteLinks.signup} element={<SignupPage />} />
|
<Route path={siteLinks.login} element={<LoginPage />} />
|
||||||
<Route path={siteLinks.forgetpwd} element={<ForgetpwdPage />} />
|
<Route path={siteLinks.signup} element={<SignupPage />} />
|
||||||
<Route path={siteLinks.csignup} element={<CSignupPage />} />
|
<Route path={siteLinks.forgetpwd} element={<ForgetpwdPage />} />
|
||||||
<Route path={siteLinks.error} element={<LoginPage />} />
|
<Route path={siteLinks.csignup} element={<CSignupPage />} />
|
||||||
</Route>
|
<Route path={siteLinks.error} element={<LoginPage />} />
|
||||||
|
</Route>
|
||||||
|
|
||||||
{/* protected routes */}
|
{/* protected routes */}
|
||||||
<Route element={<SocketIOContextProvider />}>
|
<Route element={<SocketIOContextProvider />}>
|
||||||
<Route element={<UserExist />}>
|
<Route element={<UserExist />}>
|
||||||
<Route path={siteLinks.dash} element={<HomePage />} />
|
<Route path={siteLinks.dash} element={<HomePage />} />
|
||||||
<Route path={siteLinks.product} element={<ProductPage />} />
|
<Route path={siteLinks.product} element={<ProductPage />} />
|
||||||
<Route path={siteLinks.reports} element={<ReportsPage />} />
|
<Route path={siteLinks.reports} element={<ReportsPage />} />
|
||||||
<Route path={siteLinks.comments} element={<CommentsPage />} />
|
<Route path={siteLinks.comments} element={<CommentsPage />} />
|
||||||
<Route path={siteLinks.contacts} element={<ContactsPage />} />
|
<Route path={siteLinks.contacts} element={<ContactsPage />} />
|
||||||
<Route path={siteLinks.user} element={<UserPage />} />
|
<Route path={siteLinks.user} element={<UserPage />} />
|
||||||
<Route path={siteLinks.calendar} element={<CalendarPage />} />
|
<Route path={siteLinks.calendar} element={<CalendarPage />} />
|
||||||
<Route path={siteLinks.settings} element={<SettingsPage />} />
|
<Route path={siteLinks.settings} element={<SettingsPage />} />
|
||||||
|
</Route>
|
||||||
</Route>
|
</Route>
|
||||||
</Route>
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import { useMutation } from '@tanstack/react-query'
|
import { useMutation } from '@tanstack/react-query'
|
||||||
import { useDispatch } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
|
|
||||||
// import LoginImg from '../../assets/bg/login.svg'
|
// import LoginImg from '../../assets/bg/login.svg'
|
||||||
|
|
||||||
@@ -14,14 +14,17 @@ import IOSDownload from '../../assets/img/download/apple.jpg'
|
|||||||
|
|
||||||
export default function Login() {
|
export default function Login() {
|
||||||
|
|
||||||
|
const { userDetails: { token, room }} = useSelector((state) => state?.userDetails); // CHECKS IF USER Details are avaliable, to determine if user is active
|
||||||
|
let loggedIn = token && room ? true : false; // variable to determine if user is logged in
|
||||||
|
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
|
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
const [fields, setFields] = useState({
|
const [fields, setFields] = useState({
|
||||||
username: localStorage.getItem('username') || '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
remember: localStorage.getItem('username') ? true : false
|
remember: false
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleChange = ({target:{name, value}}) => {
|
const handleChange = ({target:{name, value}}) => {
|
||||||
@@ -37,20 +40,25 @@ export default function Login() {
|
|||||||
throw new Error('Please provide all fields marked *')
|
throw new Error('Please provide all fields marked *')
|
||||||
}
|
}
|
||||||
rememberMe(fields.remember) // FUNCTION TO SAVE USERNAME OF THE USER TO LOCAL STORAGE
|
rememberMe(fields.remember) // FUNCTION TO SAVE USERNAME OF THE USER TO LOCAL STORAGE
|
||||||
|
delete fields.remember // REMOVING REMEMBER FROM THE PAYLOAD
|
||||||
return loginUser(fields)
|
return loginUser(fields)
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
},
|
},
|
||||||
onSuccess: (res) => {
|
onSuccess: (res) => {
|
||||||
const {token, room} = res?.data?.data
|
if(res?.data?.error_message){
|
||||||
if(token){
|
throw({message: res?.data?.error_message})
|
||||||
localStorage.setItem('token', token)
|
|
||||||
localStorage.setItem('room', room)
|
|
||||||
// const data = {token}
|
|
||||||
// dispatch(updateUserDetails({ ...data }));
|
|
||||||
navigate('/dash') // later add redux to dispatch state
|
|
||||||
}
|
}
|
||||||
|
const {token, room, uid} = res?.data
|
||||||
|
if(!token || !room){
|
||||||
|
throw({message: 'something went wrong, try again!'})
|
||||||
|
}
|
||||||
|
localStorage.setItem('token', token)
|
||||||
|
localStorage.setItem('room', room)
|
||||||
|
localStorage.setItem('uid', uid)
|
||||||
|
dispatch(updateUserDetails({ ...res?.data }));
|
||||||
|
navigate('/dash') // later add redux to dispatch state
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -62,6 +70,12 @@ export default function Login() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(()=>{ // NAVIGATES USER TO HOME PAGE IF USER IS ACTIVE
|
||||||
|
if(loggedIn){
|
||||||
|
navigate(siteLinks.dash)
|
||||||
|
}
|
||||||
|
},[])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="app">
|
<div className="app">
|
||||||
<div className="app-wrap">
|
<div className="app-wrap">
|
||||||
@@ -71,7 +85,7 @@ export default function Login() {
|
|||||||
<div className="row no-gutters justify-content-center">
|
<div className="row no-gutters justify-content-center">
|
||||||
<div className="col-11 col-sm-6 col-lg-5 col-xxl-3 align-self-center order-2 order-sm-1">
|
<div className="col-11 col-sm-6 col-lg-5 col-xxl-3 align-self-center order-2 order-sm-1">
|
||||||
<div className="mt-5 d-flex">
|
<div className="mt-5 d-flex">
|
||||||
<div className="bg-white register p-5">
|
<div className="bg-white register px-5 pt-5 pb-3">
|
||||||
<h1 className="mb-2">MERMS Panel</h1>
|
<h1 className="mb-2">MERMS Panel</h1>
|
||||||
<p>Welcome back, please login to your account.</p>
|
<p>Welcome back, please login to your account.</p>
|
||||||
<form className="mt-3 mt-sm-5">
|
<form className="mt-3 mt-sm-5">
|
||||||
@@ -79,19 +93,19 @@ export default function Login() {
|
|||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<label className="control-label text-black fw-bold">User Name*</label>
|
<label className="control-label text-black fw-bold">User Name*</label>
|
||||||
<input name='username' value={fields.username} onChange={handleChange} type="text" className="form-control" placeholder="Username" />
|
<input maxLength={55} name='username' value={fields.username} onChange={handleChange} type="text" className="form-control" placeholder="Username" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<label className="control-label text-black fw-bold">Password*</label>
|
<label className="control-label text-black fw-bold">Password*</label>
|
||||||
<input name='password' value={fields.password} onChange={handleChange} type="password" className="form-control" placeholder="Password" />
|
<input maxLength={55} name='password' value={fields.password} onChange={handleChange} type="password" className="form-control" placeholder="Password" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<div className="d-block d-sm-flex align-items-center">
|
<div className="d-block d-sm-flex align-items-center">
|
||||||
<div className="form-check">
|
<div className="form-check">
|
||||||
<input className="form-check-input" type="checkbox" id="gridCheck" name='remember' checked={fields.remember} onChange={handleChange} disabled={!fields.username ? true : false} />
|
<input className="form-check-input" type="checkbox" id="gridCheck" name='remember' checked={fields.remember || false} onChange={handleChange} disabled={!fields.username ? true : false} />
|
||||||
<label className="form-check-label text-black" htmlFor="gridCheck">
|
<label className="form-check-label text-black" htmlFor="gridCheck">
|
||||||
Remember Me
|
Remember Me
|
||||||
</label>
|
</label>
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import {useEffect} from 'react'
|
||||||
|
import { useMutation } from '@tanstack/react-query'
|
||||||
|
import { Outlet } from 'react-router-dom'
|
||||||
|
import MainLoaderBS from '../loaders/MainLoaderBS'
|
||||||
|
|
||||||
|
import { userToken } from '../../services/services'
|
||||||
|
|
||||||
|
export default function BearerToken() {
|
||||||
|
const bearerToken = useMutation({
|
||||||
|
mutationFn: (fields) => {
|
||||||
|
return userToken(fields)
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.log(error)
|
||||||
|
// window.location.reload(true)
|
||||||
|
},
|
||||||
|
onSuccess: (res) => {
|
||||||
|
if(res?.data?.resultCode != '0'){
|
||||||
|
throw({message: 'Something went wrong'})
|
||||||
|
}
|
||||||
|
const {access_token, refresh_token} = res?.data?.data
|
||||||
|
if(access_token){
|
||||||
|
localStorage.setItem('access_token', access_token)
|
||||||
|
}else{
|
||||||
|
throw({message: 'Something went wrong'})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
let reqData = {
|
||||||
|
"username": "user",
|
||||||
|
"password": "password"
|
||||||
|
}
|
||||||
|
bearerToken.mutate(reqData)
|
||||||
|
},[])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{bearerToken.isPending ?
|
||||||
|
<MainLoaderBS />
|
||||||
|
:
|
||||||
|
<Outlet />
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { Outlet, useNavigate } from 'react-router-dom'
|
import { Outlet, useNavigate } from 'react-router-dom'
|
||||||
|
import { useMutation } from '@tanstack/react-query'
|
||||||
|
|
||||||
import { updateUserDetails } from "../../store/UserDetails";
|
import { updateUserDetails } from "../../store/UserDetails";
|
||||||
|
import { userInfo } from '../../services/services'
|
||||||
import MainLoaderBS from '../loaders/MainLoaderBS'
|
import MainLoaderBS from '../loaders/MainLoaderBS'
|
||||||
import Layout from '../layout/Layout'
|
import Layout from '../layout/Layout'
|
||||||
import siteLinks from '../../links/siteLinks'
|
import siteLinks from '../../links/siteLinks'
|
||||||
|
|
||||||
import debounceFunction from '../../utils/debounceFunction'
|
import debounceFunction from '../../utils/debounceFunction'
|
||||||
import { accountDashboard } from '../../services/services';
|
|
||||||
import { SocketContextValues } from '../context/SocketIOContext';
|
import { SocketContextValues } from '../context/SocketIOContext';
|
||||||
|
|
||||||
|
|
||||||
@@ -23,9 +25,9 @@ export default function UserExist() {
|
|||||||
|
|
||||||
const [lastActivityTime, setLastActivityTime] = useState(Date.now()); // HOLDS THE INITIAL TIME USER LOGS IN
|
const [lastActivityTime, setLastActivityTime] = useState(Date.now()); // HOLDS THE INITIAL TIME USER LOGS IN
|
||||||
|
|
||||||
const { userDetails: { lastname }} = useSelector((state) => state?.userDetails); // CHECKS IF USER Details are avaliable, to determine if user is active
|
const { userDetails: { token, room }} = useSelector((state) => state?.userDetails); // CHECKS IF USER Details are avaliable, to determine if user is active
|
||||||
|
|
||||||
let loggedIn = lastname ? true : false; // variable to determine if user is logged in
|
let loggedIn = token && room ? true : false; // variable to determine if user is logged in
|
||||||
// console.log('loggedIn', loggedIn)
|
// console.log('loggedIn', loggedIn)
|
||||||
|
|
||||||
// Function to log the user out
|
// Function to log the user out
|
||||||
@@ -40,6 +42,31 @@ export default function UserExist() {
|
|||||||
debounceFunction(setLastActivityTime(Date.now()), 1000)
|
debounceFunction(setLastActivityTime(Date.now()), 1000)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const getUser = useMutation({
|
||||||
|
mutationFn: (fields) => {
|
||||||
|
return userInfo(fields)
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
navigate(siteLinks.login)
|
||||||
|
setLoading(false)
|
||||||
|
},
|
||||||
|
onSuccess: (res) => {
|
||||||
|
const {token, room, uid} = res?.data
|
||||||
|
if(!token || !room){
|
||||||
|
navigate(siteLinks.login)
|
||||||
|
setLoading(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
localStorage.setItem('token', token)
|
||||||
|
localStorage.setItem('room', room)
|
||||||
|
localStorage.setItem('uid', uid)
|
||||||
|
dispatch(updateUserDetails({ ...res?.data }));
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
const timer = setTimeout(()=>{
|
const timer = setTimeout(()=>{
|
||||||
if(Date.now() - Number(lastActivityTime) >= Number(process.env.REACT_APP_TIMEOUT)){
|
if(Date.now() - Number(lastActivityTime) >= Number(process.env.REACT_APP_TIMEOUT)){
|
||||||
@@ -64,35 +91,19 @@ export default function UserExist() {
|
|||||||
},[lastActivityTime])
|
},[lastActivityTime])
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
accountDashboard().then(res => {
|
let token = localStorage.getItem('token') // USER TOKEN
|
||||||
const {dash_data} = res?.data
|
let uid = localStorage.getItem('uid') // USER UID
|
||||||
|
if(token && loggedIn){
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
dispatch(updateUserDetails({ ...dash_data }));
|
}else if(token && uid && !loggedIn){
|
||||||
}).catch(err => {
|
const reqData = {token, uid}
|
||||||
|
getUser.mutate(reqData)
|
||||||
|
}else{
|
||||||
navigate(siteLinks.login)
|
navigate(siteLinks.login)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
})
|
}
|
||||||
},[])
|
},[])
|
||||||
|
|
||||||
|
|
||||||
// useEffect(()=>{
|
|
||||||
// let token = localStorage.getItem('token')
|
|
||||||
// const timer = setTimeout(()=>{
|
|
||||||
// if(token && loggedIn){
|
|
||||||
// setLoading(false)
|
|
||||||
// }else if(token && !loggedIn){
|
|
||||||
// const data = {token}
|
|
||||||
// dispatch(updateUserDetails({ ...data }));
|
|
||||||
// setLoading(false)
|
|
||||||
// // dispatch(updateUserDetails({ ...res.data }));
|
|
||||||
// }else{
|
|
||||||
// navigate('auth/login')
|
|
||||||
// }
|
|
||||||
// },1000)
|
|
||||||
|
|
||||||
// return () => clearTimeout(timer)
|
|
||||||
// },[])
|
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
if(localStorage.getItem('room')){
|
if(localStorage.getItem('room')){
|
||||||
joinRoom(localStorage.getItem('room'));
|
joinRoom(localStorage.getItem('room'));
|
||||||
|
|||||||
@@ -1,29 +1,34 @@
|
|||||||
import { useQuery } from '@tanstack/react-query'
|
import React, {useEffect} from 'react'
|
||||||
import React from 'react'
|
import { useMutation } from '@tanstack/react-query'
|
||||||
import { productData } from '../../services/services'
|
import { productsData } from '../../services/services'
|
||||||
import queryKeys from '../../services/queryKeys'
|
|
||||||
import productPath from "../../utils/productpath";
|
import productPath from "../../utils/productpath";
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
export default function Products() {
|
|
||||||
|
|
||||||
const {data, isFetching, isError, error} = useQuery({
|
|
||||||
queryKey: queryKeys.product,
|
export default function Products() {
|
||||||
queryFn: () => productData()
|
const getProductsData = useMutation({
|
||||||
|
mutationFn: (reqData) => {
|
||||||
|
return productsData(reqData)
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.log(error)
|
||||||
|
},
|
||||||
|
onSuccess: (res) => {
|
||||||
|
if(res?.data?.resultCode != '0'){
|
||||||
|
throw({message: 'Something went wrong'})
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
/*
|
|
||||||
{
|
useEffect(()=>{
|
||||||
"banner": "p1.jpg",
|
let reqData = {
|
||||||
"description": "Your personal professional web presence",
|
token: localStorage.getItem('token'), // USER TOKEN
|
||||||
"id": 1,
|
uid: localStorage.getItem('uid') // USER UID
|
||||||
"name": "Personal Website",
|
}
|
||||||
"product_id": "A000001",
|
getProductsData.mutate(reqData)
|
||||||
"product_uid": "e92282b4-3ee1-4026-92ac-12cfd214b43a",
|
},[])
|
||||||
"status": 5,
|
|
||||||
"status_text": "Activate Now"
|
const products = getProductsData?.data?.data?.products_data // PRODUCTS DATA
|
||||||
},
|
|
||||||
*/
|
|
||||||
//const products = data?.data?.products_list?.products
|
|
||||||
const products = data?.data?.products_list
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -32,7 +37,7 @@ export default function Products() {
|
|||||||
<h4 className="card-title">My Products</h4>
|
<h4 className="card-title">My Products</h4>
|
||||||
</div>
|
</div>
|
||||||
<div className="card-body pb-0">
|
<div className="card-body pb-0">
|
||||||
{isFetching ?
|
{getProductsData?.isPending ?
|
||||||
<>
|
<>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
@@ -40,10 +45,10 @@ export default function Products() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
: isError ?
|
: getProductsData?.isPending ?
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<p className='text-danger'>{error.message}</p>
|
<p className='text-danger'>{getProductsData?.error?.message}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
:
|
:
|
||||||
|
|||||||
@@ -1,20 +1,36 @@
|
|||||||
import { useQuery } from '@tanstack/react-query'
|
import React, {useEffect} from 'react'
|
||||||
import React from 'react'
|
import { useMutation } from '@tanstack/react-query'
|
||||||
import { topBar } from '../../services/services'
|
import { topBar } from '../../services/services'
|
||||||
import queryKeys from '../../services/queryKeys'
|
|
||||||
|
|
||||||
export default function TopBar() {
|
export default function TopBar() {
|
||||||
|
|
||||||
const {data, isFetching, isError, error} = useQuery({
|
const topBarData = useMutation({
|
||||||
queryKey: queryKeys.topBar,
|
mutationFn: (reqData) => {
|
||||||
queryFn: () => topBar()
|
return topBar(reqData)
|
||||||
})
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.log(error)
|
||||||
|
},
|
||||||
|
onSuccess: (res) => {
|
||||||
|
if(res?.data?.resultCode != '0'){
|
||||||
|
throw({message: 'Something went wrong'})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const topData = data?.data?.bar_data?.top_bar
|
useEffect(()=>{
|
||||||
|
let reqData = {
|
||||||
|
token: localStorage.getItem('token'), // USER TOKEN
|
||||||
|
uid: localStorage.getItem('uid') // USER UID
|
||||||
|
}
|
||||||
|
topBarData.mutate(reqData)
|
||||||
|
},[])
|
||||||
|
|
||||||
|
const data = topBarData?.data?.data?.top_bar // top bar data
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isFetching ?
|
{topBarData.isPending ?
|
||||||
<>
|
<>
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<div className="card p-4">
|
<div className="card p-4">
|
||||||
@@ -22,15 +38,15 @@ export default function TopBar() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
: isError ?
|
: topBarData.error ?
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<div className="card p-4">
|
<div className="card p-4">
|
||||||
<p className='text-danger'>{error.message}</p>
|
<p className='text-danger'>{topBarData.error.message}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
:
|
:
|
||||||
<>
|
<>
|
||||||
{topData && topData?.map((item, index)=>{
|
{data && data?.map((item, index)=>{
|
||||||
let textColor = item?.description == 'Contacts' ? 'text-danger' : item?.description == 'Site Traffic' ? 'text-primary' : item?.description == 'Appointments' ? 'text-orange' : 'text-success'
|
let textColor = item?.description == 'Contacts' ? 'text-danger' : item?.description == 'Site Traffic' ? 'text-primary' : item?.description == 'Appointments' ? 'text-orange' : 'text-success'
|
||||||
return (
|
return (
|
||||||
<div key={item.id + index} className="col-sm-6 col-xxl-3">
|
<div key={item.id + index} className="col-sm-6 col-xxl-3">
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { useQuery } from '@tanstack/react-query'
|
||||||
|
import { topBar } from '../../services/services'
|
||||||
|
import queryKeys from '../../services/queryKeys'
|
||||||
|
|
||||||
|
export default function TopBar() {
|
||||||
|
|
||||||
|
const {data, isFetching, isError, error} = useQuery({
|
||||||
|
queryKey: queryKeys.topBar,
|
||||||
|
queryFn: () => topBar()
|
||||||
|
})
|
||||||
|
|
||||||
|
const topData = data?.data?.bar_data?.top_bar
|
||||||
|
console.log('topData', topData)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{isFetching ?
|
||||||
|
<>
|
||||||
|
<div className="col-12">
|
||||||
|
<div className="card p-4">
|
||||||
|
<p className='text-mute'>Loading...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
: isError ?
|
||||||
|
<div className="col-12">
|
||||||
|
<div className="card p-4">
|
||||||
|
<p className='text-danger'>{error.message}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<>
|
||||||
|
{topData && topData?.map((item, index)=>{
|
||||||
|
let textColor = item?.description == 'Contacts' ? 'text-danger' : item?.description == 'Site Traffic' ? 'text-primary' : item?.description == 'Appointments' ? 'text-orange' : 'text-success'
|
||||||
|
return (
|
||||||
|
<div key={item.id + index} className="col-sm-6 col-xxl-3">
|
||||||
|
<div className="card card-statistics ecommerce-contant overflow-h">
|
||||||
|
<div className="card-body p-0">
|
||||||
|
<div className="d-flex m-b-0 ecommerce-contant-text h-100">
|
||||||
|
<div className="w-100">
|
||||||
|
<div className="row p-3">
|
||||||
|
<div className="col">
|
||||||
|
<h3 className="mb-0">{item?.value || 0}</h3>
|
||||||
|
<small className="d-block">{item?.data_span}</small>
|
||||||
|
</div>
|
||||||
|
<div className="col text-right">
|
||||||
|
<h5 className="text-muted mb-0">{item?.description}</h5>
|
||||||
|
<strong className={`${textColor} m-t-5`}><i
|
||||||
|
className="zmdi zmdi-long-arrow-up font-weight-bold"></i> N/A</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="apexchart-wrapper">
|
||||||
|
<div id="ecommercedemo3" className="chart-fit"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
const queryKeys = {
|
const queryKeys = {
|
||||||
|
user_details: ['user_details'],
|
||||||
|
|
||||||
dashboard: ['dashboard'],
|
dashboard: ['dashboard'],
|
||||||
topBar: ['top-bar'],
|
topBar: ['top-bar'],
|
||||||
recentAction: ['recent-action'],
|
recentAction: ['recent-action'],
|
||||||
|
|||||||
+96
-39
@@ -4,12 +4,13 @@ import axios from "axios"
|
|||||||
axios.interceptors.request.use(
|
axios.interceptors.request.use(
|
||||||
config => {
|
config => {
|
||||||
config.headers = {
|
config.headers = {
|
||||||
// Accept: "application/json",
|
Accept: "application/json",
|
||||||
"Access-Control-Allow-Origin": "*",
|
"Access-Control-Allow-Origin": "*",
|
||||||
// "Access-Control-Expose-Headers": "Access-Control-Allow-Origin",
|
// "Access-Control-Expose-Headers": "Access-Control-Allow-Origin",
|
||||||
// "Access-Control-Allow-Headers": "Origin, X-API-KEY, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Access-Control-Allow-Headers, Authorization, observe, enctype, Content-Length, X-Csrf-Token",
|
// "Access-Control-Allow-Headers": "Origin, X-API-KEY, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Access-Control-Allow-Headers, Authorization, observe, enctype, Content-Length, X-Csrf-Token",
|
||||||
// "Content-Type": "application/json;charset=UTF-8",
|
// "Content-Type": "application/json;charset=UTF-8",
|
||||||
'Authorization': `Bearer ${localStorage.getItem('token')}`
|
'Authorization': (localStorage && localStorage.getItem('access_token')) ? `Bearer ${localStorage.getItem('access_token')}` : '',
|
||||||
|
// 'uuid': 'dummy'
|
||||||
};
|
};
|
||||||
// config.headers['Authorization'] = `Bearer ${localStorage.getItem('token')}`;
|
// config.headers['Authorization'] = `Bearer ${localStorage.getItem('token')}`;
|
||||||
// config.baseURL = process.env.REACT_APP_MAIN_API
|
// config.baseURL = process.env.REACT_APP_MAIN_API
|
||||||
@@ -25,7 +26,7 @@ const postAuxEnd = (path, postData, media=false) => {
|
|||||||
return axios.post(`${basePath}${path}`, postData).then(res => {
|
return axios.post(`${basePath}${path}`, postData).then(res => {
|
||||||
return res
|
return res
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
throw new Error(err.response.data.message);
|
throw new Error(err.response.data.msg);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,12 +43,70 @@ const getAuxEnd = (path, reqData= null) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FUNCTION TO AUTHORIZE USER IN
|
||||||
|
export const userToken = (reqData) => {
|
||||||
|
let postData = {
|
||||||
|
...reqData
|
||||||
|
}
|
||||||
|
return postAuxEnd('/Authorize', postData, false)
|
||||||
|
}
|
||||||
|
|
||||||
// FUNCTION TO LOGIN USER IN
|
// FUNCTION TO LOGIN USER IN
|
||||||
export const loginUser = (reqData) => {
|
export const loginUser = (reqData) => {
|
||||||
let postData = {
|
let postData = {
|
||||||
...reqData
|
...reqData
|
||||||
}
|
}
|
||||||
return postAuxEnd('/panel/auth/login', postData, false)
|
return postAuxEnd('/panel/Login', postData, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FUNCTION TO GET USER INFO DATA
|
||||||
|
export const userInfo = (reqData) => {
|
||||||
|
let postData = {
|
||||||
|
...reqData
|
||||||
|
}
|
||||||
|
return postAuxEnd('/panel/account', postData, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FUNCTION TO GET DASHBOARD TOP BAR SECTION
|
||||||
|
export const topBar = (reqData) => {
|
||||||
|
let postData = {
|
||||||
|
...reqData,
|
||||||
|
}
|
||||||
|
return postAuxEnd(`/panel/account/bar`, postData, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FUNCTION TO GET DASHBOARD RECENT ACTIONS SECTION
|
||||||
|
export const recentActions = (reqData) => {
|
||||||
|
let postData = {
|
||||||
|
...reqData,
|
||||||
|
token: localStorage.getItem('token'), // USER TOKEN
|
||||||
|
uid: localStorage.getItem('uid') // USER UID
|
||||||
|
}
|
||||||
|
//return getAuxEnd(`/panel/account/actions`)
|
||||||
|
return postAuxEnd(`/panel/account/actions`, postData, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FUNCTION TO GET DASHBOARD PRODUCT DATA SECTION
|
||||||
|
export const productsData = (reqData) => {
|
||||||
|
let postData = {
|
||||||
|
...reqData,
|
||||||
|
}
|
||||||
|
return postAuxEnd(`/panel/account/products`, postData, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// FUNCTION TO GET DASHBOARD PRODUCT URL DATA SECTION
|
||||||
|
export const productsURL = (reqData) => {
|
||||||
|
let postData = {
|
||||||
|
...reqData,
|
||||||
|
token: localStorage.getItem('token'), // USER TOKEN
|
||||||
|
uid: localStorage.getItem('uid') // USER UID
|
||||||
|
}
|
||||||
|
return postAuxEnd(`/panel/account/products/url`, postData, false)
|
||||||
|
// return getAuxEnd(`/panel/account/products/url`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION TO REGISTER USER
|
// FUNCTION TO REGISTER USER
|
||||||
@@ -77,9 +136,11 @@ export const completeRegistration = (reqData) => {
|
|||||||
// FUNCTION TO SUBSCRIBE
|
// FUNCTION TO SUBSCRIBE
|
||||||
export const subscribe = (reqData) => {
|
export const subscribe = (reqData) => {
|
||||||
let postData = {
|
let postData = {
|
||||||
...reqData
|
...reqData,
|
||||||
|
token: localStorage.getItem('token'), // USER TOKEN
|
||||||
|
uid: localStorage.getItem('uid') // USER UID
|
||||||
}
|
}
|
||||||
return postAuxEnd('/panel/myproduct/subscription', postData, false)
|
return postAuxEnd(`/panel/myproduct/subscription`, postData, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -91,49 +152,45 @@ export const recoverPWD = (reqData) => {
|
|||||||
return postAuxEnd('/panel/auth/reset', postData, false)
|
return postAuxEnd('/panel/auth/reset', postData, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION TO GET DASHBOARD DATA
|
|
||||||
export const accountDashboard = () => {
|
|
||||||
return getAuxEnd(`/panel/account/dash`)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FUNCTION TO GET DASHBOARD TOP BAR SECTION
|
|
||||||
export const topBar = () => {
|
|
||||||
return getAuxEnd(`/panel/account/bar`)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FUNCTION TO GET CALENDAR EVENTS
|
// FUNCTION TO GET CALENDAR EVENTS
|
||||||
export const getCalendarEvents = () => {
|
export const getCalendarEvents = (reqData) => {
|
||||||
return getAuxEnd(`/panel/account/calendar`)
|
let postData = {
|
||||||
}
|
...reqData,
|
||||||
|
token: localStorage.getItem('token'), // USER TOKEN
|
||||||
// FUNCTION TO GET DASHBOARD RECENT ACTIONS SECTION
|
uid: localStorage.getItem('uid') // USER UID
|
||||||
export const recentActions = () => {
|
}
|
||||||
return getAuxEnd(`/panel/account/actions`)
|
return postAuxEnd(`/panel/account/calendar`, postData, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION TO GET MY PRODUCT PROVISION DATA
|
// FUNCTION TO GET MY PRODUCT PROVISION DATA
|
||||||
export const productProvision = (reqData) => {
|
export const productProvision = (reqData) => {
|
||||||
const postData = { ...reqData }
|
let postData = {
|
||||||
return getAuxEnd(`/panel/myproduct/provision`, postData)
|
...reqData,
|
||||||
|
token: localStorage.getItem('token'), // USER TOKEN
|
||||||
|
uid: localStorage.getItem('uid') // USER UID
|
||||||
|
}
|
||||||
|
return postAuxEnd(`/panel/myproduct/provision`, postData, false)
|
||||||
|
// return getAuxEnd(`/panel/myproduct/provision`, postData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION TO GET DASHBOARD PRODUCT DATA SECTION
|
// FUNCTION TO GET DASHBOARD PRODUCT DATA SECTION
|
||||||
export const productData = () => {
|
export const contactData = (reqData) => {
|
||||||
return getAuxEnd(`/panel/account/products`)
|
let postData = {
|
||||||
}
|
...reqData,
|
||||||
|
token: localStorage.getItem('token'), // USER TOKEN
|
||||||
// FUNCTION TO GET DASHBOARD PRODUCT DATA SECTION
|
uid: localStorage.getItem('uid') // USER UID
|
||||||
export const contactData = () => {
|
}
|
||||||
return getAuxEnd(`/panel/contacts`)
|
return postAuxEnd(`/panel/contacts`, postData, false)
|
||||||
}
|
// return getAuxEnd(`/panel/contacts`)
|
||||||
|
|
||||||
// FUNCTION TO GET DASHBOARD PRODUCT URL DATA SECTION
|
|
||||||
export const productsURL = () => {
|
|
||||||
return getAuxEnd(`/panel/account/products/url`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MyProductData = (productID) => {
|
export const MyProductData = (productID) => {
|
||||||
const reqData = { product_id : productID}
|
const reqData = { product_id : productID}
|
||||||
//console.log(reqData)
|
let postData = {
|
||||||
return getAuxEnd(`/panel/myproduct/dash`,reqData)
|
...reqData,
|
||||||
|
token: localStorage.getItem('token'), // USER TOKEN
|
||||||
|
uid: localStorage.getItem('uid') // USER UID
|
||||||
|
}
|
||||||
|
return postAuxEnd(`/panel/myproduct/dash`, postData, false)
|
||||||
|
// return getAuxEnd(`/panel/myproduct/dash`,reqData)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user