Skip to content

Commit 66d33ca

Browse files
Merge pull request #3254 from OneCommunityGlobal/nikhil-update-equipment-tool
Nikhil update equipment tool
2 parents fcfc7f3 + 1e543eb commit 66d33ca

6 files changed

Lines changed: 321 additions & 1 deletion

File tree

src/components/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ function UpdateDocumentTitle() {
4848
authUser?.firstName && authUser?.lastName
4949
? `${authUser.firstName} ${authUser.lastName}`
5050
: 'User';
51-
5251
// Define the routes array with pattern and title
5352
const Routes = [
5453
{ pattern: /^\/ProfileInitialSetup\/[^/]+$/, title: 'Profile Initial Setup' },
@@ -102,6 +101,7 @@ function UpdateDocumentTitle() {
102101
{ pattern: /^\/bmdashboard\/tools\/[^/]+\/update$/, title: 'Update Tool' },
103102
{ pattern: /^\/bmdashboard\/tools$/, title: 'Tools List' },
104103
{ pattern: /^\/bmdashboard\/tools\/add$/, title: 'Add Tool' },
104+
{ pattern: /^\/bmdashboard\/tools\/equipmentupdate$/, title: 'Update Equipment or Tool' },
105105
{ pattern: /^\/bmdashboard\/tools\/log$/, title: 'Log Tools' },
106106
{ pattern: /^\/bmdashboard\/tools\/[^/]+$/, title: 'Tool Detail' },
107107
{ pattern: /^\/bmdashboard\/lessonform\/[^/]*$/, title: 'Lesson Form' },
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.equipment-update-container {
2+
width: 100%;
3+
max-width: 800px;
4+
margin: 1rem auto;
5+
padding: 1rem 2rem;
6+
border: 1px solid #ccc;
7+
border-radius: 20px;
8+
}
9+
10+
.equipment-update-header h2 {
11+
font-size: clamp(1.5rem, 2.5vw, 2.5rem);
12+
margin-left: 1rem;
13+
}
14+
15+
@media screen and (max-width: 800px) {
16+
.equipment-update-container {
17+
width: 95%;
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import EquipmentUpdateForm from './EquipmentUpdateForm';
2+
import './EquipmentUpdate.css';
3+
4+
export default function EquipmentUpdate() {
5+
return (
6+
<main className="equipment-update-container">
7+
<header className="equipment-update-header">
8+
<h2>Which Tool or Equipment to Update</h2>
9+
</header>
10+
<EquipmentUpdateForm />
11+
</main>
12+
);
13+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
.add-tool-form {
2+
width: 100%;
3+
max-width: 600px;
4+
margin: 0 auto;
5+
padding: 1rem;
6+
}
7+
8+
.add-tool-form label {
9+
font-size: 0.9em;
10+
font-weight: bold;
11+
display: block;
12+
margin-bottom: 0.5rem;
13+
}
14+
15+
.add-tool-flex-group {
16+
display: flex;
17+
gap: 1.5rem;
18+
flex-wrap: wrap;
19+
}
20+
21+
.add-tool-buttons {
22+
display: flex;
23+
justify-content: space-between;
24+
gap: 1rem;
25+
margin: 1rem auto 2rem;
26+
}
27+
28+
.add-tool-buttons button {
29+
flex: 1;
30+
min-width: 120px;
31+
}
32+
33+
.add-tool-total-price {
34+
display: flex;
35+
border-radius: 10px;
36+
line-height: 3rem;
37+
font-weight: bolder;
38+
background-color: #f5e6e6;
39+
padding: 1rem;
40+
justify-content: space-between;
41+
align-items: center;
42+
}
43+
44+
.file-preview-container {
45+
display: flex;
46+
flex-wrap: wrap;
47+
gap: 0.5rem;
48+
width: 100%;
49+
margin-top: 1rem;
50+
}
51+
52+
.toolFormError {
53+
font-weight: 500;
54+
font-size: 12px !important;
55+
color: red;
56+
margin-top: 0.25rem;
57+
}
58+
59+
.field-required {
60+
color: red;
61+
}
62+
63+
@media screen and (max-width: 600px) {
64+
.add-tool-flex-group {
65+
flex-direction: column;
66+
gap: 1rem;
67+
}
68+
69+
.file-preview-container {
70+
flex-direction: column;
71+
}
72+
73+
.add-tool-buttons {
74+
flex-direction: column;
75+
align-items: stretch;
76+
}
77+
78+
.add-tool-buttons button {
79+
width: 100%;
80+
}
81+
}
82+
83+
@media screen and (max-width: 400px) {
84+
.add-tool-form {
85+
padding: 0.5rem;
86+
}
87+
88+
.add-tool-total-price {
89+
flex-direction: column;
90+
text-align: center;
91+
}
92+
93+
.add-tool-total-price div {
94+
width: 100%;
95+
}
96+
97+
.add-tool-buttons {
98+
gap: 0.5rem;
99+
}
100+
}
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
import { useState, useEffect, useMemo } from 'react';
2+
import { Form, FormGroup, Label, Input, Button } from 'reactstrap';
3+
import { toast } from 'react-toastify';
4+
import { useDispatch, useSelector } from 'react-redux';
5+
6+
import { fetchAllEquipments } from '../../../actions/bmdashboard/equipmentActions';
7+
import { fetchTools } from '../../../actions/bmdashboard/toolActions';
8+
import { fetchBMProjects } from '../../../actions/bmdashboard/projectActions';
9+
10+
const initialFormState = {
11+
project: '',
12+
toolOrEquipment: '',
13+
name: '',
14+
number: '',
15+
};
16+
17+
export default function EquipmentUpdateForm() {
18+
const [formData, setFormData] = useState(initialFormState);
19+
const [isFormValid, setIsFormValid] = useState(false);
20+
const dispatch = useDispatch();
21+
22+
// Fetch dropdown data
23+
const projects = useSelector(state => state.bmProjects || []);
24+
const tools = useSelector(state => state.bmTools.toolslist || []);
25+
const equipments = useSelector(state => state.bmEquipments.equipmentslist || []);
26+
27+
useEffect(() => {
28+
dispatch(fetchBMProjects());
29+
dispatch(fetchTools());
30+
dispatch(fetchAllEquipments());
31+
}, [dispatch]);
32+
33+
// Extract list of valid tools and equipment (only where name is present)
34+
const toolList = useMemo(
35+
() =>
36+
tools
37+
.filter(tool => tool.itemType && tool.itemType.name)
38+
.map(tool => ({ id: tool.itemType._id, name: tool.itemType.name })),
39+
[tools],
40+
);
41+
42+
const equipmentList = useMemo(
43+
() =>
44+
equipments
45+
.filter(equip => equip.itemType && equip.itemType.name)
46+
.map(equip => ({ id: equip.itemType._id, name: equip.itemType.name })),
47+
[equipments],
48+
);
49+
50+
// Update form validity
51+
useEffect(() => {
52+
const { project, toolOrEquipment, name, number } = formData;
53+
setIsFormValid(!!(project && toolOrEquipment && name && number));
54+
}, [formData]);
55+
56+
// Handle input change
57+
// Handle input change
58+
const handleChange = e => {
59+
const { name, value } = e.target;
60+
61+
// Allow only numbers in the "number" field
62+
if (name === 'number' && value !== '' && !/^\d+$/.test(value)) {
63+
return; // Ignore invalid input (non-numeric values)
64+
}
65+
66+
setFormData(prev => ({
67+
...prev,
68+
[name]: value,
69+
...(name === 'toolOrEquipment' ? { name: '', number: '' } : {}), // Reset name and number on change
70+
}));
71+
};
72+
73+
// Reset form
74+
const handleCancel = () => {
75+
setFormData(initialFormState);
76+
};
77+
78+
// Submit form
79+
const handleSubmit = e => {
80+
e.preventDefault();
81+
82+
if (!isFormValid) {
83+
toast.error('Please complete all fields before updating.');
84+
return;
85+
}
86+
setFormData(initialFormState);
87+
toast.success('Tool/Equipment updated successfully!');
88+
};
89+
90+
return (
91+
<div className="add-tool-form">
92+
<Form onSubmit={handleSubmit}>
93+
<FormGroup>
94+
<Label for="project">
95+
Project <span className="field-required">*</span>
96+
</Label>
97+
<Input
98+
type="select"
99+
name="project"
100+
id="project"
101+
value={formData.project}
102+
onChange={handleChange}
103+
>
104+
<option value="">Select Project</option>
105+
{projects.map(proj => (
106+
<option key={proj.id} value={proj.id}>
107+
{proj.name}
108+
</option>
109+
))}
110+
</Input>
111+
{!formData.project && <div className="toolFormError">Project is required</div>}
112+
</FormGroup>
113+
114+
<FormGroup>
115+
<Label for="toolOrEquipment">
116+
Tool or Equipment <span className="field-required">*</span>
117+
</Label>
118+
<Input
119+
type="select"
120+
name="toolOrEquipment"
121+
id="toolOrEquipment"
122+
value={formData.toolOrEquipment}
123+
onChange={handleChange}
124+
>
125+
<option value="">Select Tool/Equipment</option>
126+
<option value="Tool">Tool</option>
127+
<option value="Equipment">Equipment</option>
128+
</Input>
129+
{!formData.toolOrEquipment && <div className="toolFormError">This field is required</div>}
130+
</FormGroup>
131+
132+
<FormGroup>
133+
<Label for="name">
134+
Name <span className="field-required">*</span>
135+
</Label>
136+
<Input
137+
type="select"
138+
name="name"
139+
id="name"
140+
value={formData.name}
141+
onChange={handleChange}
142+
disabled={!formData.toolOrEquipment}
143+
>
144+
<option value="">Select Name</option>
145+
{formData.toolOrEquipment === 'Tool' &&
146+
toolList.map(item => (
147+
<option key={item.id} value={item.name}>
148+
{item.name}
149+
</option>
150+
))}
151+
{formData.toolOrEquipment === 'Equipment' &&
152+
equipmentList.map(item => (
153+
<option key={item.id} value={item.name}>
154+
{item.name}
155+
</option>
156+
))}
157+
</Input>
158+
{!formData.name && <div className="toolFormError">Please select a name</div>}
159+
</FormGroup>
160+
161+
<FormGroup>
162+
<Label for="number">
163+
Number <span className="field-required">*</span>
164+
</Label>
165+
<Input
166+
type="text"
167+
name="number"
168+
id="number"
169+
value={formData.number}
170+
onChange={handleChange}
171+
placeholder="Enter number"
172+
/>
173+
{!formData.number && <div className="toolFormError">Number is required</div>}
174+
</FormGroup>
175+
<div className="add-tool-buttons">
176+
<Button color="primary" type="submit" disabled={!isFormValid}>
177+
Update
178+
</Button>
179+
<Button color="secondary" type="button" onClick={handleCancel}>
180+
Cancel
181+
</Button>
182+
</div>
183+
</Form>
184+
</div>
185+
);
186+
}

src/routes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ import EPDashboard from './components/EductionPortal';
9292

9393
// eslint-disable-next-line import/order, import/no-unresolved
9494
import LogTools from './components/BMDashboard/LogTools/LogTools';
95+
import EquipmentUpdate from './components/BMDashboard/Tools/EquipmentUpdate';
9596

9697

9798
const ReusableListView = lazy(() => import('./components/BMDashboard/ReusableList'));
@@ -394,6 +395,7 @@ export default (
394395
<BMProtectedRoute path="/bmdashboard/AddTeamMember" component={AddTeamMember} />
395396
<BMProtectedRoute path="/bmdashboard/tools/add" exact component={AddTool} />
396397
<BMProtectedRoute path="/bmdashboard/tools/log" exact component={LogTools} />
398+
<BMProtectedRoute path="/bmdashboard/tools/equipmentupdate" exact component={EquipmentUpdate} />
397399
<BMProtectedRoute path="/bmdashboard/tools/:toolId" component={ToolDetailPage} />
398400
<BMProtectedRoute path="/bmdashboard/lessonform/:projectId" component={LessonForm} />
399401
<BMProtectedRoute path="/bmdashboard/lessonform/" component={LessonForm} />

0 commit comments

Comments
 (0)