aboutsummaryrefslogtreecommitdiff
path: root/src/components/editors
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/editors')
-rw-r--r--src/components/editors/brand-editor.js15
-rw-r--r--src/components/editors/client-editor.js24
-rw-r--r--src/components/editors/item-editor.js24
-rw-r--r--src/components/editors/multi-address-editor.js1
4 files changed, 50 insertions, 14 deletions
diff --git a/src/components/editors/brand-editor.js b/src/components/editors/brand-editor.js
index 7796c68..2b7806e 100644
--- a/src/components/editors/brand-editor.js
+++ b/src/components/editors/brand-editor.js
@@ -16,8 +16,10 @@
*/
import { Brand, saveBrand, editBrand } from './../../classes/brand'
+import { notificationConfig } from "./../../classes/notifications";
import './scss/brand-editor.scss'
+import { Store } from "react-notifications-component";
import { useState } from 'react';
const BrandEditor = (props) => {
@@ -36,13 +38,22 @@ const BrandEditor = (props) => {
}
const handleSuccess = () => {
+ Store.addNotification({
+ title: `Successfully ${props.editing ? "edited" : "added"} brand!`,
+ message: `${name} has successfully been ${props.editing ? "edited" : "saved"}.`,
+ ...notificationConfig("success")
+ });
clearAll();
props.callback();
props.editing && props.hide();
}
- const handleFail = () => {
- alert("fail");
+ const handleFail = err => {
+ Store.addNotification({
+ title: "An error occoured",
+ message: `Failed to ${props.editing ? "edit" : "add"} brand '${name}'. ${err.message}`,
+ ...notificationConfig("danger")
+ });
}
const clearAll = () => {
diff --git a/src/components/editors/client-editor.js b/src/components/editors/client-editor.js
index 9a752c7..96ab639 100644
--- a/src/components/editors/client-editor.js
+++ b/src/components/editors/client-editor.js
@@ -16,11 +16,13 @@
*/
import { Client, saveClient, editClient, Contact, Address } from './../../classes/client';
+import { notificationConfig } from "./../../classes/notifications";
import MultiAddressEditor from './multi-address-editor';
import AddressEditor from './address-editor';
import ContactEditor from './contact-editor';
import './scss/client-editor.scss';
+import { Store } from "react-notifications-component";
import { useState, useEffect } from 'react';
const ClientEditor = (props) => {
@@ -37,8 +39,8 @@ const ClientEditor = (props) => {
// will delete existing shipping addresses if false
useEffect(() =>
- setShippingAddresses(shipToBillingAddress ? [] : (shippingAddresses.length > 0 ? shippingAddresses : [new Address()]))
- , [shipToBillingAddress, shippingAddresses]);
+ setShippingAddresses(i => shipToBillingAddress ? [] : (i.length > 0 ? i : [new Address()]))
+ , [shipToBillingAddress]);
const handleSubmit = (e) => {
e.preventDefault();
@@ -63,15 +65,23 @@ const ClientEditor = (props) => {
}
const handleSuccess = (res) => {
- console.log("Successfully saved client", res)
+ Store.addNotification({
+ title: `Successfully ${props.editing ? "edited" : "added"} client!`,
+ message: `${name} has successfully been ${props.editing ? "edited" : "saved"}.`,
+ ...notificationConfig("success")
+ });
clearAll();
- props.successCallback();
+ props.successCallback && props.successCallback();
props.editing && props.hide();
}
- const handleFail = (err) => {
- alert("error while saving client. please check logs");
- console.log(err);
+ const handleFail = err => {
+ Store.addNotification({
+ title: "An error occoured",
+ message: `Failed to edit client ${name}. ${err.message}`,
+ ...notificationConfig("danger")
+ });
+ console.log(err)
}
const clearAll = () => {
diff --git a/src/components/editors/item-editor.js b/src/components/editors/item-editor.js
index be0ac4f..c1d260d 100644
--- a/src/components/editors/item-editor.js
+++ b/src/components/editors/item-editor.js
@@ -17,9 +17,11 @@
import { Item, saveItem, editItem } from './../../classes/item';
import { Brand, getAllBrands } from './../../classes/brand';
+import { notificationConfig } from "./../../classes/notifications";
import './scss/item-editor.scss';
import { useState, useEffect } from 'react';
+import { Store } from "react-notifications-component";
const ItemEditor = (props) => {
const [name, setName] = useState(props.item.Name);
@@ -37,8 +39,13 @@ const ItemEditor = (props) => {
// get saved brands from API
// needed by the brands dropdown menu
useEffect(() => {
- // TODO: handle error
- getAllBrands(setSavedBrands, () => {});
+ getAllBrands(setSavedBrands, err => {
+ Store.addNotification({
+ title: "Error while getting Brands list.",
+ message: err.message,
+ ...notificationConfig("danger")
+ });
+ });
}, [])
const handleSubmit = (e) => {
@@ -76,13 +83,22 @@ const ItemEditor = (props) => {
}
const handleSuccess = () => {
+ Store.addNotification({
+ title: `Successfully ${props.editing ? "edited" : "added"} item!`,
+ message: `${name} has successfully been ${props.editing ? "edited" : "saved"}.`,
+ ...notificationConfig("success")
+ });
clearAll();
props.callback();
props.editing && props.hide();
}
- const handleFail = () => {
- alert("fail");
+ const handleFail = err => {
+ Store.addNotification({
+ title: "An error occoured",
+ message: `Failed to ${props.editing ? "edit" : "add"} item ${name}. ${err.message}`,
+ ...notificationConfig("danger")
+ });
}
const handleBrandSelect = (e) => {
diff --git a/src/components/editors/multi-address-editor.js b/src/components/editors/multi-address-editor.js
index 1159fab..1ea58b7 100644
--- a/src/components/editors/multi-address-editor.js
+++ b/src/components/editors/multi-address-editor.js
@@ -18,7 +18,6 @@
import AddressEditor from './address-editor';
const MultiAddressEditor = ({addresses, setAddresses, setShipToBillingAddress}) => {
- console.log(addresses)
const handleChange = (id, data) => {
const newAddresses = [...addresses];
newAddresses[id] = {