reset main context store viewId and current view type on settings page (#11206)

closes https://github.com/twentyhq/core-team-issues/issues/588

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
nitin
2025-03-28 13:56:59 +05:30
committed by GitHub
parent 391392dd87
commit c294d967a3
3 changed files with 89 additions and 32 deletions

View File

@ -1,12 +1,13 @@
import { MainContextStoreProviderEffect } from '@/context-store/components/MainContextStoreProviderEffect';
import { useIsSettingsPage } from '@/navigation/hooks/useIsSettingsPage';
import { useLastVisitedView } from '@/navigation/hooks/useLastVisitedView';
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
import { prefetchIndexViewIdFromObjectMetadataItemFamilySelector } from '@/prefetch/states/selector/prefetchIndexViewIdFromObjectMetadataItemFamilySelector';
import { AppPath } from '@/types/AppPath';
import { useParams, useSearchParams } from 'react-router-dom';
import { useRecoilValue } from 'recoil';
import { useIsMatchingLocation } from '~/hooks/useIsMatchingLocation';
import { isDefined } from 'twenty-shared/utils';
import { useIsMatchingLocation } from '~/hooks/useIsMatchingLocation';
const getViewId = (
viewIdFromQueryParams: string | null,
@ -32,12 +33,7 @@ export const MainContextStoreProvider = () => {
const { isMatchingLocation } = useIsMatchingLocation();
const isRecordIndexPage = isMatchingLocation(AppPath.RecordIndexPage);
const isRecordShowPage = isMatchingLocation(AppPath.RecordShowPage);
const pageName = isRecordIndexPage
? 'record-index'
: isRecordShowPage
? 'record-show'
: undefined;
const isSettingsPage = useIsSettingsPage();
const objectNamePlural = useParams().objectNamePlural ?? '';
const objectNameSingular = useParams().objectNameSingular ?? '';
@ -67,7 +63,10 @@ export const MainContextStoreProvider = () => {
const viewId = getViewId(viewIdQueryParam, indexViewId, lastVisitedViewId);
if (!isDefined(pageName) || !isDefined(objectMetadataItem)) {
const shouldComputeContextStore =
isRecordIndexPage || isRecordShowPage || isSettingsPage;
if (!shouldComputeContextStore) {
return null;
}
@ -75,7 +74,9 @@ export const MainContextStoreProvider = () => {
<MainContextStoreProviderEffect
viewId={viewId}
objectMetadataItem={objectMetadataItem}
pageName={pageName}
isRecordIndexPage={isRecordIndexPage}
isRecordShowPage={isRecordShowPage}
isSettingsPage={isSettingsPage}
/>
);
};