Skip to content

Commit

Permalink
made requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijv256 committed Sep 30, 2023
1 parent 08d6244 commit 8d3222a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 77 deletions.
24 changes: 13 additions & 11 deletions src/Components/Assets/AssetFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,28 @@ function AssetFilter(props: any) {
const [locationId, setLocationId] = useState<string | "">(filter.location);
const [qParams, _] = useQueryParams();

const { data: facilityData } = useQuery(routes.getPermittedFacility, {
useQuery(routes.getPermittedFacility, {
pathParams: { id: facilityId },
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setFacility(data);
}
},
});

const { data: locationData } = useQuery(routes.getFacilityAssetLocation, {
useQuery(routes.getFacilityAssetLocation, {
pathParams: {
facilityId: String(facilityId),
locationId: String(locationId),
},
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setLocation(data);
}
},
prefetch: !!(facilityId && locationId),
});

useEffect(() => {
if (facilityData) {
setFacility(facilityData);
}
if (locationData) {
setLocation(locationData);
}
}, [facilityData, locationData]);

useEffect(() => {
setFacilityId(facility?.id ? `${facility?.id}` : "");
setLocationId(
Expand Down
23 changes: 8 additions & 15 deletions src/Components/Assets/AssetImportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import useConfig from "../../Common/hooks/useConfig";
import DialogModal from "../Common/Dialog";
import useQuery from "../../Utils/request/useQuery";
import routes from "../../Redux/api";
import Loading from "../Common/Loading";

interface Props {
open: boolean;
Expand All @@ -39,18 +38,14 @@ const AssetImportModal = ({ open, onClose, facility }: Props) => {
setSelectedFile(undefined);
onClose && onClose();
};
const { data: facilityAssetLocations, loading } = useQuery(
routes.listFacilityAssetLocation,
{
pathParams: { facility_external_id: `${facility.id}` },
}
);

useEffect(() => {
if (facilityAssetLocations?.count) {
setLocations(facilityAssetLocations?.results);
}
}, [facilityAssetLocations]);
useQuery(routes.listFacilityAssetLocation, {
pathParams: { facility_external_id: `${facility.id}` },
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setLocations(data.results);
}
},
});

useEffect(() => {
const readFile = async () => {
Expand Down Expand Up @@ -182,8 +177,6 @@ const AssetImportModal = ({ open, onClose, facility }: Props) => {
setSelectedFile(dropedFile);
};

if (loading) return <Loading />;

return (
<DialogModal
title="Import Assets"
Expand Down
63 changes: 29 additions & 34 deletions src/Components/Assets/AssetManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,43 +70,38 @@ const AssetManage = (props: AssetManageProps) => {
pathParams: {
external_id: assetId,
},
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setAsset(data);
}
},
});

const { data: transactionsData, refetch } = useQuery(
routes.listAssetTransaction,
{
prefetch: false,
...transactionFilter,
query: {
limit,
offset,
},
}
);

const { data: servicesData, refetch: serviceRefetch } = useQuery(
routes.listAssetService,
{
pathParams: {
asset_external_id: assetId,
},
}
);

useEffect(() => {
if (assetData) setAsset(assetData);
}, [assetData]);

useEffect(() => {
if (transactionsData) {
setTransactions(transactionsData.results);
setTotalCount(transactionsData.count);
}
}, [transactionsData]);
const { refetch } = useQuery(routes.listAssetTransaction, {
prefetch: false,
...transactionFilter,
query: {
limit,
offset,
},
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setTransactions(data.results);
setTotalCount(data.count);
}
},
});

useEffect(() => {
if (servicesData) setServices(servicesData.results);
}, [servicesData]);
const { refetch: serviceRefetch } = useQuery(routes.listAssetService, {
pathParams: {
asset_external_id: assetId,
},
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setServices(data.results);
}
},
});

useEffect(() => {
if (assetData) {
Expand Down
33 changes: 16 additions & 17 deletions src/Components/Assets/AssetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,27 @@ const AssetsList = () => {
status: qParams.status || "",
};

const { data: assetList } = useQuery(routes.listAssets, {
useQuery(routes.listAssets, {
query: params,
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setAssets(data.results);
setTotalCount(data.count);
}
},
});
const { data: facilityResponse } = useQuery(routes.getAnyFacility, {

useQuery(routes.getAnyFacility, {
pathParams: { id: qParams.facility },
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setFacility(data);
setSelectedFacility(data);
setFacilityName(data.name);
}
},
});

useEffect(() => {
if (assetList) {
setAssets(assetList.results);
setTotalCount(assetList.count);
}
}, [assetList]);

useEffect(() => {
if (facilityResponse) {
setFacility(facilityResponse);
setSelectedFacility(facilityResponse);
setFacilityName(facilityResponse.name);
}
}, [facilityResponse]);

useEffect(() => {
setAssetType(qParams.asset_type);
}, [qParams.asset_type]);
Expand Down

0 comments on commit 8d3222a

Please sign in to comment.