Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leon restructure 16 nov #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"antd": "^5.11.1",
"axios": "^0.24.0",
"date-fns": "^2.27.0",
"jsonwebtoken": "^8.5.1",
"payment": "^2.4.6",
"react": "^17.0.2",
"react-credit-cards": "^0.8.3",
"react-dom": "^17.0.2",
"react-router-dom": "^6.0.2",
"react-router-dom": "6.21.0",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
Expand Down
306 changes: 2 additions & 304 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,310 +1,8 @@
import React, { useEffect, useState, Fragment } from "react";
import jwt from "jsonwebtoken";
import {
BrowserRouter as Router,
Routes,
Route,
Navigate,
} from "react-router-dom";
import HomePage from "./components/HomePage/HomePage";
import SignIn from "./components/SignIn/SignIn";
import SignUp from "./components/SignUp/SignUp";
import Page404 from "./components/Page404/Page404";
import PatientDash from "./components/Dashboards/PatientDash/PatientDash";
import ViewLocation from "./components/Dashboards/PatientDash/Tabs/ViewLocation";
import MyAppointments from "./components/Dashboards/PatientDash/Tabs/MyAppointments";
import BookAppointment from "./components/Dashboards/PatientDash/Tabs/BookAppointment";
import MakePaymentPatinet from "./components/Dashboards/PatientDash/Tabs/MakePayment";
import CardPaymentPatient from "./components/Dashboards/PatientDash/Tabs/CardPayment";
import UpiPaymentPatient from "./components/Dashboards/PatientDash/Tabs/UpiPayment";
import Prescriptions from "./components/Dashboards/PatientDash/Tabs/Prescriptions";
import Feedback from "./components/Dashboards/PatientDash/Tabs/Feedback";
import StaffDash from "./components/Dashboards/StaffDash/StaffDash";
import BookAppointmentStaff from "./components/Dashboards/StaffDash/Tabs/BookAppointment";
import CancelAppointment from "./components/Dashboards/StaffDash/Tabs/CancelAppointment";
import MakePaymentStaff from "./components/Dashboards/StaffDash/Tabs/MakePayment";
import CardPaymentStaff from "./components/Dashboards/StaffDash/Tabs/CardPayment";
import UpiPaymentStaff from "./components/Dashboards/StaffDash/Tabs/UpiPayment";
import CashPayment from "./components/Dashboards/StaffDash/Tabs/CashPayment";
import DoctorDash from "./components/Dashboards/DoctorDash/DoctorDash";
import Appointments from "./components/Dashboards/DoctorDash/Tabs/Appointments";
import UploadPrescription from "./components/Dashboards/DoctorDash/Tabs/UploadPrescription";
import AdminDash from "./components/Dashboards/AdminDash/AdminDash";
import DocList from "./components/Dashboards/AdminDash/Tabs/DocList";
import AddNew from "./components/Dashboards/AdminDash/Tabs/AddNew";
import GenerateStats from "./components/Dashboards/AdminDash/Tabs/GenerateStats";
import VerifySignUp from "./components/Dashboards/AdminDash/Tabs/VerifySignUp";
import Feedbacks from "./components/Dashboards/AdminDash/Tabs/Feedbacks";

export const AuthContext = React.createContext();
import MyRouter from "./Router";

