Skip to content

Commit

Permalink
U4X-491 : Default users to their queues page based on their Roles sin…
Browse files Browse the repository at this point in the history
…ce patient queues has been removed (#21)

U4X-491 : Default users to their queues page based on their Roles since patient queues has been removed (#21)
  • Loading branch information
jabahum authored Mar 28, 2024
1 parent 0033f5d commit f9cbe2a
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions src/login/login.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TextInput,
Tile,
} from "@carbon/react";
import { ArrowRight } from "@carbon/react/icons";
import { ArrowRight, IbmTelehealth } from "@carbon/react/icons";
import { useTranslation } from "react-i18next";
import {
clearCurrentUser,
Expand Down Expand Up @@ -45,17 +45,50 @@ const Login: React.FC<LoginReferrer> = () => {
const formRef = useRef<HTMLFormElement>(null);
const [hasUserLocation, setHasUserLocation] = useState(false);
useEffect(() => {
if (hasUserLocation || user) {
const { pathname } = location;

const handleAuthenticatedUser = () => {
clearCurrentUser();
refetchCurrentUser().then(() => {
const authenticated =
getSessionStore().getState().session.authenticated;

if (authenticated) {
navigate({ to: config.links.loginSuccess });
const roles = getSessionStore().getState().session?.user?.roles;

if (roles && roles.length > 0) {
if (roles.length > 1) {
const filteredRoles = roles.filter(
(item) => item?.display === "Provider"
);
if (filteredRoles.length > 0) {
navigate({
to: `${window.getOpenmrsSpaBase()}home/clinical-room-patient-queues`,
});
return;
}
} else {
const role = roles[0]?.display;
if (role === "Triage") {
navigate({
to: `${window.getOpenmrsSpaBase()}home/triage-patient-queues`,
});
} else if (role === "Reception") {
navigate({
to: `${window.getOpenmrsSpaBase()}home/reception-patient-queues`,
});
}
return;
}
}
}
});
} else if (!username && location.pathname === "/login/confirm") {
nav("/login", { state: location.state });
};

if (hasUserLocation || user) {
handleAuthenticatedUser();
} else if (!username && pathname === "/login/confirm") {
nav("/login", { state: location?.state });
}
}, [
username,
Expand Down

0 comments on commit f9cbe2a

Please sign in to comment.