From adf64f0a4cc2a959378e807f7c94ae04b1f4e28e Mon Sep 17 00:00:00 2001 From: brendanlaschke Date: Mon, 29 Apr 2024 10:39:40 +0200 Subject: [PATCH] Add known sources dropdown to api docs (#5204) closes #5156 --- .../twenty-docs/src/components/token-form.css | 6 ++ .../twenty-docs/src/components/token-form.tsx | 69 +++++++++++++------ 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/packages/twenty-docs/src/components/token-form.css b/packages/twenty-docs/src/components/token-form.css index 2530a5c9c9..48016ae3e0 100644 --- a/packages/twenty-docs/src/components/token-form.css +++ b/packages/twenty-docs/src/components/token-form.css @@ -7,6 +7,7 @@ padding: 0px 8px; background: var(--ifm-color-secondary-contrast-background); z-index: 2; + display: flex; } .form { @@ -15,6 +16,7 @@ gap: 10px; width: 50%; margin-left: auto; + flex: 0.7; } .link { @@ -42,6 +44,10 @@ height: 32px; } +.input[disabled] { + color: rgb(153, 153, 153) +} + [data-theme='dark'] .input { background-color: #16233f; } diff --git a/packages/twenty-docs/src/components/token-form.tsx b/packages/twenty-docs/src/components/token-form.tsx index 3c59ba0969..4acf4e8236 100644 --- a/packages/twenty-docs/src/components/token-form.tsx +++ b/packages/twenty-docs/src/components/token-form.tsx @@ -28,6 +28,10 @@ const TokenForm = ({ const history = useHistory(); const location = useLocation(); const [isLoading, setIsLoading] = useState(false); + const [locationSetting, setLocationSetting] = useState( + parseJson(localStorage.getItem('baseUrl'))?.locationSetting ?? + 'production', + ); const [baseUrl, setBaseUrl] = useState( parseJson(localStorage.getItem('baseUrl'))?.baseUrl ?? 'https://api.twenty.com', @@ -49,13 +53,24 @@ const TokenForm = ({ await submitToken(event.target.value); }; - const updateBaseUrl = (baseUrl: string) => { - const url = baseUrl?.endsWith('/') + const updateBaseUrl = (baseUrl: string, locationSetting: string) => { + let url: string; + if (locationSetting === 'production') { + url = 'https://api.twenty.com'; + } else if (locationSetting === 'demo') { + url = 'https://api-demo.twenty.com'; + } else if (locationSetting === 'localhost') { + url = 'http://localhost:3000'; + } else { + url = baseUrl?.endsWith('/') ? baseUrl.substring(0, baseUrl.length - 1) - : baseUrl; + : baseUrl + } + setBaseUrl(url); + setLocationSetting(locationSetting); submitBaseUrl?.(url); - localStorage.setItem('baseUrl', JSON.stringify({ baseUrl: url })); + localStorage.setItem('baseUrl', JSON.stringify({ baseUrl: url, locationSetting })); }; const validateToken = (openApiJson) => { @@ -93,7 +108,7 @@ const TokenForm = ({ useEffect(() => { (async () => { - updateBaseUrl(baseUrl); + updateBaseUrl(baseUrl, locationSetting); await submitToken(token); })(); }, []); @@ -114,7 +129,35 @@ const TokenForm = ({ Back - +
+ +
+
+
+ +
+ updateBaseUrl(event.target.value, locationSetting)} + onBlur={() => submitToken(token)} + /> +
@@ -128,20 +171,6 @@ const TokenForm = ({ onChange={updateToken} />
-
-
- -
- updateBaseUrl(event.target.value)} - onBlur={() => submitToken(token)} - /> -