Skip to content

Commit

Permalink
refactor: fetch api style
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon-Chin committed Dec 12, 2023
1 parent ec4ab54 commit 9f5e27c
Show file tree
Hide file tree
Showing 7 changed files with 874 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@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",
Expand Down
48 changes: 48 additions & 0 deletions src/Router/adminRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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';


const adminRouter = [
{
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
26 changes: 26 additions & 0 deletions src/Router/doctorRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import DoctorDash from '../components/Dashboards/DoctorDash/DoctorDash';
import Appointments from '../components/Dashboards/DoctorDash/Tabs/Appointments';
import UploadPrescription from '../components/Dashboards/DoctorDash/Tabs/UploadPrescription';

const doctorRouter = [
{
path: '/dashboard/doctor',
element: <AuthContext.Provider value={{ setUserType }}>
<DoctorDash />
</AuthContext.Provider>
},
{
path: `/dashboard/doctor/appointments`,
element: <AuthContext.Provider value={{ setUserType }}>
<Appointments />
</AuthContext.Provider>
},
{
path: `/dashboard/doctor/upload-prescription`,
element: <AuthContext.Provider value={{ setUserType }}>
<UploadPrescription />
</AuthContext.Provider>
}
]

export default doctorRouter
65 changes: 65 additions & 0 deletions src/Router/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React, { useEffect, useState } from 'react';
import { createBrowserRouter, Navigate, RouterProvider } from 'react-router-dom'
import jwt from "jsonwebtoken";
import HomePage from '../components/HomePage/HomePage';
import SignIn from '../components/SignIn/SignIn';
import SignUp from '../components/SignUp/SignUp';
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';
import adminRouter from './adminRouter';
import doctorRouter from './doctorRouter';
import staffRouter from './staffRouter';

export const AuthContext = React.createContext();

export default function MyRouter() {
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);
}, []);



const router = createBrowserRouter([
{
path: '/',
element: <HomePage />
},
{
path: '/signin',
element: userType ? (
<Navigate to={`/dashboard/${userType}`} />
) : (
<AuthContext.Provider value={{ setUserType }}>
<SignIn />
</AuthContext.Provider>
),
},
{
path: '/signup',
element: userType ? <Navigate to={`/dashboard/${userType}`} /> : <SignUp />
},
userType === "admin" && { ...adminRouter },
userType === "doctor" && { ...doctorRouter },
userType === "staff" && { ...staffRouter },
{
path: '*',
element: <AuthContext.Provider value={{ userType }}>
<Page404 />
</AuthContext.Provider>,
// loader: async ({ params }) => await getonetutorial(params.tutorialID)
},
])
return (
<RouterProvider router={router} />
)
}
66 changes: 66 additions & 0 deletions src/Router/patientRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import PatientDash from '../components/Dashboards/PatientDash/PatientDash';
import BookAppointment from '../components/Dashboards/PatientDash/Tabs/BookAppointment';
import CardPaymentPatient from '../components/Dashboards/PatientDash/Tabs/CardPayment';
import Feedback from '../components/Dashboards/PatientDash/Tabs/Feedback';
import MakePaymentPatinet from '../components/Dashboards/PatientDash/Tabs/MakePayment';
import MyAppointments from '../components/Dashboards/PatientDash/Tabs/MyAppointments';
import Prescriptions from '../components/Dashboards/PatientDash/Tabs/Prescriptions';
import UpiPaymentPatient from '../components/Dashboards/PatientDash/Tabs/UpiPayment';
import ViewLocation from '../components/Dashboards/PatientDash/Tabs/ViewLocation';

const patientRouter = [
{
path: '/dashboard/patient',
element: <AuthContext.Provider value={{ setUserType }}>
<PatientDash />
</AuthContext.Provider>
},
{
path: "/dashboard/patient/view-location",
element: <ViewLocation />
},
{
path: "/dashboard/patient/my-appointments",
element: <AuthContext.Provider value={{ setUserType }}>
<MyAppointments />
</AuthContext.Provider>
},
{
path: "/dashboard/patient/book-appointment",
element: <AuthContext.Provider value={{ setUserType }}>
<BookAppointment />
</AuthContext.Provider>
},
{
path: "/dashboard/patient/make-payment",
element: <AuthContext.Provider value={{ setUserType }}>
<MakePaymentPatinet />
</AuthContext.Provider>
},
{
path: "/dashboard/patient/make-payment/card-payment",
element: <AuthContext.Provider value={{ setUserType }}>
<CardPaymentPatient />
</AuthContext.Provider>
},
{
path: "/dashboard/patient/make-payment/upi-payment",
element: <AuthContext.Provider value={{ setUserType }}>
<UpiPaymentPatient />
</AuthContext.Provider>
},
{
path: "/dashboard/patient/prescriptions",
element: <AuthContext.Provider value={{ setUserType }}>
<Prescriptions />
</AuthContext.Provider>
},
{
path: "/dashboard/patient/feedback",
element: <AuthContext.Provider value={{ setUserType }}>
<Feedback />
</AuthContext.Provider>
},
]

export default patientRouter
54 changes: 54 additions & 0 deletions src/Router/staffRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import StaffDash from '../components/Dashboards/StaffDash/StaffDash';
import BookAppointmentStaff from '../components/Dashboards/StaffDash/Tabs/BookAppointment';
import CancelAppointment from '../components/Dashboards/StaffDash/Tabs/CancelAppointment';
import CardPaymentStaff from '../components/Dashboards/StaffDash/Tabs/CardPayment';
import CashPayment from '../components/Dashboards/StaffDash/Tabs/CashPayment';
import MakePaymentStaff from '../components/Dashboards/StaffDash/Tabs/MakePayment';
import UpiPaymentStaff from '../components/Dashboards/StaffDash/Tabs/UpiPayment';

const staffRouter = [
{
path: '/dashboard/staff',
element: <AuthContext.Provider value={{ setUserType }}>
<StaffDash />
</AuthContext.Provider>
},
{
path: `/dashboard/staff/book-appointment`,
element: <AuthContext.Provider value={{ setUserType }}>
<BookAppointmentStaff />
</AuthContext.Provider>
},
{
path: `/dashboard/staff/cancel-appointment`,
element: <AuthContext.Provider value={{ setUserType }}>
<CancelAppointment />
</AuthContext.Provider>
},
{
path: `/dashboard/staff/make-payment`,
element: <AuthContext.Provider value={{ setUserType }}>
<MakePaymentStaff />
</AuthContext.Provider>
},
{
path: `/dashboard/staff/make-payment/card-payment`,
element: <AuthContext.Provider value={{ setUserType }}>
<CardPaymentStaff />
</AuthContext.Provider>
},
{
path: `/dashboard/staff/make-payment/upi-payment`,
element: <AuthContext.Provider value={{ setUserType }}>
<UpiPaymentStaff />
</AuthContext.Provider>
},
{
path: `/dashboard/staff/make-payment/cash-payment`,
element: <AuthContext.Provider value={{ setUserType }}>
<CashPayment />
</AuthContext.Provider>
}
]

export default staffRouter
Loading

0 comments on commit 9f5e27c

Please sign in to comment.