Skip to content

Commit

Permalink
Facility Id in User Profile for Nav User (#9857)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacobjeevan authored Jan 13, 2025
1 parent 578e1ec commit fc4c3d5
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
8 changes: 7 additions & 1 deletion src/components/Common/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ const capitalize = (string: string) =>

interface BreadcrumbsProps {
replacements?: {
[key: string]: { name?: string; uri?: string; style?: string };
[key: string]: {
name?: string;
uri?: string;
style?: string;
hide?: boolean;
};
};
className?: string;
hideBack?: boolean;
Expand All @@ -62,6 +67,7 @@ export default function Breadcrumbs({
const crumbs = path
?.slice(1)
.split("/")
.filter((field) => replacements[field]?.hide !== true)
.map((field, i) => ({
name: replacements[field]?.name || MENU_TAGS[field] || capitalize(field),
uri:
Expand Down
7 changes: 6 additions & 1 deletion src/components/Common/PageTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export interface PageTitleProps {
componentRight?: ReactNode;
breadcrumbs?: boolean;
crumbsReplacements?: {
[key: string]: { name?: string; uri?: string; style?: string };
[key: string]: {
name?: string;
uri?: string;
style?: string;
hide?: boolean;
};
};
focusOnLoad?: boolean;
isInsidePage?: boolean;
Expand Down
24 changes: 17 additions & 7 deletions src/components/Users/UserHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,28 @@ export default function UserHome(props: UserHomeProps) {
}

const SelectedTab = TABS[currentTab].body;
const userUrl = props.facilityId
? `/facility/${props.facilityId}/users/${username}`
: `/users/${username}`;

const usernameCrumb = {
[username]: { name: loggedInUser ? "Profile" : username },
};

const hideUsersCrumb = { users: { hide: true } };

const crumbsReplacements = {
...usernameCrumb,
...(!props.facilityId && hideUsersCrumb),
};

return (
<>
<Page
title={formatName(userData) || userData.username || t("manage_user")}
crumbsReplacements={
loggedInUser
? { [username]: { name: "Profile" } }
: { [username]: { name: username } }
}
crumbsReplacements={crumbsReplacements}
focusOnLoad={true}
backUrl="/users"
backUrl={props.facilityId ? `/users` : "/"}
hideTitleOnPage
>
{
Expand All @@ -120,7 +130,7 @@ export default function UserHome(props: UserHomeProps) {
? "border-b-2 border-primary-500 text-primary-600 hover:border-secondary-300"
: "text-secondary-700 hover:text-secondary-700",
)}
href={`/facility/${props.facilityId}/users/${username}/${p.toLocaleLowerCase()}`}
href={`${userUrl}/${p.toLocaleLowerCase()}`}
>
<div className="px-3 py-1.5" id={p.toLowerCase()}>
{t(`USERMANAGEMENT_TAB__${p}`)}
Expand Down
8 changes: 7 additions & 1 deletion src/components/ui/sidebar/app-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ export function AppSidebar({
</SidebarContent>

<SidebarFooter>
{(facilitySidebar || selectedOrganization) && <FacilityNavUser />}
{(facilitySidebar || selectedOrganization) && (
<FacilityNavUser
selectedFacilityId={
facilitySidebar ? selectedFacility?.id : undefined
}
/>
)}
{patientSidebar && <PatientNavUser />}
</SidebarFooter>

Expand Down
11 changes: 9 additions & 2 deletions src/components/ui/sidebar/nav-user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import useAuthUser, { useAuthContext } from "@/hooks/useAuthUser";
import { usePatientSignOut } from "@/hooks/usePatientSignOut";
import { usePatientContext } from "@/hooks/usePatientUser";

export function FacilityNavUser() {
export function FacilityNavUser({
selectedFacilityId,
}: {
selectedFacilityId: string | undefined;
}) {
const { t } = useTranslation();
const user = useAuthUser();
const { isMobile, open, setOpenMobile } = useSidebar();
Expand Down Expand Up @@ -94,7 +98,10 @@ export function FacilityNavUser() {
<DropdownMenuGroup>
<DropdownMenuItem
onClick={() => {
navigate(`/users/${user.username}`);
const profileUrl = selectedFacilityId
? `/facility/${selectedFacilityId}/users/${user.username}`
: `/users/${user.username}`;
navigate(profileUrl);
if (isMobile) {
setOpenMobile(false);
}
Expand Down

0 comments on commit fc4c3d5

Please sign in to comment.