Fixed notification emitting

This commit is contained in:
Paweł Malak 2021-11-09 15:04:13 +01:00
parent 969bdb7d24
commit 0d5a4c418e
3 changed files with 76 additions and 45 deletions

View file

@ -11,7 +11,6 @@ import {
UpdateAppAction,
} from '../actions/app';
import axios from 'axios';
import { createNotification } from '.';
export const getApps =
() => async (dispatch: Dispatch<GetAppsAction<undefined | App[]>>) => {
@ -44,9 +43,12 @@ export const pinApp =
? 'unpinned from Homescreen'
: 'pinned to Homescreen';
createNotification({
title: 'Success',
message: `App ${name} ${status}`,
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Success',
message: `App ${name} ${status}`,
},
});
dispatch({
@ -63,9 +65,12 @@ export const addApp =
try {
const res = await axios.post<ApiResponse<App>>('/api/apps', formData);
createNotification({
title: 'Success',
message: `App added`,
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Success',
message: `App added`,
},
});
await dispatch({
@ -74,8 +79,7 @@ export const addApp =
});
// Sort apps
// dispatch<any>(sortApps());
sortApps();
dispatch<any>(sortApps());
} catch (err) {
console.log(err);
}
@ -86,9 +90,12 @@ export const deleteApp =
try {
await axios.delete<ApiResponse<{}>>(`/api/apps/${id}`);
createNotification({
title: 'Success',
message: 'App deleted',
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Success',
message: 'App deleted',
},
});
dispatch({
@ -109,9 +116,12 @@ export const updateApp =
formData
);
createNotification({
title: 'Success',
message: `App updated`,
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Success',
message: `App updated`,
},
});
await dispatch({

View file

@ -1,6 +1,5 @@
import axios from 'axios';
import { Dispatch } from 'redux';
import { createNotification } from '.';
import {
ApiResponse,
Bookmark,
@ -51,9 +50,12 @@ export const addCategory =
formData
);
createNotification({
title: 'Success',
message: `Category ${formData.name} created`,
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Success',
message: `Category ${formData.name} created`,
},
});
dispatch({
@ -61,8 +63,7 @@ export const addCategory =
payload: res.data.data,
});
// dispatch<any>(sortCategories());
sortCategories();
dispatch<any>(sortCategories());
} catch (err) {
console.log(err);
}
@ -77,9 +78,12 @@ export const addBookmark =
formData
);
createNotification({
title: 'Success',
message: `Bookmark created`,
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Success',
message: `Bookmark created`,
},
});
dispatch({
@ -104,9 +108,12 @@ export const pinCategory =
? 'unpinned from Homescreen'
: 'pinned to Homescreen';
createNotification({
title: 'Success',
message: `Category ${name} ${status}`,
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Success',
message: `Category ${name} ${status}`,
},
});
dispatch({
@ -123,9 +130,12 @@ export const deleteCategory =
try {
await axios.delete<ApiResponse<{}>>(`/api/categories/${id}`);
createNotification({
title: 'Success',
message: `Category deleted`,
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Success',
message: `Category deleted`,
},
});
dispatch({
@ -145,9 +155,13 @@ export const updateCategory =
`/api/categories/${id}`,
formData
);
createNotification({
title: 'Success',
message: `Category ${formData.name} updated`,
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Success',
message: `Category ${formData.name} updated`,
},
});
dispatch({
@ -155,8 +169,7 @@ export const updateCategory =
payload: res.data.data,
});
// dispatch<any>(sortCategories());
sortCategories();
dispatch<any>(sortCategories());
} catch (err) {
console.log(err);
}
@ -168,9 +181,12 @@ export const deleteBookmark =
try {
await axios.delete<ApiResponse<{}>>(`/api/bookmarks/${bookmarkId}`);
createNotification({
title: 'Success',
message: 'Bookmark deleted',
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Success',
message: 'Bookmark deleted',
},
});
dispatch({
@ -205,9 +221,12 @@ export const updateBookmark =
formData
);
createNotification({
title: 'Success',
message: `Bookmark updated`,
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Success',
message: `Bookmark updated`,
},
});
// Check if category was changed

View file

@ -18,7 +18,6 @@ import {
} from '../../interfaces';
import { ActionType } from '../action-types';
import { storeUIConfig } from '../../utility';
import { createNotification } from '.';
export const getConfig = () => async (dispatch: Dispatch<GetConfigAction>) => {
try {
@ -53,9 +52,12 @@ export const updateConfig =
try {
const res = await axios.put<ApiResponse<Config>>('/api/config', formData);
createNotification({
title: 'Success',
message: 'Settings updated',
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Success',
message: 'Settings updated',
},
});
dispatch({