Skip to content

Commit

Permalink
Merge pull request #2 from bodhisha/aashna
Browse files Browse the repository at this point in the history
added UI for inventory log
  • Loading branch information
bodhisha authored Jun 16, 2020
2 parents d212cc9 + 3e93089 commit 095c3c0
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 26 deletions.
15 changes: 7 additions & 8 deletions src/Components/Facility/AddInventoryForm.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 }
Expand Down Expand Up @@ -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();

};
Expand Down
26 changes: 12 additions & 14 deletions src/Components/Facility/InventoryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -38,10 +36,10 @@ export default function InventoryList(props: any) {
},
[dispatchAction, offset, facilityId]
);

useAbortableEffect(
(status: statusType) => {
fetchData(status);
fetchData(status);
},
[fetchData]
);
Expand All @@ -61,12 +59,12 @@ export default function InventoryList(props: any) {
// }
// setIsLoading(false);
// }

let inventoryList: any = [];
if (inventory && inventory.length) {
inventoryList = inventory.map((inventoryItem: any) => (
<tr key={inventoryItem.id} className={`${inventoryItem.is_low? "bg-red-100": "bg-white"}`}>
<td className="px-5 py-5 border-b border-gray-200 text-sm">
<tr key={inventoryItem.id} className={`${inventoryItem.is_low ? "bg-red-100 hover:bg-gray-200" : "bg-white hover:bg-gray-200"}`} onClick={() => navigate(`/facility/${facilityId}/inventory/${inventoryItem.item_object?.id}`)}>
<td className="px-5 py-5 border-b border-gray-200 text-sm ">
<div className="flex items-center">
<div className="ml-3">
<p className="text-gray-900 whitespace-no-wrap">
Expand All @@ -79,7 +77,7 @@ export default function InventoryList(props: any) {
</div>
</div>
</td>
<td className="px-5 py-5 border-b border-gray-200 text-sm">
<td className="px-5 py-5 border-b border-gray-200 text-sm ">
<p className="text-gray-900 whitespace-no-wrap lowercase">
{inventoryItem.quantity} {inventoryItem.item_object?.default_unit?.name}
</p>
Expand Down Expand Up @@ -128,17 +126,17 @@ export default function InventoryList(props: any) {
{totalCount > limit && (
<div className="mt-4 flex w-full justify-center">
<Pagination
cPage={currentPage}
defaultPerPage={limit}
data={{ totalCount }}
onChange={handlePagination}
cPage={currentPage}
defaultPerPage={limit}
data={{ totalCount }}
onChange={handlePagination}
/>
</div>
)}
</>
);
}
}

return (
<div>
<PageTitle title="Inventory" hideBack={false} />
Expand Down
164 changes: 164 additions & 0 deletions src/Components/Facility/InventoryLog.tsx
Original file line number Diff line number Diff line change
@@ -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) => (
<tr key={inventoryItem.id} className="bg-white" onClick={() => navigate(`/facility/${facilityId}/inventory/${inventoryItem.id}`)}>
<td className="px-5 py-5 border-b border-gray-200 text-sm hover:bg-gray-100">
<div className="flex items-center">
<div className="ml-3">
<p className="text-gray-900 whitespace-no-wrap">
{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()} */}
</p>
</div>
</div>
</td>
<td className="px-5 py-5 border-b border-gray-200 text-sm hover:bg-gray-100">
<p className="text-gray-900 whitespace-no-wrap lowercase">
{inventoryItem.quantity} {inventoryItem.item_object?.default_unit?.name}
</p>
</td>
<td className="px-5 py-5 border-b border-gray-200 text-sm hover:bg-gray-100">
<p className="text-gray-900 whitespace-no-wrap lowercase">
{inventoryItem.is_incoming ? <span className="ml-2 text-green-600">Incoming</span> : <span className="ml-2 text-red-600">Outgoing</span>}
</p>
</td>
</tr>

));
} else if (inventory && inventory.length === 0) {
inventoryList = (
<tr className="bg-white">
<td colSpan={3} className="px-5 py-5 border-b border-gray-200 text-center">
<p className="text-gray-500 whitespace-no-wrap">
No log for this inventory available
</p>
</td>
</tr>
);
}

if (isLoading || !inventory) {
inventoryItem = <Loading />;
} else if (inventory) {
inventoryItem = (
<>
<div className="-mx-4 sm:-mx-8 px-4 sm:px-8 py-4 overflow-x-auto">
<div className="inline-block min-w-full">
<table className="min-w-full leading-normal shadow rounded-lg overflow-hidden">
<thead>
<tr>
<th
className="px-5 py-3 border-b-2 border-gray-200 bg-green-400 text-left text-xs font-semibold text-white uppercase tracking-wider">
Created On
</th>
<th
className="px-5 py-3 border-b-2 border-gray-200 bg-green-400 text-left text-xs font-semibold text-white uppercase tracking-wider">
Quantity
</th>
<th
className="px-5 py-3 border-b-2 border-gray-200 bg-green-400 text-left text-xs font-semibold text-white uppercase tracking-wider">
Status
</th>

</tr>
</thead>
<tbody>
{inventoryList}
</tbody>
</table>
</div>
</div>
{totalCount > limit && (
<div className="mt-4 flex w-full justify-center">
<Pagination
cPage={currentPage}
defaultPerPage={limit}
data={{ totalCount }}
onChange={handlePagination}
/>
</div>
)}
</>
);
}

return (
<div>
<PageTitle title="Inventory Log" hideBack={false} />
<div className="container mx-auto px-4 sm:px-8">
<div className="py-8">

{inventoryItem}
</div>
</div>
</div>
)
}
3 changes: 3 additions & 0 deletions src/Redux/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 5 additions & 3 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ export default {
path: '/api/v1/facility',
method: 'DELETE'
},

getInventorySummary: {
path: '/api/v1/facility',
method: 'GET',
},


getConsultationList: {
path: '/api/v1/consultation/'
Expand Down Expand Up @@ -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/",
},

}
3 changes: 2 additions & 1 deletion src/Router/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -121,7 +122,7 @@ const routes = {
),
"/facility/:facilityId/inventory": ({ facilityId }: any) => (<InventoryList facilityId={facilityId} />),
"/facility/:facilityId/inventory/add": ({ facilityId }: any) => (<AddInventoryForm facilityId={facilityId} />),

"/facility/:facilityId/inventory/:inventoryId": ({ facilityId, inventoryId }: any) => (<InventoryLog facilityId={facilityId} inventoryId={inventoryId} />),
};


Expand Down

0 comments on commit 095c3c0

Please sign in to comment.