Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
PPL Sosial
pilar
pilar-web
Commits
013c876b
Commit
013c876b
authored
May 20, 2021
by
FadhilP
Browse files
[GREEN] Implement invalid date warning
parent
b601cb8c
Pipeline
#78105
passed with stages
in 3 minutes and 43 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/page/batch/EditBatch.jsx
View file @
013c876b
import
React
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
css
}
from
"
@emotion/core
"
;
import
FormBatch
from
"
./FormBatch
"
;
import
ArrowBackIcon
from
"
@material-ui/icons/ArrowBack
"
;
...
...
@@ -7,19 +7,25 @@ import useFetchSingleData from "../../utils/useFetchSingleData";
import
useSendData
from
"
../../utils/useSendData
"
;
import
{
navigate
}
from
"
@reach/router
"
;
import
{
ErrorDiv
}
from
"
../../component/html/html
"
;
import
moment
from
"
moment
"
;
const
EditBatch
=
({
batchId
})
=>
{
const
url
=
`
${
process
.
env
.
REACT_APP_BASE_URL
}
/batch/
${
batchId
}
/`
;
// const url = `http://localhost:8000/batch/${batchId}/`; // for local testing purposes
const
[
initialData
,
errorState
]
=
useFetchSingleData
(
url
);
const
[
send
,
error
]
=
useSendData
({
url
,
method
:
"
PATCH
"
,
redirect
:
-
1
});
const
[
errorMessage
,
setErrorMessage
]
=
useState
(
""
)
const
onSubmit
=
(
data
)
=>
{
if
(
moment
(
data
.
start_date
)
>
moment
(
data
.
end_date
))
{
setErrorMessage
(
"
Tanggal mulai tidak boleh melebihi tanggal akhir!
"
)
}
else
{
const
formData
=
new
FormData
();
formData
.
append
(
"
batch_name
"
,
data
[
"
batch_name
"
]);
formData
.
append
(
"
start_date
"
,
data
[
"
start_date
"
]);
formData
.
append
(
"
end_date
"
,
data
[
"
end_date
"
]);
formData
.
append
(
"
shipping_cost
"
,
data
[
"
shipping_cost
"
])
formData
.
append
(
"
shipping_cost
"
,
data
[
"
shipping_cost
"
])
;
send
(
formData
);
}
};
if
(
errorState
||
Object
.
keys
(
initialData
).
length
===
0
)
return
(
...
...
@@ -90,7 +96,7 @@ const EditBatch = ({ batchId }) => {
Informasi Batch
</
div
>
</
div
>
<
FormBatch
{
...{
onSubmit
,
initialData
,
error
}
}
/>
<
FormBatch
{
...{
onSubmit
,
initialData
,
error
,
errorMessage
}
}
/>
</
div
>
);
};
...
...
src/page/batch/TambahBatch.jsx
View file @
013c876b
import
React
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
css
}
from
"
@emotion/core
"
;
import
FormBatch
from
"
./FormBatch
"
;
import
useSendData
from
"
../../utils/useSendData
"
;
import
{
Link
}
from
"
@reach/router
"
;
import
ArrowBackIcon
from
"
@material-ui/icons/ArrowBack
"
;
import
moment
from
"
moment
"
;
const
TambahBatch
=
()
=>
{
const
url
=
`
${
process
.
env
.
REACT_APP_BASE_URL
}
/batch/`
;
...
...
@@ -12,14 +13,18 @@ const TambahBatch = () => {
method
:
"
POST
"
,
redirect
:
"
/batch
"
,
});
const
[
errorMessage
,
setErrorMessage
]
=
useState
(
""
)
const
onSubmit
=
(
data
)
=>
{
const
formData
=
new
FormData
();
formData
.
append
(
"
batch_name
"
,
data
[
"
batch_name
"
]);
formData
.
append
(
"
start_date
"
,
data
[
"
start_date
"
]);
formData
.
append
(
"
end_date
"
,
data
[
"
end_date
"
]);
formData
.
append
(
"
shipping_cost
"
,
data
[
"
shipping_cost
"
]);
send
(
formData
);
if
(
moment
(
data
.
start_date
)
>
moment
(
data
.
end_date
))
{
setErrorMessage
(
"
Tanggal mulai tidak boleh melebihi tanggal akhir!
"
)
}
else
{
const
formData
=
new
FormData
();
formData
.
append
(
"
batch_name
"
,
data
[
"
batch_name
"
]);
formData
.
append
(
"
start_date
"
,
data
[
"
start_date
"
]);
formData
.
append
(
"
end_date
"
,
data
[
"
end_date
"
]);
formData
.
append
(
"
shipping_cost
"
,
data
[
"
shipping_cost
"
]);
send
(
formData
);
}
};
return
(
<
div
...
...
@@ -57,7 +62,7 @@ const TambahBatch = () => {
>
Informasi Batch
</
div
>
<
FormBatch
{
...{
onSubmit
,
error
}
}
/>
<
FormBatch
{
...{
onSubmit
,
error
,
errorMessage
}
}
/>
</
div
>
);
};
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment