Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cicer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
meskio
cicer
Commits
026ae157
Commit
026ae157
authored
4 years ago
by
meskio
Browse files
Options
Downloads
Patches
Plain Diff
Edit price when creating order
parent
f6070e28
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/PriceEditor.js
+11
-11
11 additions, 11 deletions
src/PriceEditor.js
src/ProductPicker.js
+17
-1
17 additions, 1 deletion
src/ProductPicker.js
src/order/CreateOrder.js
+6
-2
6 additions, 2 deletions
src/order/CreateOrder.js
with
34 additions
and
14 deletions
src/PriceEditor.js
+
11
−
11
View file @
026ae157
...
...
@@ -30,25 +30,25 @@ function str2price(str) {
return
parseInt
(
value
[
0
])
*
100
+
cents
;
}
function
PriceEditor
(
props
)
{
const
[
value
,
setValue
]
=
useState
(
"
0,00
"
);
const
[
invalid
,
setInvalid
]
=
useState
(
false
);
if
(
!
isNaN
(
props
.
value
)
&&
str2price
(
value
)
!==
props
.
value
)
{
let
centStr
=
(
props
.
value
%
100
).
toString
();
function
price2str
(
price
)
{
let
centStr
=
(
price
%
100
).
toString
();
if
(
centStr
.
length
===
1
)
{
centStr
=
"
0
"
+
centStr
;
}
setValue
(
Math
.
floor
(
pr
ops
.
valu
e
/
100
)
+
"
,
"
+
centStr
)
;
return
Math
.
floor
(
pr
ic
e
/
100
)
+
"
,
"
+
centStr
;
}
function
PriceEditor
(
props
)
{
const
[
value
,
setValue
]
=
useState
(
price2str
(
props
.
value
));
const
change
=
(
e
)
=>
{
setValue
(
e
.
target
.
value
);
const
price
=
str2price
(
e
.
target
.
value
);
props
.
onChange
(
price
);
setInvalid
(
isNaN
(
price
));
};
const
invalid
=
isNaN
(
props
.
value
);
return
<
Form
.
Control
value
=
{
value
}
onChange
=
{
change
}
isInvalid
=
{
invalid
}
/>
;
}
...
...
This diff is collapsed.
Click to expand it.
src/ProductPicker.js
+
17
−
1
View file @
026ae157
...
...
@@ -3,6 +3,7 @@ import { Form, Row, Col, Button } from "react-bootstrap";
import
{
Typeahead
}
from
"
react-bootstrap-typeahead
"
;
import
Fetcher
from
"
./Fetcher
"
;
import
{
printMoney
}
from
"
./util
"
;
import
PriceEditor
from
"
./PriceEditor
"
;
class
ProductPicker
extends
React
.
Component
{
constructor
(
props
)
{
...
...
@@ -25,6 +26,12 @@ class ProductPicker extends React.Component {
this
.
props
.
setPicks
(
picks
);
}
setPrice
(
index
,
price
)
{
let
picks
=
this
.
props
.
picks
;
picks
[
index
].
price
=
price
;
this
.
props
.
setPicks
(
picks
);
}
setCode
(
codeStr
)
{
const
code
=
parseInt
(
codeStr
);
const
product
=
this
.
state
.
products
.
find
((
p
)
=>
p
.
code
===
code
);
...
...
@@ -69,7 +76,16 @@ class ProductPicker extends React.Component {
<
Col
xs
=
{
4
}
>
<
p
>
{
p
.
name
}
<
/p
>
<
/Col
>
<
Col
>
{
printMoney
(
p
.
price
)
+
"
€
"
}
<
/Col
>
<
Col
>
{
this
.
props
.
price
?
(
<
PriceEditor
value
=
{
p
.
price
}
onChange
=
{(
price
)
=>
this
.
setPrice
(
i
,
price
)}
/
>
)
:
(
printMoney
(
p
.
price
)
+
"
€
"
)}
<
/Col
>
{
this
.
props
.
amount
&&
(
<
Col
>
<
Form
.
Control
...
...
This diff is collapsed.
Click to expand it.
src/order/CreateOrder.js
+
6
−
2
View file @
026ae157
...
...
@@ -45,6 +45,8 @@ function CreateOrder() {
?
prevOrders
.
map
((
o
)
=>
<
option
key
=
{
o
.
name
}
>
{
o
.
name
}
<
/option>
)
:
""
;
const
disabled
=
picks
.
find
((
p
)
=>
isNaN
(
p
.
price
))
!==
undefined
;
return
(
<
Sender
url
=
"
/api/order
"
body
=
{
body
}
onSuccess
=
{
setOrder
}
>
<
Form
.
Group
as
=
{
Row
}
>
...
...
@@ -100,11 +102,13 @@ function CreateOrder() {
/
>
<
/Col
>
<
/Form.Group
>
<
ProductPicker
picks
=
{
picks
}
setPicks
=
{
setPicks
}
/
>
<
ProductPicker
picks
=
{
picks
}
setPicks
=
{
setPicks
}
price
/>
<
Form
.
Group
as
=
{
Row
}
>
<
Col
>
<
div
className
=
"
text-right
"
>
<
Button
type
=
"
submit
"
>
Abrir
pedido
<
/Button
>
<
Button
type
=
"
submit
"
disabled
=
{
disabled
}
>
Abrir
pedido
<
/Button
>
<
/div
>
<
/Col
>
<
/Form.Group
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment