Skip to content

Commit

Permalink
Merge pull request #1956 from OneCommunityGlobal/Chengyan-Phase2-Reus…
Browse files Browse the repository at this point in the history
…ables-List-UI

Chengyan phase2 reusables list UI
  • Loading branch information
one-community authored Mar 10, 2024
2 parents 9f264b8 + b3a0661 commit 5a31347
Show file tree
Hide file tree
Showing 32 changed files with 586 additions and 821 deletions.
32 changes: 32 additions & 0 deletions src/actions/bmdashboard/reusableActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import axios from "axios";
import {
SET_REUSABLES
} from "constants/bmdashboard/reusableConstants"
import { GET_ERRORS } from "constants/errors";
import { ENDPOINTS } from "utils/URL";

export const setReusables = payload => {
return {
type: SET_REUSABLES,
payload
}
}

export const setErrors = payload => {
return {
type: GET_ERRORS,
payload
}
}

export const fetchAllReusables = () => {
return async dispatch => {
axios.get(ENDPOINTS.BM_REUSABLES)
.then(res => {
dispatch(setReusables(res.data))
})
.catch(err => {
dispatch(setErrors(err))
})
}
}
43 changes: 43 additions & 0 deletions src/components/BMDashboard/ConsumableList/ConsumableListView.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { fetchAllConsumables } from 'actions/bmdashboard/consumableActions';
import ItemListView from '../ItemList/ItemListView';
import UpdateConsumableModal from '../UpdateConsumables/UpdateConsumableModal';

function ConsumableListView() {
const dispatch = useDispatch();
const consumables = useSelector(state => state.bmConsumables.consumableslist);
const errors = useSelector(state => state.errors);
const postConsumableUpdateResult = useSelector(state => state.bmConsumables.updateConsumables);

useEffect(() => {
dispatch(fetchAllConsumables());
}, []);

useEffect(() => {
if (!postConsumableUpdateResult || postConsumableUpdateResult?.result == null)
dispatch(fetchAllConsumables());
}, [postConsumableUpdateResult?.result]);

const itemType = 'Consumables';

const dynamicColumns = [
{ label: 'Unit', key: 'itemType.unit' },
{ label: 'Bought', key: 'stockBought' },
{ label: 'Used', key: 'stockUsed' },
{ label: 'Available', key: 'stockAvailable' },
{ label: 'Waste', key: 'stockWasted' },
];

return (
<ItemListView
itemType={itemType}
items={consumables}
errors={errors}
UpdateItemModal={UpdateConsumableModal}
dynamicColumns={dynamicColumns}
/>
);
}

export default ConsumableListView;
3 changes: 3 additions & 0 deletions src/components/BMDashboard/ConsumableList/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ConsumableListView from './ConsumableListView';

export default ConsumableListView;

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5a31347

Please sign in to comment.