diff --git a/.env b/.env index 86810db..cc99187 100644 --- a/.env +++ b/.env @@ -6,7 +6,7 @@ TWITTER_URL=https://twitter.com INSTAGRAM_URL=https://www.instagram.com # BACKEND END POINTS -REACT_APP_MAIN_API='https://devcore.digifi.chiefsoft.net' +REACT_APP_MAIN_API='http://backoffice-apidev.simbrellang.net:14700' # ENQUIRIES CONTACTS VITE_CALL_ENDPOINT='09099000000' diff --git a/.env.development b/.env.development index b7fc43e..79cb474 100644 --- a/.env.development +++ b/.env.development @@ -6,7 +6,7 @@ VITE_TWITTER_URL=https://twitter.com VITE_INSTAGRAM_URL=https://www.instagram.com # BACKEND END POINTS -REACT_APP_MAIN_API='https://devcore.digifi.chiefsoft.net' +REACT_APP_MAIN_API='http://backoffice-apidev.simbrellang.net:14700' # ENQUIRIES CONTACTS VITE_CALL_ENDPOINT='09099000000' diff --git a/.env.production b/.env.production index 86810db..cc99187 100644 --- a/.env.production +++ b/.env.production @@ -6,7 +6,7 @@ TWITTER_URL=https://twitter.com INSTAGRAM_URL=https://www.instagram.com # BACKEND END POINTS -REACT_APP_MAIN_API='https://devcore.digifi.chiefsoft.net' +REACT_APP_MAIN_API='http://backoffice-apidev.simbrellang.net:14700' # ENQUIRIES CONTACTS VITE_CALL_ENDPOINT='09099000000' diff --git a/src/components/auth/LoginCom.jsx b/src/components/auth/LoginCom.jsx index 28b0d5e..00aa232 100644 --- a/src/components/auth/LoginCom.jsx +++ b/src/components/auth/LoginCom.jsx @@ -1,20 +1,29 @@ import React, { useEffect, useState } from 'react' import { useDispatch } from 'react-redux' import { useLocation, useNavigate, Link } from 'react-router-dom' -// import { useMutation } from '@tanstack/react-query' +import { useMutation } from '@tanstack/react-query' +import {Formik, Form} from 'formik' +import * as Yup from "yup"; -import Label from '../Label' import InputText from '../InputText' -import PageLoader from '../PageLoader' import { updateUserDetails } from "../../store/UserDetails"; -// import { loginUser } from '../../services/siteServices' +import { loginUser } from '../../services/siteServices' -import GoogleDownload from '../../assets/download/andriod.jpg' -import IOSDownload from '../../assets/download/apple.jpg' import RouteLinks from '../../RouteLinks' -import DummyLogo from '../DummyLogo' import Icons from '../Icons' + +const initialValues = { + username: "", + password: "", +}; + +// To get the validation schema +const validationSchema = Yup.object().shape({ + username: Yup.string().required("username is required"), + password: Yup.string().required("password is required").min(6, 'must be upto 6 characters').max(12, 'must not exceed 12 characters'), +}); + export default function LoginCom() { const dispatch = useDispatch() @@ -22,111 +31,132 @@ export default function LoginCom() { const [loading, setLoading] = useState(false) - const [fields, setFields] = useState({ - username: '', - password: '', + const login = useMutation({ + mutationFn: (fields) => { + if(!fields.username || !fields.password){ + throw new Error('Please provide all fields marked *') + } + return loginUser(fields) + }, + onError: (error) => { + console.log(error) + }, + onSuccess: (res) => { + const {jwt_token, user} = res?.data + if(jwt_token){ + localStorage.setItem('token', jwt_token) + // localStorage.setItem('room', room) + const data = {jwt_token} + dispatch(updateUserDetails({ ...data, ...user })); + } + navigate(RouteLinks.homePage, {state:{proceed:'true'}}) // later add redux to dispatch state + } }) - const handleChange = ({target:{name, value}}) => { - setFields(prev => ({...prev, [name]:value})) - } + // const handleLogin = () => { + // setLoading(true) + // const data = {name: 'dummy'} + // localStorage.setItem('token', 'token') + // dispatch(updateUserDetails({ ...data })); + // setTimeout(()=>{ + // navigate(RouteLinks.homePage, {replace:true}) + // },500) + // } - // const login = useMutation({ - // mutationFn: (fields) => { - // if(!fields.username || !fields.password){ - // throw new Error('Please provide all fields marked *') - // } - // return loginUser(fields) - // }, - // onError: (error) => { - // console.log(error) - // }, - // onSuccess: (res) => { - // // const {token, room} = res?.data?.data - // // if(token){ - // // localStorage.setItem('token', token) - // // localStorage.setItem('room', room) - // // // const data = {token} - // // // dispatch(updateUserDetails({ ...data })); - // // } - // navigate(myLinks.home, {state:{proceed:'true'}}) // later add redux to dispatch state - // } - // }) + //FUNCTION TO HANDLE LOGIN + const handleSubmit = (values, helper) => { + login.mutate(values) + // handleLogin() + }; - const handleLogin = () => { - setLoading(true) - const data = {name: 'dummy'} - localStorage.setItem('token', 'token') - dispatch(updateUserDetails({ ...data })); - setTimeout(()=>{ - navigate(RouteLinks.homePage, {replace:true}) - },500) - } - return ( <>
-
-
-

Sign In

-

Welcome back, please login to your account

-
+ + {(props)=>( +
+
+
+

Sign In

+

Welcome back, please login to your account

+
- {/* social login */} -
-
- - Sign in with Google -
-
- - Sign in with Apple -
-
+ {/* social login */} +
+
+ + Sign in with Google +
+
+ + Sign in with Apple +
+
-
-

Or with email

-
+
+

Or with email

+
-
-
- -
-
- - {/*

Forget password ?

*/} -
-
- {/* */} - -
- - {/* {login.error && - <> -
-

{login.error.message}

-
- - } */} -
+
+
+

+ {(props.errors.username && props.touched.username) ? props.errors.username : ''} +

+ +
+
+

+ {(props.errors.password && props.touched.password) ? props.errors.password : ''} +

+ + {/*

Forget password ?

*/} +
+
+ +
+ + {login.error && + <> +
+

{login.error.message}

+
+ + } +
- {/*

Not yet a member? Sign Up

*/} + {/*

Not yet a member? Sign Up

*/} -
- Terms - Plans - Contact Us -
+
+ Terms + Plans + Contact Us +
-
-
-
- {/* -

Dummy Text Here

*/} +
+ + )} +
diff --git a/src/components/home/HomeCom.jsx b/src/components/home/HomeCom.jsx index b830a33..bec0724 100644 --- a/src/components/home/HomeCom.jsx +++ b/src/components/home/HomeCom.jsx @@ -1,4 +1,5 @@ import React from 'react' +import { useQuery } from "@tanstack/react-query"; import BreadcrumbCom from '../../components/breadcrumb/BreadcrumbCom' import CustomCounter from '../../components/CustomCounter' import Icons from '../../components/Icons' @@ -6,71 +7,73 @@ import TableWrapper from '../../components/tableWrapper/TableWrapper' import Avatar from '../../assets/user_avatar.jpg' import { Widget1 } from './Widget1' import { Widget2 } from './Widget2' +import formatNumber from '../../helpers/formatNumber' + +import queryKeys from '../../services/queryKeys' +import { getDashData } from '../../services/siteServices' export default function HomeCom() { + + const {data, isFetching, isError, error} = useQuery({ + queryKey: queryKeys.dashboard, + queryFn: () => getDashData() + }) + + const dashData = data?.data // DASHBOARD DATA + + // console.log('dashData', dashData) + // loans, payments, recent_transactions [], request_summary + return (
+ + {(isFetching || isError) ? +
+ {isError ?

{error.message}

:

Loading...

} +
+ :

Loans

-

$

-

This week

+ {/*

{dashData?.loans?.currency_text}

*/} +

{dashData?.loans?.currency_text}

+

{dashData?.loans?.text}

Payments

{/* */}
-

-

This week

+

{dashData?.payments?.currency_text}

+

{dashData?.payments?.text}

Request Summary

-
-
- -
-
-

$K

-

Sales

-
-
-
-
- -
-
-

$K

-

Revenue

-
-
-
-
- -
-
-

$K

-

Tickets

-
-
-
-
- -
-
-

$M

-

Tasks

-
-
+ { + Object.values(dashData?.request_summary).map((item, index) => { + return ( +
+
+ +
+
+

$K

+

{Object.keys(item)[0]}

+
+
+ ) + }) + }
+
@@ -83,7 +86,7 @@ export default function HomeCom() {
*/}
- + {({ data }) => ( <> @@ -104,21 +107,21 @@ export default function HomeCom() { - {data.map(item => ( - + {(data && data.length > 0) ? data?.map((item, index) => ( + - ))} + )) + : + + + + }
Jese image
-
John Dummy
-
HTML, JS, ReactJS
+
{item?.account_id}
+
{item?.channel}
-
chiefSoft
-
Web, UI/UX Design
+
{item?.transaction_id}
+
{item?.type}
@@ -143,7 +146,16 @@ export default function HomeCom() {
+
+ No Record Found +
+
@@ -152,6 +164,7 @@ export default function HomeCom() {
+ } ) } \ No newline at end of file diff --git a/src/components/tableWrapper/TableWrapper.jsx b/src/components/tableWrapper/TableWrapper.jsx index 95d3ded..c995ad5 100644 --- a/src/components/tableWrapper/TableWrapper.jsx +++ b/src/components/tableWrapper/TableWrapper.jsx @@ -87,7 +87,7 @@ export default function TableWrapper({
Showing {isLoading ? '----' : `${currentPage + 1}-${currentPage + numberOfSelection >= data.length ? data.length : (currentPage + numberOfSelection)}`} of {data.length}
- {(newData.length >= itemsPerPage) && + {(newData.length >= 0) &&
{ + // return new Intl.NumberFormat().format(number); + return number.toFixed(2); + }; + + export default formatNumber \ No newline at end of file diff --git a/src/services/queryKeys.js b/src/services/queryKeys.js index a8a232c..17fab73 100644 --- a/src/services/queryKeys.js +++ b/src/services/queryKeys.js @@ -1,4 +1,5 @@ const queryKeys = { + dashboard: ['dashboard'], apply_loan: ['apply'], select_loan: ['select-loan'], approved_loan: ['approved-loan'], diff --git a/src/services/siteServices.js b/src/services/siteServices.js index 55595c5..1a9ef4f 100644 --- a/src/services/siteServices.js +++ b/src/services/siteServices.js @@ -9,7 +9,7 @@ axios.interceptors.request.use( // "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", "Content-Type": "application/json;charset=UTF-8", - // 'Authorization': `Bearer ${localStorage.getItem('token')}` + 'Authorization': (localStorage && localStorage.getItem('token')) ? `Bearer ${localStorage.getItem('token')}` : '' }; // config.headers['Authorization'] = `Bearer ${localStorage.getItem('token')}`; // config.baseURL = process.env.REACT_APP_MAIN_API @@ -25,7 +25,7 @@ const postAuxEnd = (path, postData, media=false) => { return axios.post(`${basePath}${path}`, postData).then(res => { return res }).catch(err => { - throw new Error(err.response.data.message); + throw new Error(err); }) } @@ -47,7 +47,13 @@ export const loginUser = (reqData) => { let postData = { ...reqData } - return postAuxEnd('/salary/login', postData, false) + return postAuxEnd('/login', postData, false) +} + +// FUNCTION TO GET DASHBOARD DATA +export const getDashData = (reqData) => { + const postData = { ...reqData } + return getAuxEnd(`/dashboard`, postData) } // FUNCTION TO GET APPLIED LOANS TABLE