802a5b0af6
## Summary - Migrate ~200 files from `@emotion/styled` / `@emotion/react` to `@linaria/react` + `themeCssVariables`, continuing the zero-runtime CSS-in-JS migration (PR 2-3 of the [migration plan](docs/emotion-to-linaria-migration-plan.md)) - Modules covered: **auth** (19), **activities** (53), **ai** (30), **pages** (70), **action-menu** (3), **object-metadata** (4), **onboarding** (2), **workspace** (2), **file** (3), **error-handler** (2), **front-components** (1), **geo-map** (1), **loading** (5), **testing** (5), plus a `style` prop addition to `TableRow` - Handles `styled(FunctionComponent)<Props>` incompatibility with Linaria by using CSS custom properties via `style` + `var()` references ## Test plan - [x] `npx nx lint:diff-with-main twenty-front` passes - [x] `npx nx typecheck twenty-front` passes - [ ] Visual spot-check of auth, onboarding, settings, activities, and AI chat screens - [ ] No remaining `@emotion/styled` or `@emotion/react` imports in migrated files Made with [Cursor](https://cursor.com)
97 lines
3.2 KiB
TypeScript
97 lines
3.2 KiB
TypeScript
import { FrontComponentRendererProvider } from '@/front-components/components/FrontComponentRendererProvider';
|
|
import { useFrontComponentExecutionContext } from '@/front-components/hooks/useFrontComponentExecutionContext';
|
|
import { useOnFrontComponentUpdated } from '@/front-components/hooks/useOnFrontComponentUpdated';
|
|
import { frontComponentApplicationTokenPairComponentState } from '@/front-components/states/frontComponentApplicationTokenPairComponentState';
|
|
import { getFrontComponentUrl } from '@/front-components/utils/getFrontComponentUrl';
|
|
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
|
import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';
|
|
import { t } from '@lingui/core/macro';
|
|
import { useCallback, useContext } from 'react';
|
|
import { FrontComponentRenderer as SharedFrontComponentRenderer } from 'twenty-sdk/front-component-renderer';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { ThemeContext } from 'twenty-ui/theme';
|
|
import { REACT_APP_SERVER_BASE_URL } from '~/config';
|
|
import { useFindOneFrontComponentQuery } from '~/generated-metadata/graphql';
|
|
|
|
type FrontComponentRendererProps = {
|
|
frontComponentId: string;
|
|
};
|
|
|
|
export const FrontComponentRenderer = ({
|
|
frontComponentId,
|
|
}: FrontComponentRendererProps) => {
|
|
const { theme } = useContext(ThemeContext);
|
|
const { enqueueErrorSnackBar } = useSnackBar();
|
|
|
|
const setFrontComponentApplicationTokenPair = useSetAtomComponentState(
|
|
frontComponentApplicationTokenPairComponentState,
|
|
frontComponentId,
|
|
);
|
|
|
|
const { executionContext, frontComponentHostCommunicationApi } =
|
|
useFrontComponentExecutionContext({ frontComponentId });
|
|
|
|
const handleError = useCallback(
|
|
(error?: Error) => {
|
|
if (!isDefined(error)) {
|
|
return;
|
|
}
|
|
|
|
const errorMessage = error.message;
|
|
|
|
enqueueErrorSnackBar({
|
|
message: t`Failed to load front component: ${errorMessage}`,
|
|
});
|
|
},
|
|
[enqueueErrorSnackBar],
|
|
);
|
|
|
|
const { data, loading } = useFindOneFrontComponentQuery({
|
|
variables: { id: frontComponentId },
|
|
onError: handleError,
|
|
onCompleted: (completedData) => {
|
|
const tokenPair = completedData.frontComponent?.applicationTokenPair;
|
|
|
|
if (isDefined(tokenPair)) {
|
|
setFrontComponentApplicationTokenPair(tokenPair);
|
|
}
|
|
},
|
|
});
|
|
|
|
useOnFrontComponentUpdated({
|
|
frontComponentId,
|
|
});
|
|
|
|
const componentUrl = getFrontComponentUrl({
|
|
frontComponentId,
|
|
checksum: data?.frontComponent?.builtComponentChecksum,
|
|
});
|
|
|
|
const applicationTokenPair =
|
|
data?.frontComponent?.applicationTokenPair ?? null;
|
|
|
|
if (
|
|
loading ||
|
|
!isDefined(data?.frontComponent) ||
|
|
!isDefined(applicationTokenPair)
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<FrontComponentRendererProvider frontComponentId={frontComponentId}>
|
|
<SharedFrontComponentRenderer
|
|
theme={theme}
|
|
componentUrl={componentUrl}
|
|
applicationAccessToken={
|
|
applicationTokenPair.applicationAccessToken.token
|
|
}
|
|
apiUrl={REACT_APP_SERVER_BASE_URL}
|
|
executionContext={executionContext}
|
|
frontComponentHostCommunicationApi={frontComponentHostCommunicationApi}
|
|
onError={handleError}
|
|
/>
|
|
</FrontComponentRendererProvider>
|
|
);
|
|
};
|