From 0aacdea91457d95fe6eeb9222145c3b13d240263 Mon Sep 17 00:00:00 2001 From: FadhilP Date: Sun, 6 Jun 2021 13:00:10 +0700 Subject: [PATCH 1/4] [REFACTOR] Fix radio button having a default value --- src/page/produk/FormProduk.jsx | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/page/produk/FormProduk.jsx b/src/page/produk/FormProduk.jsx index 3cd7da2..a7c3d64 100644 --- a/src/page/produk/FormProduk.jsx +++ b/src/page/produk/FormProduk.jsx @@ -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 (
{ name="preorder" value="true" id="open" - checked={isPreorder} ref={register({ required: true })} - onClick={() => setIsPreorder(true)} + onClick={() => setIsPreorder("true")} /> @@ -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")} /> @@ -322,15 +319,15 @@ const FormProduk = ({ onSubmit, initialData = null, error }) => { color: red; `} > - * + {isPreorder === "true" && "*"} {errors.preorder_duration && ( Durasi Pre-order tidak boleh kosong @@ -347,15 +344,15 @@ const FormProduk = ({ onSubmit, initialData = null, error }) => { color: red; `} > - * + {isPreorder === "false" && "*"} {errors.stock && Stok Produk tidak boleh kosong} -- GitLab From 5e0dcb4a4c66285b729851843a175034269b7108 Mon Sep 17 00:00:00 2001 From: FadhilP Date: Sun, 6 Jun 2021 13:26:44 +0700 Subject: [PATCH 2/4] [REFACTOR] Fix package.json changed in dev --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3aea092..733a2fa 100644 --- a/package.json +++ b/package.json @@ -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", -- GitLab From 724bb939e6b0b191ed755d7499bb853565bd3f07 Mon Sep 17 00:00:00 2001 From: FadhilP Date: Sun, 6 Jun 2021 22:50:03 +0700 Subject: [PATCH 3/4] [REFACTOR] Fix variable name --- src/component/TableUtils.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/component/TableUtils.jsx b/src/component/TableUtils.jsx index 4b7358e..d995ae1 100644 --- a/src/component/TableUtils.jsx +++ b/src/component/TableUtils.jsx @@ -68,7 +68,7 @@ export const itemDonationStatus = (donation) => { } export const preorderStock = (product) => ( -
{product.pre_order ? "preorder" : product.stock}
+
{product.preorder ? "preorder" : product.stock}
); export const donasiProgram = (program) => ( -- GitLab From fc0783095e6875801b1b3d6cd72e6bd59dbe20fa Mon Sep 17 00:00:00 2001 From: FadhilP Date: Sun, 6 Jun 2021 22:50:26 +0700 Subject: [PATCH 4/4] [REFACTOR] Add new preorder duration column --- src/page/produk/ListProduk.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/page/produk/ListProduk.jsx b/src/page/produk/ListProduk.jsx index 9918aa5..3312c3d 100644 --- a/src/page/produk/ListProduk.jsx +++ b/src/page/produk/ListProduk.jsx @@ -15,6 +15,7 @@ const ListProduk = () => { keyValuePairs: [ ["id", "id"], ["name", "Nama Produk"], + ["preorder_duration", "Preorder Duration"], ["", "Stok", preorderStock], ["unit", "Satuan"], ["price", "Harga Satuan", stringToCurrency], -- GitLab