Skip to content

Commit 8c52d46

Browse files
Merge pull request #4828 from OneCommunityGlobal/adithya_fix_consumables_usability
Adithya fix consumables usability
2 parents 756bacb + 560fe5e commit 8c52d46

5 files changed

Lines changed: 216 additions & 116 deletions

File tree

src/components/BMDashboard/ConsumableList/ConsumableListView.jsx

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,39 @@ function ConsumableListView() {
1010
const errors = useSelector(state => state.errors);
1111
const postConsumableUpdateResult = useSelector(state => state.bmConsumables.updateConsumables);
1212

13-
const consumablesWithId = consumables
14-
? consumables.map(item => ({
15-
...item,
16-
id:
17-
parseInt(item._id.substring(item._id.length - 6), 16) ||
18-
Math.floor(Math.random() * 1000000), // Convert last 6 chars of _id to number, or use random as fallback
19-
}))
13+
// --- DATA TRANSFORMATION ---
14+
const transformedConsumables = consumables
15+
? consumables
16+
.map(item => ({
17+
...item,
18+
// Flatten Data
19+
projectName: item.project?.name || 'N/A',
20+
name: item.itemType?.name || 'N/A',
21+
unit: item.itemType?.unit || 'N/A',
22+
// Dropdown Fixes
23+
inventoryItemType: item.itemType?.name || 'N/A',
24+
type: item.itemType?.name || 'N/A',
25+
// Preserve Structure
26+
itemType: item.itemType || { name: 'N/A', unit: '' },
27+
id: item._id,
28+
}))
29+
// Filter out bad data (empty names)
30+
.filter(item => item.name !== 'N/A')
2031
: [];
2132

2233
useEffect(() => {
2334
dispatch(fetchAllConsumables());
24-
}, []);
35+
}, [dispatch]);
2536

2637
useEffect(() => {
2738
if (!postConsumableUpdateResult || postConsumableUpdateResult?.result == null)
2839
dispatch(fetchAllConsumables());
29-
}, [postConsumableUpdateResult?.result]);
40+
}, [postConsumableUpdateResult?.result, dispatch]);
3041

31-
const itemType = 'Consumables';
42+
const itemTypeLabel = 'Consumables';
3243

3344
const dynamicColumns = [
34-
{ label: 'Unit', key: 'itemType.unit' },
45+
{ label: 'Unit', key: 'unit' },
3546
{ label: 'Bought', key: 'stockBought' },
3647
{ label: 'Used', key: 'stockUsed' },
3748
{ label: 'Available', key: 'stockAvailable' },
@@ -40,8 +51,8 @@ function ConsumableListView() {
4051

4152
return (
4253
<ItemListView
43-
itemType={itemType}
44-
items={consumablesWithId}
54+
itemType={itemTypeLabel}
55+
items={transformedConsumables}
4556
errors={errors}
4657
UpdateItemModal={UpdateConsumableModal}
4758
dynamicColumns={dynamicColumns}

src/components/BMDashboard/ItemList/ItemListView.jsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,25 @@ export function ItemListView({ itemType, items, errors, UpdateItemModal, dynamic
6969
<span>
7070
{items && (
7171
<div className={`${styles.selectInput}`}>
72-
<label htmlFor="itemListTime">Time:</label>
73-
<DatePicker
74-
selected={selectedTime}
75-
onChange={date => setSelectedTime(date)}
76-
showTimeSelect
77-
timeFormat="HH:mm"
78-
timeIntervals={15}
79-
dateFormat="yyyy-MM-dd HH:mm:ss"
80-
placeholderText="Select date and time"
81-
inputId="itemListTime" // This is the key line
82-
className={darkMode ? styles.darkDatePickerInput : styles.lightDatePickerInput}
83-
calendarClassName={darkMode ? styles.darkDatePicker : styles.lightDatePicker}
84-
popperClassName={
85-
darkMode ? styles.darkDatePickerPopper : styles.lightDatePickerPopper
86-
}
87-
/>
72+
{/* Wrap the Time label and Datepicker in a flex group */}
73+
<div className={`${styles.filterGroup}`}>
74+
<label htmlFor="itemListTime">Time:</label>
75+
<DatePicker
76+
selected={selectedTime}
77+
onChange={date => setSelectedTime(date)}
78+
showTimeSelect
79+
timeFormat="HH:mm"
80+
timeIntervals={15}
81+
dateFormat="yyyy-MM-dd HH:mm:ss"
82+
placeholderText="Select date and time"
83+
inputId="itemListTime"
84+
className={darkMode ? styles.darkDatePickerInput : styles.lightDatePickerInput}
85+
calendarClassName={darkMode ? styles.darkDatePicker : styles.lightDatePicker}
86+
popperClassName={
87+
darkMode ? styles.darkDatePickerPopper : styles.lightDatePickerPopper
88+
}
89+
/>
90+
</div>
8891
<SelectForm
8992
items={items}
9093
setSelectedProject={setSelectedProject}
@@ -95,6 +98,7 @@ export function ItemListView({ itemType, items, errors, UpdateItemModal, dynamic
9598
selectedProject={selectedProject}
9699
selectedItem={selectedItem}
97100
setSelectedItem={setSelectedItem}
101+
label={itemType}
98102
/>
99103
</div>
100104
)}

src/components/BMDashboard/ItemList/ItemListView.module.css

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,30 @@ table td {
4949
}
5050

5151
.selectInput {
52-
display: grid;
53-
grid-template-columns: auto 1fr auto 1fr auto 1fr;
52+
display: flex;
53+
flex-wrap: wrap;
54+
justify-content: center;
5455
align-items: center;
55-
gap: 15px;
56+
gap: 30px;
5657
width: 100%;
5758
max-width: 1200px;
58-
margin: 0 auto 10px auto;
59+
margin: 0 auto 20px auto;
5960
overflow: visible;
6061
}
6162

63+
.filterGroup,
64+
.selectInput > div,
65+
.selectInput > form {
66+
display: flex;
67+
align-items: center;
68+
gap: 10px;
69+
}
70+
6271
.selectInput label {
6372
font-weight: bold;
6473
text-align: center;
6574
white-space: nowrap;
66-
margin-bottom: 8px;
75+
margin-bottom: 0;
6776
}
6877

6978
.selectInput input,
@@ -75,12 +84,12 @@ table td {
7584
padding: 5px;
7685
border: 1px solid #ccc;
7786
border-radius: 4px;
78-
margin-bottom: 8px;
87+
margin-bottom: 0;
7988
}
8089

8190
.selectInput input[type='text'] {
8291
padding: 5px;
83-
margin-bottom: 8px;
92+
margin-bottom: 0;
8493
}
8594
.btnPrimary {
8695
background-color: #468ef9;

0 commit comments

Comments
 (0)