From 39819430fa47172c1a3a36218339f6baf86f8983 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Tue, 27 Sep 2022 21:42:51 +0530 Subject: added edit option for items and brands --- src/components/editors/brand-editor.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/components/editors/brand-editor.js') diff --git a/src/components/editors/brand-editor.js b/src/components/editors/brand-editor.js index 801a790..26f4cca 100644 --- a/src/components/editors/brand-editor.js +++ b/src/components/editors/brand-editor.js @@ -15,13 +15,13 @@ * along with this program. If not, see . */ -import { Brand, saveBrand } from './../../classes/brand' +import { Brand, saveBrand, editBrand } from './../../classes/brand' import './scss/brand-editor.scss' import { useState, useEffect } from 'react'; const BrandEditor = (props) => { - const [name, setName] = useState(""); + const [name, setName] = useState(props.brand.Name); const handleSubmit = (e) => { e.preventDefault(); @@ -29,13 +29,15 @@ const BrandEditor = (props) => { const brand = new Brand(); brand.Name = name; - // TODO: Save is for new brands. implement modification too - saveBrand(brand, handleSuccess, handleFail); + props.editing + ? editBrand(brand, handleSuccess, handleFail) + : saveBrand(brand, handleSuccess, handleFail); } const handleSuccess = () => { clearAll(); props.callback(); + props.editing && props.hide(); } const handleFail = () => { @@ -47,8 +49,8 @@ const BrandEditor = (props) => { } const handleCancel = () => { - // TODO: hide this component or something clearAll(); + props.editing && props.hide(); } const validateFloatInput = (e, callback) => { @@ -57,7 +59,7 @@ const BrandEditor = (props) => { } return ( -
+

{props.heading}

- + + {props.editing && + + } -- cgit v1.2.3