-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify and scale the ACL logic for admin and non-admin roles
- Loading branch information
Showing
5 changed files
with
136 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from "react"; | ||
import { Navigate } from "react-router-dom"; | ||
import { useAuth } from "../../context/auth-context"; | ||
|
||
interface AdminRequiredProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
const AdminRequired: React.FC<AdminRequiredProps> = ({ children }) => { | ||
const { user } = useAuth(); | ||
|
||
if (!user || user.role !== "Admin") { | ||
return <Navigate to="/anauthorized" />; | ||
} | ||
|
||
return <>{children}</>; | ||
}; | ||
|
||
export default AdminRequired; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useNavigate } from "react-router-dom"; | ||
import Navbar from "../nav-bar/nav-bar"; | ||
import LeftsideBar from "../leftside-bar/leftside-bar"; | ||
import OrganiziationConfig from "../settings-dropdown/organization-configuration"; | ||
|
||
const Anauthorized = () => { | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<> | ||
<Navbar /> | ||
<div className="flex flex-row"> | ||
<LeftsideBar /> | ||
<OrganiziationConfig /> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default Anauthorized; |
27 changes: 27 additions & 0 deletions
27
src/Components/settings-dropdown/organization-configuration.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { useAuth } from "../../context/auth-context"; | ||
|
||
const OrganiziationConfig = () => { | ||
const { user } = useAuth(); | ||
const organizationId = user.organization._id; | ||
const [organizationName, setOrganizationName] = useState<string>(""); | ||
useEffect(() => { | ||
console.log(user); | ||
setOrganizationName(user.organization.name); | ||
}, [organizationId]); | ||
return ( | ||
<div className="flex-grow mx-auto align-middle text-left p-4 pr-8"> | ||
<h2 className="text-2xl font-bold mb-2.5">Organization Settings</h2> | ||
<p className="text-gray-600 text-sm">View your current settings.</p> | ||
<div className="flex flex-col mt-5"> | ||
<h3 className="text-lg font-semibold">General</h3> | ||
<div className="flex flex-col gap-2.5 border-b py-2.5 border-gray-300 text-base"> | ||
<span className="text-[#96ACC1]">Organization Name:</span> | ||
<span className="text-gray-700">{organizationName}</span> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default OrganiziationConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters