Fakultas Ilmu Komputer UI

Commit 7e81f216 authored by Intan Fadilla Andyani's avatar Intan Fadilla Andyani
Browse files

Merge branch 'coldfix' into 'dev'

COLDFIX

See merge request !34
parents 90e29e27 e5b3572b
Pipeline #81599 passed with stages
in 4 minutes and 1 second
......@@ -31,7 +31,7 @@
"reactstrap": "^8.9.0"
},
"scripts": {
"start": "cross-env REACT_APP_BASE_URL=http://localhost:8000 parcel public/index.html",
"start": "cross-env REACT_APP_BASE_URL=$(grep REACT_APP_BASE_URL .env_var | cut -d '=' -f2) parcel public/index.html",
"build": "cross-env REACT_APP_BASE_URL=$(grep REACT_APP_BASE_URL .env_var | cut -d '=' -f2) parcel build public/index.html",
"test": "jest",
"test:coverage": "jest --coverage",
......
......@@ -13,7 +13,7 @@ import {
import { css } from "@emotion/core";
const FormProduk = ({ onSubmit, initialData = null, error }) => {
const [isPreorder, setIsPreorder] = useState(true);
const [isPreorder, setIsPreorder] = useState("");
const { register, handleSubmit, errors, watch } = useForm({
defaultValues:
initialData !== null
......@@ -59,12 +59,11 @@ const FormProduk = ({ onSubmit, initialData = null, error }) => {
if (data.image.length !== 0) formData.append("image", data["image"][0]);
}
else formData.append(key, data[key]);
isPreorder ? formData.delete("stock") : formData.delete("preorder_duration")
isPreorder === "true" ? formData.set("stock" , null) : formData.set("preorder_duration", null)
}
onSubmit(formData);
}, []);
}, [isPreorder]);
return (
<form
......@@ -284,9 +283,8 @@ const FormProduk = ({ onSubmit, initialData = null, error }) => {
name="preorder"
value="true"
id="open"
checked={isPreorder}
ref={register({ required: true })}
onClick={() => setIsPreorder(true)}
onClick={() => setIsPreorder("true")}
/>
<label htmlFor="open">Pre-order</label>
</div>
......@@ -304,9 +302,8 @@ const FormProduk = ({ onSubmit, initialData = null, error }) => {
name="preorder"
value="false"
id="close"
checked={!isPreorder}
ref={register({ required: true })}
onClick={() => setIsPreorder(false)}
onClick={() => setIsPreorder("false")}
/>
<label htmlFor="close">Ready stock</label>
</div>
......@@ -322,15 +319,15 @@ const FormProduk = ({ onSubmit, initialData = null, error }) => {
color: red;
`}
>
*
{isPreorder === "true" && "*"}
</span>
</LabelInput>
<InputForm
data-testid="preorder-duration-input"
type="number"
name="preorder_duration"
ref={register({ required: isPreorder })}
disabled={!isPreorder}
ref={register({ required: isPreorder === "true" })}
disabled={isPreorder ? isPreorder === "false" : true}
/>
{errors.preorder_duration && (
<ErrorDiv>Durasi Pre-order tidak boleh kosong</ErrorDiv>
......@@ -347,15 +344,15 @@ const FormProduk = ({ onSubmit, initialData = null, error }) => {
color: red;
`}
>
*
{isPreorder === "false" && "*"}
</span>
</LabelInput>
<InputForm
data-testid="stock-produk-input"
type="number"
name="stock"
ref={register({ required: !isPreorder })}
disabled={isPreorder}
ref={register({ required: isPreorder === "false" })}
disabled={isPreorder ? isPreorder === "true" : true}
/>
{errors.stock && <ErrorDiv>Stok Produk tidak boleh kosong</ErrorDiv>}
</RowInput>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment