From 3e2683ff813ee8d7a6f6b39dadd46fca00f97ee4 Mon Sep 17 00:00:00 2001 From: David Code Howard Date: Mon, 30 Oct 2023 09:40:53 -0400 Subject: [PATCH] fix: Delete sites from project slice on update (#149) --- src/site/siteSlice.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/site/siteSlice.ts b/src/site/siteSlice.ts index aae9f284..0a361e59 100644 --- a/src/site/siteSlice.ts +++ b/src/site/siteSlice.ts @@ -19,6 +19,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; import { SiteAddMutationInput, SiteTransferMutationInput, + SiteUpdateMutationInput, } from 'terraso-client-shared/graphqlSchema/graphql'; import { addSiteToProject, @@ -72,9 +73,18 @@ export const addSite = createAsyncThunk( }, ); -export const updateSite = createAsyncThunk( +export const updateSite = createAsyncThunk( '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(