Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Delete sites from project slice on update #149

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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