# Introduction In this PR we've migrated `twenty-shared` from a `vite` app [libary-mode](https://vite.dev/guide/build#library-mode) to a [preconstruct](https://preconstruct.tools/) "atomic" application ( in the future would like to introduce preconstruct to handle of all our atomic dependencies such as `twenty-emails` `twenty-ui` etc it will be integrated at the monorepo's root directly, would be to invasive in the first, starting incremental via `twenty-shared`) For more information regarding the motivations please refer to nor: - https://github.com/twentyhq/core-team-issues/issues/587 - https://github.com/twentyhq/core-team-issues/issues/281#issuecomment-2630949682 close https://github.com/twentyhq/core-team-issues/issues/589 close https://github.com/twentyhq/core-team-issues/issues/590 ## How to test In order to ease the review this PR will ship all the codegen at the very end, the actual meaning full diff is `+2,411 −114` In order to migrate existing dependent packages to `twenty-shared` multi barrel new arch you need to run in local: ```sh yarn tsx packages/twenty-shared/scripts/migrateFromSingleToMultiBarrelImport.ts && \ npx nx run-many -t lint --fix -p twenty-front twenty-ui twenty-server twenty-emails twenty-shared twenty-zapier ``` Note that `migrateFromSingleToMultiBarrelImport` is idempotent, it's atm included in the PR but should not be merged. ( such as codegen will be added before merging this script will be removed ) ## Misc - related opened issue preconstruct https://github.com/preconstruct/preconstruct/issues/617 ## Closed related PR - https://github.com/twentyhq/twenty/pull/11028 - https://github.com/twentyhq/twenty/pull/10993 - https://github.com/twentyhq/twenty/pull/10960 ## Upcoming enhancement: ( in others dedicated PRs ) - 1/ refactor generate barrel to export atomic module instead of `*` - 2/ generate barrel own package with several files and tests - 3/ Migration twenty-ui the same way - 4/ Use `preconstruct` at monorepo global level ## Conclusion As always any suggestions are welcomed !
124 lines
3.2 KiB
TypeScript
124 lines
3.2 KiB
TypeScript
import styled from '@emotion/styled';
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { MainButton } from '@/ui/input/button/MainButton';
|
|
import { TextInput } from '@/ui/input/components/TextInput';
|
|
import { clearStore } from '~/utils/apolloClient';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
const StyledWrapper = styled.div`
|
|
align-items: center;
|
|
background: ${({ theme }) => theme.background.primary};
|
|
display: flex;
|
|
height: 100vh;
|
|
justify-content: center;
|
|
`;
|
|
|
|
const StyledContainer = styled.div`
|
|
width: 400px;
|
|
height: 350px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: ${({ theme }) => theme.spacing(8)};
|
|
`;
|
|
|
|
const StyledActionContainer = styled.div`
|
|
align-items: center;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
justify-content: center;
|
|
width: 300px;
|
|
`;
|
|
|
|
const Settings = () => {
|
|
const [serverBaseUrl, setServerBaseUrl] = useState('');
|
|
const [clientUrl, setClientUrl] = useState('');
|
|
const [currentClientUrl, setCurrentClientUrl] = useState('');
|
|
const [currentServerUrl, setCurrentServerUrl] = useState('');
|
|
|
|
useEffect(() => {
|
|
const getState = async () => {
|
|
const store = await chrome.storage.local.get([
|
|
'serverBaseUrl',
|
|
'clientUrl',
|
|
]);
|
|
if (isDefined(store.serverBaseUrl)) {
|
|
setServerBaseUrl(store.serverBaseUrl);
|
|
setCurrentServerUrl(store.serverBaseUrl);
|
|
} else {
|
|
setServerBaseUrl(import.meta.env.VITE_SERVER_BASE_URL);
|
|
setCurrentServerUrl(import.meta.env.VITE_SERVER_BASE_URL);
|
|
}
|
|
|
|
if (isDefined(store.clientUrl)) {
|
|
setClientUrl(store.clientUrl);
|
|
setCurrentClientUrl(store.clientUrl);
|
|
} else {
|
|
setClientUrl(import.meta.env.VITE_FRONT_BASE_URL);
|
|
setCurrentClientUrl(import.meta.env.VITE_FRONT_BASE_URL);
|
|
}
|
|
};
|
|
void getState();
|
|
}, []);
|
|
|
|
const handleSettingsChange = () => {
|
|
chrome.storage.local.set({
|
|
serverBaseUrl,
|
|
clientUrl,
|
|
navigateSidepanel: 'sidepanel',
|
|
});
|
|
clearStore();
|
|
};
|
|
|
|
const handleCloseSettings = () => {
|
|
chrome.storage.local.set({
|
|
navigateSidepanel: 'sidepanel',
|
|
});
|
|
};
|
|
|
|
return (
|
|
<StyledWrapper>
|
|
<StyledContainer>
|
|
<img src="/logo/32-32.svg" alt="twenty-logo" height={40} width={40} />
|
|
<StyledActionContainer>
|
|
<TextInput
|
|
label="Client URL"
|
|
value={clientUrl}
|
|
onChange={setClientUrl}
|
|
placeholder="My client URL"
|
|
fullWidth
|
|
/>
|
|
<TextInput
|
|
label="Server URL"
|
|
value={serverBaseUrl}
|
|
onChange={setServerBaseUrl}
|
|
placeholder="My server URL"
|
|
fullWidth
|
|
/>
|
|
<MainButton
|
|
title="Done"
|
|
disabled={
|
|
currentClientUrl === clientUrl &&
|
|
currentServerUrl === serverBaseUrl
|
|
}
|
|
variant="primary"
|
|
onClick={handleSettingsChange}
|
|
fullWidth
|
|
/>
|
|
<MainButton
|
|
title="Close"
|
|
variant="secondary"
|
|
onClick={handleCloseSettings}
|
|
fullWidth
|
|
/>
|
|
</StyledActionContainer>
|
|
</StyledContainer>
|
|
</StyledWrapper>
|
|
);
|
|
};
|
|
|
|
export default Settings;
|