The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix view deletion (#2314)
bosiraphael27b451ee56ba
diff --git a/front/src/modules/views/components/ViewBarEffect.tsx b/front/src/modules/views/components/ViewBarEffect.tsxindex 51a63a11609..5d499dcbb4d 100644--- a/front/src/modules/views/components/ViewBarEffect.tsx+++ b/front/src/modules/views/components/ViewBarEffect.tsx@@ -41,6 +41,7 @@ export const ViewBarEffect = () => {} = useView();const [searchParams] = useSearchParams();+ const currentViewIdFromUrl = searchParams.get('view');const { viewType, viewObjectId } = useViewGetStates(viewScopeId);@@ -63,7 +64,7 @@ export const ViewBarEffect = () => {if (!nextViews.length) return;- if (!currentViewId) return changeViewInUrl(nextViews[0].id);+ if (!currentViewIdFromUrl) return changeViewInUrl(nextViews[0].id);},),});@@ -223,8 +224,6 @@ export const ViewBarEffect = () => {),});- const currentViewIdFromUrl = searchParams.get('view');-useEffect(() => {if (!currentViewIdFromUrl) return;loadView(currentViewIdFromUrl);diff --git a/front/src/modules/views/hooks/internal/useViewSorts.ts b/front/src/modules/views/hooks/internal/useViewSorts.tsindex 9fe25ababe4..0565cc530f8 100644--- a/front/src/modules/views/hooks/internal/useViewSorts.ts+++ b/front/src/modules/views/hooks/internal/useViewSorts.ts@@ -77,11 +77,11 @@ export const useViewSorts = (viewScopeId: string) => {if (!viewSortIdsToDelete.length) return;return Promise.all(- viewSortIdsToDelete.map((viewFilterId) =>+ viewSortIdsToDelete.map((viewSortId) =>apolloClient.mutate({mutation: deleteOneMutation,variables: {- idToDelete: viewFilterId,+ idToDelete: viewSortId,},}),),diff --git a/front/src/modules/views/hooks/internal/useViews.ts b/front/src/modules/views/hooks/internal/useViews.tsindex a10b572e831..854e35a5458 100644--- a/front/src/modules/views/hooks/internal/useViews.ts+++ b/front/src/modules/views/hooks/internal/useViews.ts@@ -7,10 +7,14 @@ import { viewTypeScopedState } from '@/views/states/viewTypeScopedState';import { View } from '@/views/types/View';export const useViews = (scopeId: string) => {- const { updateOneMutation, createOneMutation, findManyQuery } =- useFindOneObjectMetadataItem({- objectNameSingular: 'viewV2',- });+ const {+ updateOneMutation,+ createOneMutation,+ deleteOneMutation,+ findManyQuery,+ } = useFindOneObjectMetadataItem({+ objectNameSingular: 'viewV2',+ });const apolloClient = useApolloClient();const createView = useRecoilCallback(@@ -54,11 +58,14 @@ export const useViews = (scopeId: string) => {});};- const deleteView = async (_viewId: string) => {- // await deleteViewMutation({- // variables: { where: { id: viewId } },- // refetchQueries: [getOperationName(GET_VIEWS) ?? ''],- // });+ const deleteView = async (viewId: string) => {+ await apolloClient.mutate({+ mutation: deleteOneMutation,+ variables: {+ idToDelete: viewId,+ },+ refetchQueries: [findManyQuery],+ });};return {diff --git a/front/src/modules/views/hooks/useView.ts b/front/src/modules/views/hooks/useView.tsindex 4e9decd6d74..35a12c0bd0d 100644--- a/front/src/modules/views/hooks/useView.ts+++ b/front/src/modules/views/hooks/useView.ts@@ -227,20 +227,22 @@ export const useView = (props?: UseViewProps) => {const removeView = useRecoilCallback(({ set, snapshot }) =>- async (viewId: string) => {+ async (viewIdToDelete: string) => {const currentViewId = await snapshot.getPromise(currentViewIdScopedState({ scopeId }),);- if (currentViewId === viewId)+ if (currentViewId === viewIdToDelete)set(currentViewIdScopedState({ scopeId }), undefined);set(viewsScopedState({ scopeId }), (previousViews) =>- previousViews.filter((view) => view.id !== viewId),+ previousViews.filter((view) => view.id !== viewIdToDelete),);- internalDeleteView(viewId);+ internalDeleteView(viewIdToDelete);++ if (currentViewId === viewIdToDelete) setSearchParams();},- [internalDeleteView, scopeId],+ [internalDeleteView, scopeId, setSearchParams],);const handleViewNameSubmit = useRecoilCallback(