aboutsummaryrefslogtreecommitdiff
path: root/src/store/actions
diff options
context:
space:
mode:
authorIvan Chen <ivan@thetaggid.com>2021-01-12 12:38:46 -0500
committerGitHub <noreply@github.com>2021-01-12 12:38:46 -0500
commit6892c63b899b46fedc9d99b8274a17e9043fe361 (patch)
tree454d836c5848b4d9b2e082ae19e4e64679ccd49d /src/store/actions
parentd955c6bc31be3b2e3e289a8dec8b5970251d4090 (diff)
[TMA-527/506/523] Custom Moment Categories (#174)
* changed logic to allow ≥ 1 categories * now using array of strings for moment categories * updated error strings * formatting and check for picker cancellation * initial UI done * cleaned up logic, added custom icon * renamed onboarding stack to match main stack * removed unused import * deterministic color picker * custom category defaults to selected instead of added * removed function in route
Diffstat (limited to 'src/store/actions')
-rw-r--r--src/store/actions/momentCategories.tsx23
1 files changed, 5 insertions, 18 deletions
diff --git a/src/store/actions/momentCategories.tsx b/src/store/actions/momentCategories.tsx
index a522c3e0..987fc9e5 100644
--- a/src/store/actions/momentCategories.tsx
+++ b/src/store/actions/momentCategories.tsx
@@ -1,13 +1,8 @@
import {RootState} from '../rootReducer';
-import {
- deleteMomentCategories,
- loadMomentCategories,
- postMomentCategories,
-} from '../../services';
+import {loadMomentCategories, postMomentCategories} from '../../services';
import {Action, ThunkAction} from '@reduxjs/toolkit';
import {momentCategoriesFetched} from '../reducers';
import {getTokenOrLogout} from '../../utils';
-import {MomentCategoryType} from '../../types';
/**
* Load all categories for user
@@ -23,7 +18,7 @@ export const loadUserMomentCategories = (
const categories = await loadMomentCategories(userId, token);
dispatch({
type: momentCategoriesFetched.type,
- payload: {categories, add: true},
+ payload: {categories},
});
} catch (error) {
console.log(error);
@@ -33,28 +28,20 @@ export const loadUserMomentCategories = (
/**
* Handle addition / deletion of categories for a user
* @param categories List of categories
- * @param add boolean, if true, we add new categories, else we delete
* @param userId id of the user for whom categories should be updated
*/
export const updateMomentCategories = (
- categories: Array<MomentCategoryType>,
- add: boolean,
- userId: string,
+ categories: string[],
): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
dispatch,
) => {
try {
const token = await getTokenOrLogout(dispatch);
- let success = false;
- if (add) {
- success = await postMomentCategories(categories, token);
- } else {
- success = await deleteMomentCategories(categories, userId, token);
- }
+ const success = await postMomentCategories(categories, token);
if (success) {
dispatch({
type: momentCategoriesFetched.type,
- payload: {categories, add},
+ payload: {categories},
});
}
} catch (error) {