Skip to content

Commit

Permalink
🐛 allow users to upload with only total number set (#275)
Browse files Browse the repository at this point in the history
also fixes bug introduced with the change earlier this week
  • Loading branch information
munroTom authored Feb 19, 2020
1 parent bf0c3fd commit a10c3a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/components/pages/PhotoPage/Fields/components/Fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { validateIsPositiveNumber } from "../../CategoryField/components/validat

import "./Fields.scss";

const INITIAL_CATEGORY_VALUES = [{ keyIndex: 0, values: { error: true } }];
const INITIAL_CATEGORY_VALUES = [{ keyIndex: 0, values: { error: false } }];

const Fields = ({ imgSrc, handleChange, handleTotalCountChange }) => {
const [categoryValues, setCategoryValues] = useState(INITIAL_CATEGORY_VALUES);
const [childIndex, setNextChildIndex] = useState(categoryValues.length);
const [totalCount, setTotalCount] = useState(null);
const [anyCategoryErrors, setAnyCategoryErrors] = useState(true);
const [anyCategoryErrors, setAnyCategoryErrors] = useState(false);
const [totalCountErrors, setTotalCountErrors] = useState(true);
const [photoEnlarged, setPhotoEnlarged] = useState(false);

Expand All @@ -25,7 +25,7 @@ const Fields = ({ imgSrc, handleChange, handleTotalCountChange }) => {

setTotalCount(newTotalCount);
setTotalCountErrors(countError);
handleTotalCountChange(countError || anyCategoryErrors, totalCount);
handleTotalCountChange(countError || anyCategoryErrors, newTotalCount);
};

const handleClickAdd = categoryValues => {
Expand Down
8 changes: 4 additions & 4 deletions src/components/pages/PhotoPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const emptyState = {
anyError: true,
enabledUploadButton: true,
next: false,
fieldsValues: {},
fieldsValues: [],
totalCount: null
};

Expand Down Expand Up @@ -158,14 +158,14 @@ class PhotoPage extends Component {
return;
}

const { fieldsValues } = this.state;
let totalCount = 0;
const { fieldsValues, totalCount } = this.state;

const fieldValuesToSend = fieldsValues.map(value => {
const {
values: { error, number, ...otherNonExtraneousFields }
} = value;
const numberAsNumber = Number(number);
totalCount += numberAsNumber;

return { number: numberAsNumber, ...otherNonExtraneousFields };
});

Expand Down

0 comments on commit a10c3a7

Please sign in to comment.