From 79c5aea2c4c0d6a524c6da2590d7be883fe09093 Mon Sep 17 00:00:00 2001 From: Fatima-Bibi Date: Fri, 15 Nov 2024 10:44:02 +0500 Subject: [PATCH] Fixed Apollo Error When Saving Category Name with Highlighted Auto-Suggestion #639 --- .../src/components/Category/Category.jsx | 20 +++++++++++-------- .../src/config/constants.js | 2 +- .../src/screens/Checkout/Checkout.js | 2 ++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/enatega-multivendor-admin/src/components/Category/Category.jsx b/enatega-multivendor-admin/src/components/Category/Category.jsx index 86fb88f4..d495377b 100644 --- a/enatega-multivendor-admin/src/components/Category/Category.jsx +++ b/enatega-multivendor-admin/src/components/Category/Category.jsx @@ -14,8 +14,8 @@ const CREATE_CATEGORY = gql` const EDIT_CATEGORY = gql` ${editCategory} ` - function Category(props) { + console.log("props",props); const mutation = props.category ? EDIT_CATEGORY : CREATE_CATEGORY const [mainError, mainErrorSetter] = useState('') const [success, successSetter] = useState('') @@ -24,20 +24,24 @@ function Category(props) { ) const restaurantId = localStorage.getItem('restaurantId') const onCompleted = data => { + console.log("category",props.category) const message = props.category ? t('CategoryUpdatedSuccessfully') : t('CategoryAddedSuccessfully') successSetter(message) mainErrorSetter('') - setCategory('') - setTimeout(hideAlert, 3000) - } - const onError = error => { - const message = `${t('ActionFailedTryAgain')} ${error}` - successSetter('') - mainErrorSetter(message) + setCategory('') setTimeout(hideAlert, 3000) } + const onError = (error) => { + let message = t('ActionFailedTryAgain'); + if (error.message.includes('Category already exists')) { + message = error.message; + } + successSetter(''); + mainErrorSetter(message); + setTimeout(hideAlert, 3000); + }; const [mutate, { loading }] = useMutation(mutation, { onError, onCompleted }) const hideAlert = () => { mainErrorSetter('') diff --git a/enatega-multivendor-admin/src/config/constants.js b/enatega-multivendor-admin/src/config/constants.js index 5fcdfb2d..28ba5e9f 100644 --- a/enatega-multivendor-admin/src/config/constants.js +++ b/enatega-multivendor-admin/src/config/constants.js @@ -4,7 +4,7 @@ import ConfigurationContext from '../context/Configuration' const ConfigurableValues = () => { const configuration = useContext(ConfigurationContext) - const SERVER_URL = 'https://enatega-multivendor.up.railway.app' + const SERVER_URL = 'https://enatega-multivendor.up.railway.app' const WS_SERVER_URL = 'wss://enatega-multivendor.up.railway.app' // const SERVER_URL = 'http://localhost:8001' // const WS_SERVER_URL = 'ws://localhost:8001' diff --git a/enatega-multivendor-web/src/screens/Checkout/Checkout.js b/enatega-multivendor-web/src/screens/Checkout/Checkout.js index 04068aca..750779c7 100644 --- a/enatega-multivendor-web/src/screens/Checkout/Checkout.js +++ b/enatega-multivendor-web/src/screens/Checkout/Checkout.js @@ -149,6 +149,7 @@ function Checkout() { let costType = configuration.costType; let amount = calculateAmount(costType, configuration.deliveryRate, distance); setDeliveryCharges(amount > 0 ? amount : configuration.deliveryRate); + } })(); }, [data, location]); @@ -450,6 +451,7 @@ function Checkout() { toggleCloseModal(); return; } + if (!cart.length) { showMessage({ type: "error",