Files
twenty/packages/twenty-front/src/modules/settings/workspace/components/NameField.tsx
T
Félix Malfait 1088f7bbab feat: add lingui/no-unlocalized-strings ESLint rule and fix translations (#16610)
## Summary
This PR adds the `lingui/no-unlocalized-strings` ESLint rule to detect
untranslated strings and fixes translation issues across multiple
components.

## Changes

### ESLint Configuration (`eslint.config.react.mjs`)
- Added comprehensive `ignore` patterns for non-translatable strings
(CSS values, HTML attributes, technical identifiers)
- Added `ignoreNames` for props that don't need translation (className,
data-*, aria-*, etc.)
- Added `ignoreFunctions` for console methods, URL APIs, and other
non-user-facing functions
- Disabled rule for debug files, storybook, and test files

### Components Fixed (~19 files)
- Object record components (field inputs, pickers, merge dialogs)
- Settings components (accounts, admin panel)
- Serverless function components
- Record table and title cell components

## Status
🚧 **Work in Progress** - ~124 files remaining to fix

This PR is being submitted as draft to allow progressive fixing of
remaining translation issues.

## Testing
- Run `npx eslint "src/**/*.tsx"` in `packages/twenty-front` to check
remaining issues
2025-12-17 22:08:33 +01:00

101 lines
2.8 KiB
TypeScript

import styled from '@emotion/styled';
import { useCallback, useEffect, useState } from 'react';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { useDebouncedCallback } from 'use-debounce';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { SettingsTextInput } from '@/ui/input/components/SettingsTextInput';
import { useLingui } from '@lingui/react/macro';
import isEmpty from 'lodash.isempty';
import { isDefined } from 'twenty-shared/utils';
import { useUpdateWorkspaceMutation } from '~/generated-metadata/graphql';
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
import { logError } from '~/utils/logError';
const StyledComboInputContainer = styled.div`
display: flex;
flex-direction: row;
> * + * {
margin-left: ${({ theme }) => theme.spacing(4)};
}
`;
type NameFieldProps = {
autoSave?: boolean;
onNameUpdate?: (name: string) => void;
};
export const NameField = ({
autoSave = true,
onNameUpdate,
}: NameFieldProps) => {
const { t } = useLingui();
const currentWorkspace = useRecoilValue(currentWorkspaceState);
const setCurrentWorkspace = useSetRecoilState(currentWorkspaceState);
const [displayName, setDisplayName] = useState(
currentWorkspace?.displayName ?? '',
);
const [updateWorkspace] = useUpdateWorkspaceMutation();
// TODO: Enhance this with react-web-hook-form (https://www.react-hook-form.com)
// eslint-disable-next-line react-hooks/exhaustive-deps
const debouncedUpdate = useCallback(
useDebouncedCallback(async (name: string) => {
if (isEmpty(name)) return;
// 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);
}
if (!autoSave || !name) {
return;
}
try {
const { data, errors } = await updateWorkspace({
variables: {
input: {
displayName: name,
},
},
});
if (isDefined(errors) || isUndefinedOrNull(data?.updateWorkspace)) {
throw errors;
}
} catch (error) {
logError(error);
}
}, 500),
[updateWorkspace, setCurrentWorkspace],
);
useEffect(() => {
debouncedUpdate(displayName);
return debouncedUpdate.cancel;
}, [debouncedUpdate, displayName]);
return (
<StyledComboInputContainer>
<SettingsTextInput
instanceId="workspace-name"
label={t`Name`}
value={displayName}
onChange={setDisplayName}
placeholder={t`Apple`}
fullWidth
/>
</StyledComboInputContainer>
);
};