Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/components/BMDashboard/Equipment/Add/AddTypeForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { toast } from 'react-toastify';
import { useHistory } from 'react-router-dom';

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

const FuelTypes = {
dies: 'Diesel',
Expand All @@ -15,13 +16,15 @@ const FuelTypes = {
etha: 'Ethanol',
};

const DESC_CHAR_LIMIT = 150;

// const [inputText, setInputText] = useState('');

const schema = Joi.object({
name: Joi.string().required(),
desc: Joi.string()
.required()
.max(150),
.max(DESC_CHAR_LIMIT),
});

export default function AddTypeForm() {
Expand All @@ -46,7 +49,7 @@ export default function AddTypeForm() {
setName(event.target.value);
}
if (event.target.name === 'desc') {
setDesc(event.target.value);
setDesc(event.target.value.slice(0, DESC_CHAR_LIMIT));
}
if (event.target.name === 'fuel') {
setFuel(event.target.value);
Expand Down Expand Up @@ -104,13 +107,16 @@ export default function AddTypeForm() {
name="desc"
type="textarea"
rows={2}
maxLength={DESC_CHAR_LIMIT}
value={desc}
invalid={errInput === 'desc'}
onChange={handleChange}
/>
<div className="form-footer" style={{ color: desc.length > 150 ? '#dc3545' : 'black' }}>
Character {desc.length}/150
</div>
<BMCharacterLimitHint
limit={DESC_CHAR_LIMIT}
length={desc.length}
summary={`Character ${desc.length}/${DESC_CHAR_LIMIT}`}
/>
{/* {!errInput && <FormText>Max 150 characters</FormText>} */}
<FormFeedback>
{errType === 'string.max'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import Joi from 'joi-browser';

import { boxStyle } from '~/styles';
import { purchaseEquipment } from '~/actions/bmdashboard/equipmentActions';
import BMCharacterLimitHint from '../shared/BMCharacterLimitHint';

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

const DESC_CHAR_LIMIT = 150;

export default function PurchaseForm() {
const bmProjects = useSelector(state => state.bmProjects);
const equipments = useSelector(state => state.bmInvTypes.list);
Expand Down Expand Up @@ -38,7 +41,7 @@ export default function PurchaseForm() {
estTime: Joi.string().required(),
desc: Joi.string()
.required()
.max(150),
.max(DESC_CHAR_LIMIT),
makeModel: Joi.string().allow(''),
});

Expand Down Expand Up @@ -204,13 +207,14 @@ export default function PurchaseForm() {
<Input
id="input-usage-description"
type="textarea"
maxLength={DESC_CHAR_LIMIT}
value={desc}
onChange={({ currentTarget }) => {
setValidationError('');
setDesc(currentTarget.value);
setDesc(currentTarget.value.slice(0, DESC_CHAR_LIMIT));
}}
/>
<FormText>Max 150 characters</FormText>
<BMCharacterLimitHint limit={DESC_CHAR_LIMIT} length={desc.length} />
</FormGroup>
<FormGroup>
<Label for="input-brand">Preferred Make &amp; Model (optional)</Label>
Expand Down
Loading
Loading