Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide Facility link and unlink button for non-admin users #7738

Merged
merged 12 commits into from
Jun 14, 2024
154 changes: 81 additions & 73 deletions src/Components/Users/ManageUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ export function UserFacilities(props: { user: any }) {
facility?: FacilityModel;
isHomeFacility: boolean;
}>({ show: false, userName: "", facility: undefined, isHomeFacility: false });
const authUser = useAuthUser();

const [replaceHomeFacility, setReplaceHomeFacility] = useState<{
show: boolean;
Expand Down Expand Up @@ -762,39 +763,39 @@ export function UserFacilities(props: { user: any }) {
{user?.home_facility_object && (
<div className="py-2" id="home-facility">
<div className="relative rounded p-2 transition hover:bg-gray-200 focus:bg-gray-200 md:rounded-lg">
<div className="flex items-center justify-between gap-2">
<div className="flex content-center items-center justify-center gap-2">
<span>{user?.home_facility_object?.name}</span>{" "}
<span
className={
"flex items-center justify-center rounded-xl bg-green-600 px-2 py-0.5 text-sm font-medium text-white"
}
>
<CareIcon
icon="l-estate"
className="mr-1 pt-px text-lg"
/>
Home Facility
</span>
</div>
<div className="flex items-center gap-2">
<button
className="tooltip text-lg text-red-600"
onClick={() =>
setUnlinkFacilityData({
show: true,
facility: user?.home_facility_object,
userName: username,
isHomeFacility: true,
})
}
>
<CareIcon icon="l-link-broken" />
<span className="tooltip-text tooltip-left">
{t("clear_home_facility")}
</span>
</button>
</div>
<div className="flex items-center justify-between">
<span>{user?.home_facility_object?.name}</span>
<span
className={
"flex items-center justify-center rounded-xl bg-green-600 px-2 py-0.5 text-sm font-medium text-white"
}
>
<CareIcon icon="l-estate" className="mr-1 pt-px text-lg" />
Home Facility
</span>
{(["DistrictAdmin", "StateAdmin"].includes(
authUser.user_type,
) ||
username === authUser.username) && (
<div className="flex items-center gap-2">
<button
className="tooltip text-lg text-red-600"
onClick={() =>
setUnlinkFacilityData({
show: true,
facility: user?.home_facility_object,
userName: username,
isHomeFacility: true,
})
}
>
<CareIcon icon="l-link-broken" />
<span className="tooltip-text tooltip-left">
{t("clear_home_facility")}
</span>
</button>
</div>
)}
</div>
</div>
</div>
Expand All @@ -820,49 +821,56 @@ export function UserFacilities(props: { user: any }) {
>
<div className="flex items-center justify-between">
<span>{facility.name}</span>
<div className="flex items-center gap-2">
<button
className="tooltip text-lg hover:text-primary-500"
id="home-facility-icon"
onClick={() => {
if (user?.home_facility_object) {
// has previous home facility
setReplaceHomeFacility({
{(["DistrictAdmin", "StateAdmin"].includes(
authUser.user_type,
) ||
username === authUser.username) && (
<div className="flex items-center gap-2">
{authUser.user_type !== "Nurse" && (
<button
className="tooltip text-lg hover:text-primary-500"
id="home-facility-icon"
onClick={() => {
if (user?.home_facility_object) {
// has previous home facility
setReplaceHomeFacility({
show: true,
userName: username,
previousFacility:
user?.home_facility_object,
newFacility: facility,
});
} else {
// no previous home facility
updateHomeFacility(username, facility);
}
}}
>
<CareIcon icon="l-estate" />
<span className="tooltip-text tooltip-left">
Set as home facility
</span>
</button>
)}
<button
id="unlink-facility-button"
className="tooltip text-lg text-red-600"
onClick={() => {
setUnlinkFacilityData({
show: true,
facility: facility,
userName: username,
previousFacility:
user?.home_facility_object,
newFacility: facility,
isHomeFacility: false,
});
} else {
// no previous home facility
updateHomeFacility(username, facility);
}
}}
>
<CareIcon icon="l-estate" />
<span className="tooltip-text tooltip-left">
Set as home facility
</span>
</button>
<button
id="unlink-facility-button"
className="tooltip text-lg text-red-600"
onClick={() =>
setUnlinkFacilityData({
show: true,
facility: facility,
userName: username,
isHomeFacility: false,
})
}
>
<CareIcon icon="l-link-broken" />
<span className="tooltip-text tooltip-left">
Unlink Facility
</span>
</button>
</div>
}}
>
<CareIcon icon="l-link-broken" />
<span className="tooltip-text tooltip-left">
Unlink Facility
</span>
</button>
</div>
)}
</div>
</div>
);
Expand Down
Loading