Skip to content

Commit

Permalink
Ignoring empty lines from the textarea
Browse files Browse the repository at this point in the history
  • Loading branch information
wender committed Feb 20, 2020
1 parent 80ec9f8 commit 4e0632b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
4 changes: 2 additions & 2 deletions react/components/AutocompleteBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const AutocompleteBlock: StorefrontFunctionComponent<any> = ({

return (
<div>
<div className="w-third-l w-100-ns">
<div className="w-third-l w-100-ns fl-l">
<div className="flex-grow-1">
<h2 className="t-heading-3 mb3 ml5 ml3-ns mt4">
<FormattedMessage id="quickorder.autocomplete.label" />
Expand All @@ -94,7 +94,7 @@ const AutocompleteBlock: StorefrontFunctionComponent<any> = ({
</div>
</div>
</div>
<div className="w-two-thirds-l w-100-ns">
<div className="w-two-thirds-l w-100-ns fr-l">
<div className="w-100 mb5">
<div className="bg-base t-body c-on-base pa7 br3 b--muted-4 ba">
<div className={'flex flex-column w-60'}>
Expand Down
4 changes: 2 additions & 2 deletions react/components/TextAreaBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const TextAreaBlock: StorefrontFunctionComponent<TextAreaBlockInterface> = ({

return (
<div>
<div className="w-third-l w-100-ns">
<div className="w-third-l w-100-ns fl-l">
<div className="flex-grow-1">
<h2 className="t-heading-3 mb3 ml5 ml3-ns mt4">
<FormattedMessage id="quickorder.textarea.label" />
Expand All @@ -53,7 +53,7 @@ const TextAreaBlock: StorefrontFunctionComponent<TextAreaBlockInterface> = ({
</div>
</div>
</div>
<div className="w-two-thirds-l w-100-ns">
<div className="w-two-thirds-l w-100-ns fr-l">
<div className="w-100 mb5">
<div className="bg-base t-body c-on-base pa7 br3 b--muted-4 ba">
<Textarea
Expand Down
52 changes: 29 additions & 23 deletions react/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
export const GetText = (items: any) => {
let joinLines = items
.map((line: any) => {
Expand All @@ -10,30 +11,35 @@ export const GetText = (items: any) => {
export const ParseText = (textAreaValue: string) => {
const rawText: any = String(textAreaValue || '')
const arrText = String(rawText).split(/[\n\r]/)
let items = arrText.map((line: any, index: number) => {
let lineSplitted: any = line.split(',')
if (lineSplitted.length === 2) {
if (
!!lineSplitted[0] &&
!!String(lineSplitted[1]).trim() &&
!isNaN(lineSplitted[1])
) {
return {
line: index,
sku: String(lineSplitted[0]).trim(),
quantity: parseInt(String(lineSplitted[1]).trim()),
content: line,
error: null,
let items = arrText
.filter((item: any) => {
return String(item).trim() !== ''
})
.map((line: any, index: number) => {
let lineSplitted: any = line.split(',')
if (lineSplitted.length === 2) {
if (
!!lineSplitted[0] &&
!!String(lineSplitted[1]).trim() &&
!isNaN(lineSplitted[1])
) {
return {
line: index,
sku: String(lineSplitted[0]).trim(),
quantity: parseInt(String(lineSplitted[1]).trim()),
content: line,
error: null,
}
}
}
}
return {
line: index,
content: line,
sku: null,
quantity: null,
error: 'quickorder.invalidPattern',
}
})
return {
line: index,
content: line,
sku: null,
quantity: null,
error: 'quickorder.invalidPattern',
}
})
console.log('Items', items)
return items
}

0 comments on commit 4e0632b

Please sign in to comment.