function AddCategory({ handleClose }) {
  const [data, setData] = useState([]);
  const [categoryItem, setItem] = useState({category : ''});
  useEffect(() => {
    try {
      async function getData(){
        let response = await makeRequest({
          method: "GET",
          url: "/v1/getAllCategories",
        });
       
        if(response.data.code === 200){
          setData(response.data.result);
        }
      }
      getData();
    } catch (error) {
      ToastsStore.error(error.message)

    }
  }, []);
  const saveCategory = (category) => {
    try {
      async function saveCategory(){
        let response = await makeRequest({
          method: "POST",
          url: "/v1/addOrUpdateCategory",
          data : category
        });
      }
      saveCategory();
    } catch (error) {
      ToastsStore.error(error.message)

    }
  };
  
  const handleChange = (event) => {
    setItem({category : event.target.value});
  };
  const handleDelete = (category) => {
    try {
      async function saveCategory(){
        let response = await makeRequest({
          method: "POST",
          url: "/v1/deleteCategory",
          data : category
        });
        if(response.data.code === 200){
          setData((data) => data.filter((c) => c.categoryId !== category.categoryId))
        }
      }
      saveCategory();
    } catch (error) {
      ToastsStore.error(error.message)

    }
  };
  return (
    <div className="popup-box">
      <div className="box">
        <span className="close-icon" onClick={handleClose}>
          x
        </span>
        <div className="column">
          <Typography component="h1" variant="h5">
            Add New Category
          </Typography>
         <div className='row margin-y-12'>
         {data.map((categoryItem) => {
          return (
           <div className='margin-x-8'>
           <Chip  
           key={categoryItem.categoryId} 
           className='width-content-fit' 
           label={categoryItem.category} 
           onDelete={() => handleDelete(categoryItem)} color="primary" />
           </div>
          );
        })}
         </div>
          <form noValidate>
            <TextField
              variant="outlined"
              margin="normal"
              required
              fullWidth
              id="category"
              label="Category Name"
              name="category"
              autoComplete="Category Name"
              onChange={handleChange}
              autoFocus
            />
            <Button
              type="submit"
              fullWidth
              variant="contained"
              color="primary"
              onClick={() => saveCategory(categoryItem)}
            >
              Save
            </Button>
          </form>
        </div>
      </div>
    </div>
  );
}
/**
 * Created by Piyush on Sat Nov 21 2020 15:42:34 GMT+0530 (India Standard Time)
 * popup for category
 * Updated by Piyush on Sat Nov 21 2020 15:42:34 GMT+0530 (India Standard Time)
 * popup for category
 */
