From e0efa358dee056a7167732c3f8ad1a87bd5bfa85 Mon Sep 17 00:00:00 2001 From: Arun Kumar Date: Thu, 18 Apr 2024 20:24:32 +0530 Subject: [PATCH] Fixes #5024: Update local recoil state when workspace name changes (#5033) This PR fixes #5024. Local recoil state was not updated when workspace name is changed. This PR updates local recoil state so that dropdown (and other parts of the app) correctly shows the workspace name without reload. --- .../settings/workspace/components/NameField.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/twenty-front/src/modules/settings/workspace/components/NameField.tsx b/packages/twenty-front/src/modules/settings/workspace/components/NameField.tsx index d2d01267b..3a921e92f 100644 --- a/packages/twenty-front/src/modules/settings/workspace/components/NameField.tsx +++ b/packages/twenty-front/src/modules/settings/workspace/components/NameField.tsx @@ -1,6 +1,6 @@ import { useCallback, useEffect, useState } from 'react'; import styled from '@emotion/styled'; -import { useRecoilValue } from 'recoil'; +import { useRecoilValue, useSetRecoilState } from 'recoil'; import { useDebouncedCallback } from 'use-debounce'; import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState'; @@ -28,6 +28,7 @@ export const NameField = ({ onNameUpdate, }: NameFieldProps) => { const currentWorkspace = useRecoilValue(currentWorkspaceState); + const setCurrentWorkspace = useSetRecoilState(currentWorkspaceState); const [displayName, setDisplayName] = useState( currentWorkspace?.displayName ?? '', @@ -39,6 +40,17 @@ export const NameField = ({ // eslint-disable-next-line react-hooks/exhaustive-deps const debouncedUpdate = useCallback( useDebouncedCallback(async (name: string) => { + // update local recoil state when workspace name is updated + setCurrentWorkspace((currentValue) => { + if (currentValue === null) { + return null; + } + + return { + ...currentValue, + displayName: name, + }; + }); if (isDefined(onNameUpdate)) { onNameUpdate(displayName); } @@ -61,7 +73,7 @@ export const NameField = ({ logError(error); } }, 500), - [updateWorkspace], + [updateWorkspace, setCurrentWorkspace], ); useEffect(() => {