Skip to content

Commit

Permalink
fix: Delete sites from project slice on update (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-code authored Oct 30, 2023
1 parent ca1f283 commit 3e2683f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/site/siteSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import {
SiteAddMutationInput,
SiteTransferMutationInput,
SiteUpdateMutationInput,
} from 'terraso-client-shared/graphqlSchema/graphql';
import {
addSiteToProject,
Expand Down Expand Up @@ -72,9 +73,18 @@ export const addSite = createAsyncThunk<Site, SiteAddMutationInput>(
},
);

export const updateSite = createAsyncThunk(
export const updateSite = createAsyncThunk<Site, SiteUpdateMutationInput>(
'site/updateSite',
siteService.updateSite,
async (input, _currentUser, { dispatch }) => {
const result = await siteService.updateSite(input);
dispatch(removeSiteFromAllProjects(result.id));
if (result.projectId) {
dispatch(
addSiteToProject({ projectId: result.projectId, siteId: input.id }),
);
}
return result;
},
);

export const deleteSite = createAsyncThunk<string, Site>(
Expand Down

0 comments on commit 3e2683f

Please sign in to comment.