fix: super admin dashboard

fix: clinic list fitler counts
This commit is contained in:
deepvasoya 2025-05-21 11:54:59 +05:30
parent 35f21f2749
commit 60d187b300
3 changed files with 15 additions and 16 deletions

View File

@ -31,9 +31,9 @@ export const isBSPortal = () => {
return { isSuperAdmin }; return { isSuperAdmin };
}; };
export const commonLogoutFunc = async (redirectPath = "/auth/login") => { export const commonLogoutFunc = async () => {
try { try {
await logout(); // await logout();
resetLocalStorage(); resetLocalStorage();
// Try to delete the Firebase messaging token, but don't let it block logout if it fails // Try to delete the Firebase messaging token, but don't let it block logout if it fails
try { try {
@ -42,12 +42,12 @@ export const commonLogoutFunc = async (redirectPath = "/auth/login") => {
console.warn('Failed to delete Firebase messaging token:', error); console.warn('Failed to delete Firebase messaging token:', error);
// Continue with logout even if token deletion fails // Continue with logout even if token deletion fails
} }
window.location.replace(redirectPath); window.location.replace("/");
} catch (error) { } catch (error) {
console.error('Error during logout:', error); console.error('Error during logout:', error);
// Ensure user is still logged out even if there's an error // Ensure user is still logged out even if there's an error
resetLocalStorage(); resetLocalStorage();
window.location.replace(redirectPath); window.location.replace("/");
} }
}; };

View File

@ -8,8 +8,6 @@ import { differenceInDays, format } from 'date-fns';
import { LoadingButton } from '@mui/lab'; import { LoadingButton } from '@mui/lab';
import FileDownloadIcon from '@mui/icons-material/FileDownload'; import FileDownloadIcon from '@mui/icons-material/FileDownload';
import { useStyles } from "./clinicListStyles"; import { useStyles } from "./clinicListStyles";
import { CLINIC_STATUS, CLINIC_TYPE, NOT_AVAILABLE_TEXT, PLAN_STATUS_TYPE } from "../../constants"; import { CLINIC_STATUS, CLINIC_TYPE, NOT_AVAILABLE_TEXT, PLAN_STATUS_TYPE } from "../../constants";
import { getClinics } from "../../services/clinics.service"; import { getClinics } from "../../services/clinics.service";
@ -32,6 +30,8 @@ const ClinicsList = () => {
const showNewPlanAddedModel = const showNewPlanAddedModel =
Boolean(queryParams.get("isPlanCreated")) ?? false; Boolean(queryParams.get("isPlanCreated")) ?? false;
const [isDownloading, setIsDownloading] = useState(false); const [isDownloading, setIsDownloading] = useState(false);
const[totalActive, setTotalActive] = useState(0);
const[totalInactive, setTotalInactive] = useState(0);
const [showModel, setShowModel] = useState(false); const [showModel, setShowModel] = useState(false);
const [modelType, setModelType] = useState(""); const [modelType, setModelType] = useState("");
const [rowActionData, setRowActionData] = useState(""); const [rowActionData, setRowActionData] = useState("");
@ -406,7 +406,8 @@ const ClinicsList = () => {
type, type,
}; };
const resp = await getClinics(params); const resp = await getClinics(params);
console.log(resp) setTotalActive(resp?.data?.data?.data?.totalRegisteredClinics);
setTotalInactive(resp?.data?.data?.data?.totalRejectedClinics);
return { return {
data: resp?.data?.data?.data?.clinics, data: resp?.data?.data?.data?.clinics,
rowCount: resp?.data?.data?.total, rowCount: resp?.data?.data?.total,
@ -467,8 +468,8 @@ const ClinicsList = () => {
extraComponent={ extraComponent={
<Box className={classes.tabsBox}> <Box className={classes.tabsBox}>
<Tabs value={type} onChange={handleTabsChange}> <Tabs value={type} onChange={handleTabsChange}>
<Tab value={CLINIC_TYPE.UNREGISTERED} label="Unregistered (2)" /> <Tab value={CLINIC_TYPE.UNREGISTERED} label={`Unregistered (${totalInactive})`} />
<Tab value={CLINIC_TYPE.REGISTERED} label="Registered (2)" /> <Tab value={CLINIC_TYPE.REGISTERED} label={`Registered (${totalActive})`} />
{/* <Tab value={COMPANY_TYPE.SUBSCRIBED} label="Subscribers" /> */} {/* <Tab value={COMPANY_TYPE.SUBSCRIBED} label="Subscribers" /> */}
</Tabs> </Tabs>
</Box> </Box>

View File

@ -80,22 +80,20 @@ function Dashboard() {
}; };
useEffect(() => { useEffect(() => {
getClinic();
// Determine user role based on user data from login reducer // Determine user role based on user data from login reducer
if (user) { if (user) {
// Check if user is a super admin // Check if user is a super admin
// This logic can be adjusted based on your specific role criteria // This logic can be adjusted based on your specific role criteria
const isSuperAdmin = const isSuperAdmin =
user.userType == USER_ROLES.SUPER_ADMIN.toLowerCase(); user.userType == USER_ROLES.SUPER_ADMIN.toLowerCase();
const clinicStatus = user.created_clinics[0].status;
setIsActive(clinicStatus == "active");
if (isSuperAdmin) { if (isSuperAdmin) {
dispatch(setUserRole(USER_ROLES.SUPER_ADMIN, clinicStatus)); dispatch(setUserRole(USER_ROLES.SUPER_ADMIN, ""));
} else { } else {
const clinicStatus = user.created_clinics[0].status;
setIsActive(clinicStatus == "active");
dispatch(setUserRole(USER_ROLES.CLINIC_ADMIN, clinicStatus)); dispatch(setUserRole(USER_ROLES.CLINIC_ADMIN, clinicStatus));
getClinic();
} }
} }
setIsLoading(false); setIsLoading(false);