From 1139da4da7f1bb0ee4a66d420e690beed36832c2 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sun, 4 Dec 2022 21:37:52 +0530 Subject: added notification system --- src/components/editors/client-editor.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/components/editors/client-editor.js') 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 = () => { -- cgit v1.2.3