Skip to content

Commit

Permalink
Merge pull request #83 from JooLuiz/enhancement/not-show-validate-but…
Browse files Browse the repository at this point in the history
…ton-if-empty

[Enhancement] Changing the validate button in TextArea and Upload blocks to only be shown if the user has written something or sent a file, respectively
  • Loading branch information
whc105 authored Feb 9, 2022
2 parents 6ab5017 + 2bf64e4 commit b1319ca
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Changing the validate button in TextArea and Upload blocks to only be shown if the user has written something or sent a file, respectively

## [3.6.0] - 2022-02-09

### Added
Expand Down
20 changes: 11 additions & 9 deletions react/TextAreaBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,17 @@ const TextAreaBlock: FunctionComponent<TextAreaBlockInterface &
}
/>
<div className={`mt2 flex justify-end ${handles.buttonValidate}`}>
<Button
variation="secondary"
size="regular"
onClick={() => {
parseText()
}}
>
<FormattedMessage id="store/quickorder.validate" />
</Button>
{textAreaValue && (
<Button
variation="secondary"
size="regular"
onClick={() => {
parseText()
}}
>
<FormattedMessage id="store/quickorder.validate" />
</Button>
)}
</div>
</div>
</div>
Expand Down
33 changes: 22 additions & 11 deletions react/UploadBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ const UploadBlock: FunctionComponent<UploadBlockInterface &
showAddToCart: false,
})

const [showValidateButton, setShowValidateButton] = useState<boolean>(false)

const [refidLoading, setRefIdLoading] = useState<any>()
const [productsQueue, setproductsQueue] = useState<any>()
const { reviewItems, reviewState, showAddToCart } = state

const [
Expand Down Expand Up @@ -151,7 +154,7 @@ const UploadBlock: FunctionComponent<UploadBlockInterface &
const parseText = () => {
let textAreaValue = ''

productsArray.forEach(element => {
productsQueue.forEach(element => {
textAreaValue += `${element[0]},${element[1]}\n`
})

Expand Down Expand Up @@ -209,6 +212,9 @@ const UploadBlock: FunctionComponent<UploadBlockInterface &
p[0] = (p[0] || '').toString().trim()
p[1] = (p[1] || '').toString().trim()
})

setShowValidateButton(true)
setproductsQueue(productsArray)
}

reader.onerror = () => {
Expand All @@ -222,13 +228,16 @@ const UploadBlock: FunctionComponent<UploadBlockInterface &
doFile(files)
}

const handleReset = () => {}
const handleReset = () => {
setShowValidateButton(false)
}

const backList = () => {
setState({
...state,
reviewState: false,
})
setShowValidateButton(false)
}

const callAddToCart = async (items: any) => {
Expand Down Expand Up @@ -418,15 +427,17 @@ const UploadBlock: FunctionComponent<UploadBlockInterface &
</div>
</Dropzone>
<div className={`mt2 flex justify-end ${handles.buttonValidate}`}>
<Button
variation="secondary"
size="regular"
onClick={() => {
parseText()
}}
>
<FormattedMessage id="store/quickorder.validate" />
</Button>
{showValidateButton && (
<Button
variation="secondary"
size="regular"
onClick={() => {
parseText()
}}
>
<FormattedMessage id="store/quickorder.validate" />
</Button>
)}
</div>
</div>
</div>
Expand Down

0 comments on commit b1319ca

Please sign in to comment.