Skip to content

Commit

Permalink
fix lint and remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Apr 16, 2024
1 parent b041e47 commit 68efb17
Showing 1 changed file with 9 additions and 132 deletions.
141 changes: 9 additions & 132 deletions src/Components/Facility/FacilityUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@ 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";
Expand All @@ -29,9 +23,7 @@ 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<any | null>(null);
Expand All @@ -49,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, {
Expand All @@ -81,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 },
});
Expand All @@ -98,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 = () => {
Expand All @@ -123,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: "" });
};
Expand All @@ -164,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",
);
//change iver here
const showLinkFacility = (username: string) => {
return (
<a
onClick={() => showLinkFacilityModal(username)}
className={facilityClassname}
href="#"
>
Link new facility
</a>
);
};

const showFacilities = (username: string, facilities: FacilityModel[]) => {
if (!facilities || !facilities.length) {
return (
<>
<div className="font-semibold">No Facilities!</div>
{showLinkFacility(username)}
</>
);
}
return (
<div className="col-span-full sm:col-span-3 sm:col-start-2">
<div className="mb-2">
{facilities.map((facility, i) => (
<div
key={`facility_${i}`}
className="font-gbold mr-3 mt-2 inline-block rounded-md border-2 py-1 pl-3"
>
<div className="flex items-center space-x-1">
<div className="font-semibold">{facility.name}</div>
<ButtonV2
size="small"
circle
variant="secondary"
disabled={isUnlinkFacilityLoading}
onClick={() =>
setUnlinkFacilityData({
show: true,
facility: facility,
userName: username,
})
}
>
<CareIcon icon="l-multiply" />
</ButtonV2>
</div>
</div>
))}
</div>
{showLinkFacility(username)}
{unlinkFacilityData.show && (
<UnlinkFacilityDialog
facilityName={unlinkFacilityData.facility?.name || ""}
userName={unlinkFacilityData.userName}
isHomeFacility={false}
handleCancel={hideUnlinkFacilityModal}
handleOk={handleUnlinkFacilitySubmit}
/>
)}
</div>
);
};

const addFacility = async (username: string, facility: any) => {
hideLinkFacilityModal();
setIsAddFacilityLoading(true);
Expand Down Expand Up @@ -330,13 +207,13 @@ export default function FacilityUsers(props: any) {
id="facilities"
className="flex w-full items-center @sm:w-1/2"
onClick={() => {
setExpandFacilityList(!expandFacilityList);
setSelectedUser(user);
}}
>
<CareIcon icon="l-hospital" className="text-lg" />
<p>Linked Facilities</p>
</ButtonV2>
setExpandFacilityList(!expandFacilityList);
setSelectedUser(user);
}}
>
<CareIcon icon="l-hospital" className="text-lg" />
<p>Linked Facilities</p>
</ButtonV2>
</UserDetails>
)}
</div>
Expand Down

0 comments on commit 68efb17

Please sign in to comment.