Fakultas Ilmu Komputer UI

Commit c65216fe authored by Fadhil Pradipta Widyanto's avatar Fadhil Pradipta Widyanto
Browse files

COLDFIX

parent 930e8d38
......@@ -15,9 +15,9 @@ const EditProduk = ({ productId }) => {
const onSubmit = (data) => {
send(data);
};
return (
<Fragment>
{errorState || Object.keys(initialData.length === 0) ? (<div
if (errorState || Object.keys(initialData).length === 0) {
return (
<div
data-testid="waiting-edit-produk"
css={css`
display: flex;
......@@ -27,7 +27,12 @@ const EditProduk = ({ productId }) => {
`}
>
Fetching data..
</div>) : (<div
</div>
)
}
return (
<Fragment>
<div
data-testid="edit-produk"
css={css`
display: flex;
......@@ -81,7 +86,7 @@ const EditProduk = ({ productId }) => {
</div>
</div>
<FormProduk {...{ onSubmit, initialData, error }} />
</div>)}
</div>
</Fragment>
)
};
......
......@@ -113,15 +113,13 @@ const FormProduk = ({ onSubmit, initialData = null, error }) => {
}
const formData = new FormData();
const formKey = ["image"];
const formCurrency = ["modal", "price"];
// Loop through every field in form and append to FormData
for (const key in data) {
if (formKey.includes(key)) {
if (data.image.length !== 0)
formData.append("image", data["image"][0]);
} else if (formCurrency.includes(key))
formData.append(key, formatValue(data[key]));
}
else formData.append(key, data[key]);
isPreorder === "true"
? formData.set("stock", "")
......@@ -129,6 +127,9 @@ const FormProduk = ({ onSubmit, initialData = null, error }) => {
isHampers === "false"
? formData.set("hampers_price", "")
: formData.set("hampers_price", data["hampers_price"]);
formData.set("modal", formatValue(valueModal))
formData.set("price", formatValue(valueHarga))
}
onSubmit(formData);
},
......@@ -182,30 +183,28 @@ const FormProduk = ({ onSubmit, initialData = null, error }) => {
{/* NAME SECTION END */}
{/* MODAL SECTION START */}
{/* SATUAN SECTION START */}
<RowInput>
<LabelInput htmlFor="modal">Modal/Satuan </LabelInput>
<MaskedInput
data-testid="modal-produk-input"
type="text"
name="modal"
<RowInput>
<LabelInput htmlFor="unit">
Satuan
<span
css={css`
color: red;
`}
>
*
</span>
</LabelInput>
<InputForm
data-testid="unit-produk-input"
name="unit"
ref={register({ required: true })}
onChange={onChangeModal}
mask={currencyMask}
css={css`
flex-grow: 4;
border: 1px solid #e0e1e2;
box-sizing: border-box;
border-radius: 4px;
font-size: 1rem;
padding-left: 1rem;
`}
/>
{errorModal === 1 && <ErrorDiv>Modal tidak boleh kosong</ErrorDiv>}
{errors.unit && <ErrorDiv>Satuan Produk tidak boleh kosong</ErrorDiv>}
</RowInput>
{/* MODAL SECTION END */}
{/* SATUAN SECTION END */}
{/* CATEGORY SECTION START */}
......@@ -303,6 +302,31 @@ const FormProduk = ({ onSubmit, initialData = null, error }) => {
{/* DESCRIPTION SECTION END */}
{/* MODAL SECTION START */}
<RowInput>
<LabelInput htmlFor="modal">Modal/Satuan </LabelInput>
<MaskedInput
data-testid="modal-produk-input"
type="text"
name="modal"
ref={register({ required: true })}
onChange={onChangeModal}
mask={currencyMask}
css={css`
flex-grow: 4;
border: 1px solid #e0e1e2;
box-sizing: border-box;
border-radius: 4px;
font-size: 1rem;
padding-left: 1rem;
`}
/>
{errorModal === 1 && <ErrorDiv>Modal tidak boleh kosong</ErrorDiv>}
</RowInput>
{/* MODAL SECTION END */}
{/* HARGA SECTION START */}
<RowInput>
......@@ -505,29 +529,6 @@ const FormProduk = ({ onSubmit, initialData = null, error }) => {
{/* PREORDER SECTION END */}
{/* SATUAN SECTION START */}
<RowInput>
<LabelInput htmlFor="unit">
Satuan
<span
css={css`
color: red;
`}
>
*
</span>
</LabelInput>
<InputForm
data-testid="unit-produk-input"
name="unit"
ref={register({ required: true })}
/>
{errors.unit && <ErrorDiv>Satuan Produk tidak boleh kosong</ErrorDiv>}
</RowInput>
{/* SATUAN SECTION END */}
{/* IMAGE SECTION START */}
<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