function App() {
const [userType, setUserType] = useState(
jwt.decode(localStorage.getItem("accessToken"))?.userType
);
useEffect(() => {
const token = localStorage.getItem("accessToken");
const payload = token && jwt.decode(token);
const userTyp = payload && payload.userType;
setUserType(userTyp && userTyp);
}, []);

return (
<Router>
<Routes>
<Route path="/" exact element={<HomePage />} />
<Route
path="/signin"
exact
element={
userType ? (
<Navigate to={`/dashboard/${userType}`} />
) : (
<AuthContext.Provider value={{ setUserType }}>
<SignIn />
</AuthContext.Provider>
)
}
/>
<Route
path="/signup"
exact
element={
userType ? <Navigate to={`/dashboard/${userType}`} /> : <SignUp />
}
/>
{/*----------> Admin Routes <------------- */}
{userType === "admin" && (
<Fragment>
<Route
path="/dashboard/admin"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<AdminDash />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/admin/doctors'-list"
element={
<AuthContext.Provider value={{ setUserType }}>
<DocList />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/admin/doctors'-list/add-new"
element={
<AuthContext.Provider value={{ setUserType }}>
<AddNew />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/admin/generate-stats"
element={
<AuthContext.Provider value={{ setUserType }}>
<GenerateStats />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/admin/verify-signup"
element={
<AuthContext.Provider value={{ setUserType }}>
<VerifySignUp />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/admin/generate-stats/feedbacks"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<Feedbacks />
</AuthContext.Provider>
}
/>
</Fragment>
)}
{/*----------> Doctor Routes <------------- */}
{userType === "doctor" && (
<Fragment>
<Route
path="/dashboard/doctor"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<DoctorDash />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/doctor/appointments"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<Appointments />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/doctor/upload-prescription"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<UploadPrescription />
</AuthContext.Provider>
}
/>
</Fragment>
)}
{/*----------> Patient Routes <------------- */}
{userType === "patient" && (
<Fragment>
<Route
path="/dashboard/patient"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<PatientDash />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/patient/view-location"
exact
element={<ViewLocation />}
/>
<Route
path="/dashboard/patient/my-appointments"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<MyAppointments />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/patient/book-appointment"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<BookAppointment linkto="patient" />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/patient/make-payment"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<MakePaymentPatinet />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/patient/make-payment/card-payment"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<CardPaymentPatient />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/patient/make-payment/upi-payment"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<UpiPaymentPatient />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/patient/prescriptions"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<Prescriptions />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/patient/feedback"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<Feedback />
</AuthContext.Provider>
}
/>
</Fragment>
)}
{/*----------> Staff Routes <------------- */}
{userType === "staff" && (
<Fragment>
<Route
path="/dashboard/staff"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<StaffDash />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/staff/book-appointment"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<BookAppointmentStaff linkto="staff" />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/staff/cancel-appointment"
element={
<AuthContext.Provider value={{ setUserType }}>
<CancelAppointment />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/staff/make-payment"
exact
element={
<AuthContext.Provider value={{ setUserType }}>
<MakePaymentStaff />
</AuthContext.Provider>
}
/>
<Route
path="/dashboard/staff/make-payment/card-payment"
element={<CardPaymentStaff />}
/>
<Route
path="/dashboard/staff/make-payment/upi-payment"
element={<UpiPaymentStaff />}
/>
<Route
path="/dashboard/staff/make-payment/cash-payment"
element={<CashPayment />}
/>
</Fragment>
)}
{/*----------> Unknown Routes <------------- */}
<Route
path="*"
element={
<AuthContext.Provider value={{ userType }}>
<Page404 />
</AuthContext.Provider>
}
/>
</Routes>
</Router>
<MyRouter />
);
}

Expand Down
50 changes: 50 additions & 0 deletions src/Router/adminRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

import { AuthContext } from '.';
import DocList from '../pages/AdminDash/Tabs/DocList';
import AddNew from '../pages/AdminDash/Tabs/AddNew';
import GenerateStats from '../pages/AdminDash/Tabs/GenerateStats';
import Feedbacks from '../pages/AdminDash/Tabs/Feedbacks';
import VerifySignUp from '../pages/AdminDash/Tabs/VerifySignUp';
import AdminDash from '../pages/AdminDash';


const adminRouter = (setUserType) => [
{
path: '/dashboard/admin',
element: <AuthContext.Provider value={{ setUserType }}>
<AdminDash />
</AuthContext.Provider>
},
{
path: `/dashboard/admin/doctors'-list`,
element: <AuthContext.Provider value={{ setUserType }}>
<DocList />
</AuthContext.Provider>
},
{
path: `/dashboard/admin/doctors'-list/add-new`,
element: <AuthContext.Provider value={{ setUserType }}>
<AddNew />
</AuthContext.Provider>
},
{
path: `/dashboard/admin/generate-stats`,
element: <AuthContext.Provider value={{ setUserType }}>
<GenerateStats />
</AuthContext.Provider>
},
{
path: `/dashboard/admin/verify-signup`,
element: <AuthContext.Provider value={{ setUserType }}>
<VerifySignUp />
</AuthContext.Provider>
},
{
path: `/dashboard/admin/generate-stats/feedbacks`,
element: <AuthContext.Provider value={{ setUserType }}>
<Feedbacks />
</AuthContext.Provider>
},
]

export default adminRouter
Loading