added dynamically master menu
This commit is contained in:
parent
75c81ecc0c
commit
33c8b690ef
@ -11,7 +11,16 @@ import showToast from "../../services/toastService";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export const useMasterMenu = ()=>{
|
||||||
|
return useQuery({
|
||||||
|
queryKey:["MasterMenu"],
|
||||||
|
queryFn:async()=> {
|
||||||
|
debugger
|
||||||
|
const resp = await MasterRespository.getMasterMenus();
|
||||||
|
return resp.data
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export const useActivitiesMaster = () =>
|
export const useActivitiesMaster = () =>
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import MasterModal from "../../components/master/MasterModal";
|
|||||||
import { mastersList } from "../../data/masters";
|
import { mastersList } from "../../data/masters";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { changeMaster } from "../../slices/localVariablesSlice";
|
import { changeMaster } from "../../slices/localVariablesSlice";
|
||||||
import useMaster from "../../hooks/masterHook/useMaster"
|
import useMaster, { useMasterMenu } from "../../hooks/masterHook/useMaster"
|
||||||
import MasterTable from "./MasterTable";
|
import MasterTable from "./MasterTable";
|
||||||
import { getCachedData } from "../../slices/apiDataManager";
|
import { getCachedData } from "../../slices/apiDataManager";
|
||||||
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
@ -13,6 +13,7 @@ import { useQueryClient } from "@tanstack/react-query";
|
|||||||
|
|
||||||
|
|
||||||
const MasterPage = () => {
|
const MasterPage = () => {
|
||||||
|
const {data,isLoading,isError,error:menuError} = useMasterMenu()
|
||||||
const [modalConfig, setModalConfig] = useState({ modalType: "", item: null, masterType: null });
|
const [modalConfig, setModalConfig] = useState({ modalType: "", item: null, masterType: null });
|
||||||
const [searchTerm, setSearchTerm] = useState('');
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
const [filteredResults, setFilteredResults] = useState([]);
|
const [filteredResults, setFilteredResults] = useState([]);
|
||||||
@ -23,7 +24,7 @@ const MasterPage = () => {
|
|||||||
const selectedMaster = useSelector((store) => store.localVariables.selectedMaster);
|
const selectedMaster = useSelector((store) => store.localVariables.selectedMaster);
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
const { data: masterData = [], loading, error, RecallApi } = useMaster();
|
const { data: masterData = [], loading, error, RecallApi,isError:isMasterError } = useMaster();
|
||||||
|
|
||||||
const openModal = () => setIsCreateModalOpen(true);
|
const openModal = () => setIsCreateModalOpen(true);
|
||||||
|
|
||||||
@ -83,7 +84,10 @@ const MasterPage = () => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
if(isError || isMasterError) return <div className="d-flex flex-column align-items-center justify-content-center py-5">
|
||||||
|
<h4 className=" mb-3"><i className="fa-solid fa-triangle-exclamation fs-5" /> Oops, an error occurred</h4>
|
||||||
|
<p className="text-muted">{error?.message || menuError?.message}</p>
|
||||||
|
</div>
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isCreateModalOpen && (
|
{isCreateModalOpen && (
|
||||||
@ -121,8 +125,8 @@ const MasterPage = () => {
|
|||||||
className="form-select form-select-sm"
|
className="form-select form-select-sm"
|
||||||
value={selectedMaster}
|
value={selectedMaster}
|
||||||
>
|
>
|
||||||
|
{isLoading && (<option value={null}>Loading...</option>)}
|
||||||
{mastersList.map((item) => (
|
{(!isLoading && data) && data?.map((item) => (
|
||||||
|
|
||||||
<option key={item.id} value={item.name}>{item.name}</option>
|
<option key={item.id} value={item.name}>{item.name}</option>
|
||||||
))}
|
))}
|
||||||
@ -154,7 +158,6 @@ const MasterPage = () => {
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
className={`btn btn-sm add-new btn-primary `}
|
className={`btn btn-sm add-new btn-primary `}
|
||||||
// ${hasUserPermission('660131a4-788c-4739-a082-cbbf7879cbf2') ? "":"d-none"}
|
|
||||||
tabIndex="0"
|
tabIndex="0"
|
||||||
aria-controls="DataTables_Table_0"
|
aria-controls="DataTables_Table_0"
|
||||||
type="button"
|
type="button"
|
||||||
@ -162,7 +165,6 @@ const MasterPage = () => {
|
|||||||
data-bs-target="#master-modal"
|
data-bs-target="#master-modal"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleModalData(selectedMaster, "null", selectedMaster)
|
handleModalData(selectedMaster, "null", selectedMaster)
|
||||||
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span>
|
<span>
|
||||||
|
|||||||
@ -18,6 +18,8 @@ export const RolesRepository = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const MasterRespository = {
|
export const MasterRespository = {
|
||||||
|
getMasterMenus:()=>api.get("/api/AppMenu/get/master-list"),
|
||||||
|
|
||||||
getRoles: () => api.get("/api/roles"),
|
getRoles: () => api.get("/api/roles"),
|
||||||
createRole: (data) => api.post("/api/roles", data),
|
createRole: (data) => api.post("/api/roles", data),
|
||||||
updateRoles: (id, data) => api.put(`/api/roles/${id}`, data),
|
updateRoles: (id, data) => api.put(`/api/roles/${id}`, data),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user