diff --git a/src/Components/Facility/FacilityUsers.tsx b/src/Components/Facility/FacilityUsers.tsx index 6e092e7a809..31ceb6e1937 100644 --- a/src/Components/Facility/FacilityUsers.tsx +++ b/src/Components/Facility/FacilityUsers.tsx @@ -3,28 +3,30 @@ import CountBlock from "../../CAREUI/display/Count"; import CareIcon from "../../CAREUI/icons/CareIcon"; import { RESULTS_PER_PAGE_LIMIT } from "../../Common/constants"; import * as Notification from "../../Utils/Notifications.js"; -import { classNames, isUserOnline, relativeTime } from "../../Utils/utils"; +import { isUserOnline, relativeTime } from "../../Utils/utils"; +import SlideOverCustom from "../../CAREUI/interactive/SlideOver"; import Pagination from "../Common/Pagination"; import UserDetails from "../Common/UserDetails"; import ButtonV2 from "../Common/components/ButtonV2"; import Page from "../Common/components/Page"; -import { FacilityModel } from "../Facility/models"; import LinkFacilityDialog from "../Users/LinkFacilityDialog"; -import UnlinkFacilityDialog from "../Users/UnlinkFacilityDialog"; import UserDeleteDialog from "../Users/UserDeleteDialog"; import request from "../../Utils/request/request"; import routes from "../../Redux/api"; import useQuery from "../../Utils/request/useQuery"; +import { UserFacilities } from "../Users/ManageUsers"; +import { useTranslation } from "react-i18next"; const Loading = lazy(() => import("../Common/Loading")); export default function FacilityUsers(props: any) { + const { t } = useTranslation(); const { facilityId } = props; let manageUsers: any = null; - const [isUnlinkFacilityLoading, setIsUnlinkFacilityLoading] = useState(false); const [isAddFacilityLoading, setIsAddFacilityLoading] = useState(false); - const [isLoadFacilityLoading, setIsLoadFacilityLoading] = useState(false); const [currentPage, setCurrentPage] = useState(1); + const [expandFacilityList, setExpandFacilityList] = useState(false); + const [selectedUser, setSelectedUser] = useState(null); // eslint-disable-next-line @typescript-eslint/no-unused-vars const [offset, setOffset] = useState(0); @@ -39,12 +41,6 @@ export default function FacilityUsers(props: any) { name: string; }>({ show: false, username: "", name: "" }); - const [unlinkFacilityData, setUnlinkFacilityData] = useState<{ - show: boolean; - userName: string; - facility?: FacilityModel; - }>({ show: false, userName: "", facility: undefined }); - const limit = RESULTS_PER_PAGE_LIMIT; const { data: facilityData } = useQuery(routes.getAnyFacility, { @@ -71,10 +67,9 @@ export default function FacilityUsers(props: any) { }; const loadFacilities = async (username: string) => { - if (isUnlinkFacilityLoading || isAddFacilityLoading) { + if (isAddFacilityLoading) { return; } - setIsLoadFacilityLoading(true); const { res, data } = await request(routes.userListFacility, { pathParams: { username: username }, }); @@ -88,22 +83,6 @@ export default function FacilityUsers(props: any) { : user; }); } - setIsLoadFacilityLoading(false); - }; - - const showLinkFacilityModal = (username: string) => { - setLinkFacility({ - show: true, - username, - }); - }; - - const hideUnlinkFacilityModal = () => { - setUnlinkFacilityData({ - show: false, - facility: undefined, - userName: "", - }); }; const hideLinkFacilityModal = () => { @@ -113,27 +92,6 @@ export default function FacilityUsers(props: any) { }); }; - const handleUnlinkFacilitySubmit = async () => { - setIsUnlinkFacilityLoading(true); - await request(routes.deleteUserFacility, { - // body given in the dispatch call but there is no body in API documentation - body: { facility: String(unlinkFacilityData?.facility?.id) }, - pathParams: { - username: unlinkFacilityData.userName, - }, - onResponse: ({ res }) => { - if (res?.status === 204) { - Notification.Success({ - msg: "User Facility deleted successfully", - }); - } - }, - }); - setIsUnlinkFacilityLoading(false); - loadFacilities(unlinkFacilityData.userName); - hideUnlinkFacilityModal(); - }; - const handleCancel = () => { setUserData({ show: false, username: "", name: "" }); }; @@ -154,77 +112,6 @@ export default function FacilityUsers(props: any) { facilityUserFetch(); }; - const facilityClassname = classNames( - "align-baseline text-sm font-bold", - isAddFacilityLoading || isUnlinkFacilityLoading || isLoadFacilityLoading - ? "text-gray-500" - : "text-blue-500 hover:text-blue-800", - ); - - const showLinkFacility = (username: string) => { - return ( - showLinkFacilityModal(username)} - className={facilityClassname} - href="#" - > - Link new facility - - ); - }; - - const showFacilities = (username: string, facilities: FacilityModel[]) => { - if (!facilities || !facilities.length) { - return ( - <> -
No Facilities!
- {showLinkFacility(username)} - - ); - } - return ( -
-
- {facilities.map((facility, i) => ( -
-
-
{facility.name}
- - setUnlinkFacilityData({ - show: true, - facility: facility, - userName: username, - }) - } - > - - -
-
- ))} -
- {showLinkFacility(username)} - {unlinkFacilityData.show && ( - - )} -
- ); - }; - const addFacility = async (username: string, facility: any) => { hideLinkFacilityModal(); setIsAddFacilityLoading(true); @@ -316,17 +203,17 @@ export default function FacilityUsers(props: any) { {user.username && ( - {(user as any).facilities && - showFacilities(user.username, (user as any).facilities)} - {!(user as any).facilities && ( - loadFacilities(user.username)} - className={`inline-block ${facilityClassname}`} - href="#" - > - Click here to show - - )} + { + setExpandFacilityList(!expandFacilityList); + setSelectedUser(user); + }} + > + +

Linked Facilities

+
)} @@ -393,6 +280,15 @@ export default function FacilityUsers(props: any) { /> )} + + +
{manageUsers}
diff --git a/src/Components/Users/ManageUsers.tsx b/src/Components/Users/ManageUsers.tsx index 460cf712127..b0207fd1a77 100644 --- a/src/Components/Users/ManageUsers.tsx +++ b/src/Components/Users/ManageUsers.tsx @@ -564,7 +564,7 @@ export default function ManageUsers() { ); } -function UserFacilities(props: { user: any }) { +export function UserFacilities(props: { user: any }) { const { t } = useTranslation(); const { user } = props; const username = user.username;