Created by Piyush on Sat Nov 21 2020 15:42:34 GMT+0530 (India Standard Time)
popup for category
Updated by Piyush on Sat Nov 21 2020 15:42:34 GMT+0530 (India Standard Time)
popup for category
Created by Piyush on Sat Nov 21 2020 15 : 42 : 34 GMT + 0530 ( India Standard Time ) popup for category Updated by Piyush on Sat Nov 21 2020 15 : 42 : 34 GMT + 0530 ( India Standard Time ) popup for category
function AddCategory({ handleClose }) {
  const [data, setData] = useState([]);
  const [categoryItem, setItem] = useState({category : ''});
  useEffect(() => {
    try {
      async function getData(){
        let response = await makeRequest({
          method: "GET",
          url: "/v1/getAllCategories",
        });
        if(response.data.code === 200){
          setData(response.data.result);
        }
      }
      getData();
    } catch (error) {
      ToastsStore.error(error.message)
    }
  }, []);
  const saveCategory = (category) => {
    try {
      async function saveCategory(){
        let response = await makeRequest({
          method: "POST",
          url: "/v1/addOrUpdateCategory",
          data : category
        });
      }
      saveCategory();
    } catch (error) {
      ToastsStore.error(error.message)
    }
  };
  const handleChange = (event) => {
    setItem({category : event.target.value});
  };
  const handleDelete = (category) => {
    try {
      async function saveCategory(){
        let response = await makeRequest({
          method: "POST",
          url: "/v1/deleteCategory",
          data : category
        });
        if(response.data.code === 200){
          setData((data) => data.filter((c) => c.categoryId !== category.categoryId))
        }
      }
      saveCategory();
    } catch (error) {
      ToastsStore.error(error.message)
    }
  };
  return (
    <div className="popup-box">
      <div className="box">
        <span className="close-icon" onClick={handleClose}>
          x
        </span>
        <div className="column">
          <Typography component="h1" variant="h5">
            Add New Category
          </Typography>
         <div className='row margin-y-12'>
         {data.map((categoryItem) => {
          return (
           <div className='margin-x-8'>
           <Chip  
           key={categoryItem.categoryId} 
           className='width-content-fit' 
           label={categoryItem.category} 
           onDelete={() => handleDelete(categoryItem)} color="primary" />
           </div>
          );
        })}
         </div>
          <form noValidate>
            <TextField
              variant="outlined"
              margin="normal"
              required
              fullWidth
              id="category"
              label="Category Name"
              name="category"
              autoComplete="Category Name"
              onChange={handleChange}
              autoFocus
            />
            <Button
              type="submit"
              fullWidth
              variant="contained"
              color="primary"
              onClick={() => saveCategory(categoryItem)}
            >
              Save
            </Button>
          </form>
        </div>
      </div>
    </div>
  );
}
function AddCategory ( { handleClose } ) { const [ data , setData ] = useState ( [ ] ) ; const [ categoryItem , setItem ] = useState ( { category : '' } ) ; useEffect ( ( ) => { try { async function getData ( ) { let response = await makeRequest ( { method : "GET" , url : "/v1/getAllCategories" , } ) ; if ( response . data . code === 200 ) { setData ( response . data . result ) ; } } getData ( ) ; } catch ( error ) { ToastsStore . error ( error . message ) } } , [ ] ) ; const saveCategory = ( category ) => { try { async function saveCategory ( ) { let response = await makeRequest ( { method : "POST" , url : "/v1/addOrUpdateCategory" , data : category } ) ; } saveCategory ( ) ; } catch ( error ) { ToastsStore . error ( error . message ) } } ; const handleChange = ( event ) => { setItem ( { category : event . target . value } ) ; } ; const handleDelete = ( category ) => { try { async function saveCategory ( ) { let response = await makeRequest ( { method : "POST" , url : "/v1/deleteCategory" , data : category } ) ; if ( response . data . code === 200 ) { setData ( ( data ) => data . filter ( ( c ) => c . categoryId !== category . categoryId ) ) } } saveCategory ( ) ; } catch ( error ) { ToastsStore . error ( error . message ) } } ; return ( < div className = "popup-box" > < div className = "box" > < span className = "close-icon" onClick = { handleClose } > 
          x
         < / span > < div className = "column" > < Typography component = "h1" variant = "h5" > 
            Add New Category
           < / Typography > < div className = 'row margin-y-12' > { data . map ( ( categoryItem ) => { return ( < div className = 'margin-x-8' > < Chip key = { categoryItem . categoryId } className = 'width-content-fit' label = { categoryItem . category } onDelete = { ( ) => handleDelete ( categoryItem ) } color = "primary" / > < / div > ) ; } ) } < / div > < form noValidate > < TextField variant = "outlined" margin = "normal" required fullWidth id = "category" label = "Category Name" name = "category" autoComplete = "Category Name" onChange = { handleChange } autoFocus / > < Button type = "submit" fullWidth variant = "contained" color = "primary" onClick = { ( ) => saveCategory ( categoryItem ) } > 
              Save
             < / Button > < / form > < / div > < / div > < / div > ) ; }
Created by Piyush on Sat Nov 21 2020 15:42:34 GMT+0530 (India Standard Time)
 popup for category
 Updated by Piyush on Sat Nov 21 2020 15:42:34 GMT+0530 (India Standard Time)
 popup for category
Created by Piyush on Sat Nov 21 2020 15 : 42 : 34 GMT + 0530 ( India Standard Time ) popup for category Updated by Piyush on Sat Nov 21 2020 15 : 42 : 34 GMT + 0530 ( India Standard Time ) popup for category