Skip to content

Commit 6e71141

Browse files
Merge pull request #5078 from OneCommunityGlobal/auto-populate-optimize-tool-selection-workflow
Uha fix purchase form
2 parents eb26257 + aae1bf9 commit 6e71141

6 files changed

Lines changed: 440 additions & 20 deletions

File tree

src/components/BMDashboard/Equipment/Add/AddTypeForm.jsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { toast } from 'react-toastify';
66
import { useHistory } from 'react-router-dom';
77

88
import { addEquipmentType, fetchAllEquipments } from '~/actions/bmdashboard/equipmentActions';
9+
import BMCharacterLimitHint from '../../shared/BMCharacterLimitHint';
910

1011
const FuelTypes = {
1112
dies: 'Diesel',
@@ -15,13 +16,15 @@ const FuelTypes = {
1516
etha: 'Ethanol',
1617
};
1718

19+
const DESC_CHAR_LIMIT = 150;
20+
1821
// const [inputText, setInputText] = useState('');
1922

2023
const schema = Joi.object({
2124
name: Joi.string().required(),
2225
desc: Joi.string()
2326
.required()
24-
.max(150),
27+
.max(DESC_CHAR_LIMIT),
2528
});
2629

2730
export default function AddTypeForm() {
@@ -46,7 +49,7 @@ export default function AddTypeForm() {
4649
setName(event.target.value);
4750
}
4851
if (event.target.name === 'desc') {
49-
setDesc(event.target.value);
52+
setDesc(event.target.value.slice(0, DESC_CHAR_LIMIT));
5053
}
5154
if (event.target.name === 'fuel') {
5255
setFuel(event.target.value);
@@ -104,13 +107,16 @@ export default function AddTypeForm() {
104107
name="desc"
105108
type="textarea"
106109
rows={2}
110+
maxLength={DESC_CHAR_LIMIT}
107111
value={desc}
108112
invalid={errInput === 'desc'}
109113
onChange={handleChange}
110114
/>
111-
<div className="form-footer" style={{ color: desc.length > 150 ? '#dc3545' : 'black' }}>
112-
Character {desc.length}/150
113-
</div>
115+
<BMCharacterLimitHint
116+
limit={DESC_CHAR_LIMIT}
117+
length={desc.length}
118+
summary={`Character ${desc.length}/${DESC_CHAR_LIMIT}`}
119+
/>
114120
{/* {!errInput && <FormText>Max 150 characters</FormText>} */}
115121
<FormFeedback>
116122
{errType === 'string.max'

src/components/BMDashboard/EquipmentPurchaseRequest/PurchaseForm.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import Joi from 'joi';
77

88
import { boxStyle } from '~/styles';
99
import { purchaseEquipment } from '~/actions/bmdashboard/equipmentActions';
10+
import BMCharacterLimitHint from '../shared/BMCharacterLimitHint';
1011

1112
import stylesPurchaseForm from './PurchaseForm.module.css';
1213

14+
const DESC_CHAR_LIMIT = 150;
15+
1316
export default function PurchaseForm() {
1417
const bmProjects = useSelector(state => state.bmProjects);
1518
const equipments = useSelector(state => state.bmInvTypes.list);
@@ -38,7 +41,7 @@ export default function PurchaseForm() {
3841
estTime: Joi.string().required(),
3942
desc: Joi.string()
4043
.required()
41-
.max(150),
44+
.max(DESC_CHAR_LIMIT),
4245
makeModel: Joi.string().allow(''),
4346
});
4447

@@ -204,13 +207,14 @@ export default function PurchaseForm() {
204207
<Input
205208
id="input-usage-description"
206209
type="textarea"
210+
maxLength={DESC_CHAR_LIMIT}
207211
value={desc}
208212
onChange={({ currentTarget }) => {
209213
setValidationError('');
210-
setDesc(currentTarget.value);
214+
setDesc(currentTarget.value.slice(0, DESC_CHAR_LIMIT));
211215
}}
212216
/>
213-
<FormText>Max 150 characters</FormText>
217+
<BMCharacterLimitHint limit={DESC_CHAR_LIMIT} length={desc.length} />
214218
</FormGroup>
215219
<FormGroup>
216220
<Label for="input-brand">Preferred Make &amp; Model (optional)</Label>

0 commit comments

Comments
 (0)