diff --git a/src/Components/Facility/AddInventoryForm.tsx b/src/Components/Facility/AddInventoryForm.tsx index d5c8cacf39c..3ef67b2faa8 100644 --- a/src/Components/Facility/AddInventoryForm.tsx +++ b/src/Components/Facility/AddInventoryForm.tsx @@ -1,6 +1,5 @@ import { Button, Card, CardContent, InputLabel } from "@material-ui/core"; import CheckCircleOutlineIcon from '@material-ui/icons/CheckCircleOutline'; -import moment from 'moment'; import React, { useCallback, useReducer, useState, useEffect } from "react"; import { useDispatch } from "react-redux"; import { statusType, useAbortableEffect } from "../../Common/utils"; @@ -11,12 +10,11 @@ import { Loading } from "../Common/Loading"; import PageTitle from "../Common/PageTitle"; import { InventoryItemsModel } from "./models"; - const initForm = { id: "", quantity: "", unit: "", - isIncoming: true, + isIncoming: false, }; const initialState = { form: { ...initForm } @@ -95,18 +93,19 @@ export const AddInventoryForm = (props: any) => { item: Number(state.form.id), unit: Number(state.form.unit), }; - + const res = await dispatchAction(postInventory(data, { facilityId })); setIsLoading(false); if (res && res.data) { Notification.Success({ msg: "Inventory created successfully" }); - } else { - Notification.Success({ - msg: "something went wrong!" - }); } + // else { + // Notification.Error({ + // msg: "something went wrong!" + // }); + // } goBack(); }; diff --git a/src/Components/Facility/InventoryList.tsx b/src/Components/Facility/InventoryList.tsx index 830aca51f19..e4b8dd82afd 100644 --- a/src/Components/Facility/InventoryList.tsx +++ b/src/Components/Facility/InventoryList.tsx @@ -20,8 +20,6 @@ export default function InventoryList(props: any) { const [offset, setOffset] = useState(0); const [currentPage, setCurrentPage] = useState(1); const [totalCount, setTotalCount] = useState(0); - - const limit = 14; const fetchData = useCallback( @@ -38,10 +36,10 @@ export default function InventoryList(props: any) { }, [dispatchAction, offset, facilityId] ); - + useAbortableEffect( (status: statusType) => { - fetchData(status); + fetchData(status); }, [fetchData] ); @@ -61,12 +59,12 @@ export default function InventoryList(props: any) { // } // setIsLoading(false); // } - + let inventoryList: any = []; if (inventory && inventory.length) { inventoryList = inventory.map((inventoryItem: any) => ( - - + navigate(`/facility/${facilityId}/inventory/${inventoryItem.item_object?.id}`)}> +

@@ -79,7 +77,7 @@ export default function InventoryList(props: any) {

- +

{inventoryItem.quantity} {inventoryItem.item_object?.default_unit?.name}

@@ -128,17 +126,17 @@ export default function InventoryList(props: any) { {totalCount > limit && (
)} ); - } - + } + return (
diff --git a/src/Components/Facility/InventoryLog.tsx b/src/Components/Facility/InventoryLog.tsx new file mode 100644 index 00000000000..498593bc8d8 --- /dev/null +++ b/src/Components/Facility/InventoryLog.tsx @@ -0,0 +1,164 @@ +import React, { useState, useCallback } from 'react' +import PageTitle from '../Common/PageTitle' +import { Button } from "@material-ui/core"; +import { Loading } from "../Common/Loading"; +import { navigate } from "hookrouter"; +import { useDispatch } from "react-redux"; +import { getInventoryLog } from '../../Redux/actions'; +import { statusType, useAbortableEffect } from "../../Common/utils"; +import Pagination from "../Common/Pagination"; +import { FacilityCreate } from './FacilityCreate'; +import moment from "moment"; + +export default function InventoryLog(props: any) { + + const { facilityId, inventoryId }: any = props; + console.log(facilityId); + console.log(inventoryId); + + + const dispatchAction: any = useDispatch(); + const [isLoading, setIsLoading] = useState(false); + const initialInventory: any[] = []; + let inventoryItem: any = null; + const [inventory, setInventory] = useState(initialInventory); + const [offset, setOffset] = useState(0); + const [currentPage, setCurrentPage] = useState(1); + const [totalCount, setTotalCount] = useState(0); + const limit = 14; + const item = inventoryId; + + const fetchData = useCallback( + async (status: statusType) => { + setIsLoading(true); + const res = await dispatchAction(getInventoryLog(facilityId, { item, limit, offset })); + if (!status.aborted) { + if (res && res.data) { + setInventory(res.data.results); + setTotalCount(res.data.count); + } + setIsLoading(false); + } + }, + [dispatchAction, offset, facilityId] + ); + + useAbortableEffect( + (status: statusType) => { + fetchData(status); + }, + [fetchData] + ); + + const handlePagination = (page: number, limit: number) => { + const offset = (page - 1) * limit; + setCurrentPage(page); + setOffset(offset); + }; + + // const onSearchSuspects = async (searchValue: string) => { + // setIsLoading(true); + // const res = await dispatchAction(getFacilities({ limit, offset, search_text: searchValue })); + // if (res && res.data) { + // setData(res.data.results); + // setTotalCount(res.data.count); + // } + // setIsLoading(false); + // } + + let inventoryList: any = []; + if (inventory && inventory.length) { + inventoryList = inventory.map((inventoryItem: any) => ( + navigate(`/facility/${facilityId}/inventory/${inventoryItem.id}`)}> + +
+
+

+ {moment(inventoryItem.created_date).format("DD-MM-YYYY hh:mm:ss")} + {/* {new Date(inventoryItem.created_date).getDate()}-{new Date(inventoryItem.created_date).getMonth()}-{new Date(inventoryItem.created_date).getFullYear()} */} +

+
+
+ + +

+ {inventoryItem.quantity} {inventoryItem.item_object?.default_unit?.name} +

+ + +

+ {inventoryItem.is_incoming ? Incoming : Outgoing} +

+ + + + )); + } else if (inventory && inventory.length === 0) { + inventoryList = ( + + +

+ No log for this inventory available +

+ + + ); + } + + if (isLoading || !inventory) { + inventoryItem = ; + } else if (inventory) { + inventoryItem = ( + <> +
+
+ + + + + + + + + + + {inventoryList} + +
+ Created On + + Quantity + + Status +
+
+
+ {totalCount > limit && ( +
+ +
+ )} + + ); + } + + return ( +
+ +
+
+ + {inventoryItem} +
+
+
+ ) +} \ No newline at end of file diff --git a/src/Redux/actions.tsx b/src/Redux/actions.tsx index f81b414f286..62c18e1d0b2 100644 --- a/src/Redux/actions.tsx +++ b/src/Redux/actions.tsx @@ -182,3 +182,6 @@ export const getItems = (params: object) => { export const postInventory = (params: object, pathParams: object) => { return fireRequest("createInventory", [], params, pathParams) }; +export const getInventoryLog = (params: object, pathParams: object) => { + return fireRequest("getInventoryLog", [params, "inventory"], pathParams) +} \ No newline at end of file diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index c60f5cbb197..89088b0a832 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -92,12 +92,12 @@ export default { path: '/api/v1/facility', method: 'DELETE' }, - + getInventorySummary: { path: '/api/v1/facility', method: 'GET', }, - + getConsultationList: { path: '/api/v1/consultation/' @@ -276,10 +276,12 @@ export default { getItems: { path: '/api/v1/items/' }, - createInventory: { path: "/api/v1/facility/{facilityId}/inventory/", method: 'POST' }, + getInventoryLog: { + path: "/api/v1/facility/", + }, } diff --git a/src/Router/AppRouter.tsx b/src/Router/AppRouter.tsx index 6d42c348440..0308b5be5e7 100644 --- a/src/Router/AppRouter.tsx +++ b/src/Router/AppRouter.tsx @@ -31,6 +31,7 @@ import ManageUsers from "../Components/Users/ManageUsers"; import { UserAdd } from "../Components/Users/UserAdd"; import AmbulanceOnboarding from "../Components/Ambulance/AmbulanceOnboarding"; import InventoryList from "../Components/Facility/InventoryList"; +import InventoryLog from "../Components/Facility/InventoryLog"; import { AddInventoryForm } from "../Components/Facility/AddInventoryForm" const img = @@ -121,7 +122,7 @@ const routes = { ), "/facility/:facilityId/inventory": ({ facilityId }: any) => (), "/facility/:facilityId/inventory/add": ({ facilityId }: any) => (), - + "/facility/:facilityId/inventory/:inventoryId": ({ facilityId, inventoryId }: any) => (), };