Skip to content

Commit 36d7ac1

Browse files
committed
refactor toasts, add toasts for individual keyword view
1 parent 8313f42 commit 36d7ac1

2 files changed

Lines changed: 23 additions & 33 deletions

File tree

frontend/packages/volto-keywordmanager/src/components/KeywordManager.tsx

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -95,39 +95,6 @@ const KeywordManager = (props) => {
9595
dispatch(getKeywordIndexes());
9696
}, [dispatch, options]);
9797

98-
useEffect(() => {
99-
const actionType = keywords.type;
100-
101-
const isUpdate = actionType.startsWith('UPDATE_');
102-
const isDelete = actionType.startsWith('DELETE_');
103-
const isSuccess = actionType.endsWith('_SUCCESS');
104-
const isFail = actionType.endsWith('_FAIL');
105-
106-
if (!isUpdate && !isDelete) return;
107-
108-
if (isUpdate) {
109-
isSuccess &&
110-
toast.success(
111-
<Toast title="Update Success" content="Updated successfully!" />,
112-
);
113-
isFail &&
114-
toast.error(
115-
<Toast error title="Update Failed" content="Could not update." />,
116-
);
117-
}
118-
119-
if (isDelete) {
120-
isSuccess &&
121-
toast.success(
122-
<Toast title="Delete Success" content="Deleted successfully!" />,
123-
);
124-
isFail &&
125-
toast.error(
126-
<Toast error title="Delete Failed" content="Could not delete." />,
127-
);
128-
}
129-
}, [keywords]);
130-
13198
const columns = [
13299
{
133100
id: 'keyword',
@@ -204,6 +171,13 @@ const KeywordManager = (props) => {
204171
setIsLoading(true);
205172
try {
206173
await dispatch(deleteKeywords({ items: kw, indexName: keywordIndex }));
174+
toast.success(
175+
<Toast title="Delete Success" content="Deleted successfully!" />,
176+
);
177+
} catch (error) {
178+
toast.error(
179+
<Toast error title="Delete Failed" content="Could not delete." />,
180+
);
207181
} finally {
208182
setIsLoading(false);
209183
}
@@ -220,6 +194,13 @@ const KeywordManager = (props) => {
220194
indexName: keywordIndex,
221195
}),
222196
);
197+
toast.success(
198+
<Toast title="Update Success" content="Updated successfully!" />,
199+
);
200+
} catch (error) {
201+
toast.error(
202+
<Toast error title="Update Failed" content="Could not update." />,
203+
);
223204
} finally {
224205
setIsLoading(false);
225206
}

frontend/packages/volto-keywordmanager/src/components/KeywordView.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { useDispatch, useSelector } from 'react-redux';
1313
import { Link, useParams } from 'react-router-dom';
1414
import { deleteKeywords } from 'volto-keywordmanager/actions/keywords';
1515
import DeleteModal from './DeleteModal';
16+
import { toast } from 'react-toastify';
17+
import { Toast } from '@plone/components';
1618

1719
import { getVocabulary } from '@plone/volto/actions/vocabularies/vocabularies';
1820
import backSVG from '@plone/volto/icons/back.svg';
@@ -131,6 +133,13 @@ const KeywordView = (props) => {
131133
await dispatch(
132134
deleteKeywords({ items: kw, path: id, indexName: keywordIndex }),
133135
);
136+
toast.success(
137+
<Toast title="Delete Success" content="Deleted successfully!" />,
138+
);
139+
} catch (error) {
140+
toast.error(
141+
<Toast error title="Delete Failed" content="Could not delete." />,
142+
);
134143
} finally {
135144
setIsLoading(false);
136145
}

0 commit comments

Comments
 (0)