import { Button, TextField } from '@mui/material'; import { styled } from '@mui/material/styles'; import { useTranslation } from 'react-i18next'; import { SupportedStorageServices } from '@services/types'; import { useState } from 'react'; import { useAuth, useGetGithubUserInfoOnLoad } from './gitTokenHooks'; import { useTokenForm } from './useTokenForm'; const AuthingLoginButton = styled(Button)` width: 100%; `; const GitTokenInput = styled((props: React.ComponentProps & { helperText?: string }) => )` color: ${({ theme }) => theme.palette.text.primary}; input { color: ${({ theme }) => theme.palette.text.primary}; } p, label { color: ${({ theme }) => theme.palette.text.secondary}; } `; export function CustomServerTokenForm(): React.JSX.Element { const { t } = useTranslation(); const storageService = SupportedStorageServices.testOAuth; const [onClickLogin, onClickLogout] = useAuth(storageService); useGetGithubUserInfoOnLoad(); const { token, userName, email, branch, isLoggedIn, isReady, tokenSetter, userNameSetter, emailSetter, branchSetter } = useTokenForm(storageService); // Custom server configuration const [serverUrl, serverUrlSetter] = useState('http://127.0.0.1:8888'); const [clientId, clientIdSetter] = useState('test-client-id'); // Store custom server config before OAuth login const handleLogin = async () => { // Save custom server configuration await window.service.auth.set('testOAuth-serverUrl', serverUrl); await window.service.auth.set('testOAuth-clientId', clientId); // Then trigger OAuth login await onClickLogin(); }; if (!isReady) { return
{t('Loading')}
; } return ( <> { serverUrlSetter(event.target.value); }} placeholder='http://127.0.0.1:8888' data-testid='custom-server-url-input' /> { clientIdSetter(event.target.value); }} placeholder='client-id' data-testid='custom-client-id-input' /> {!isLoggedIn && ( {t('AddWorkspace.LogoutToGetStorageServiceToken')} )} {isLoggedIn && ( {t('Preference.Logout')} )} { tokenSetter(event.target.value); }} value={token} data-testid='custom-token-input' /> { userNameSetter(event.target.value); }} value={userName} data-testid='custom-username-input' /> { emailSetter(event.target.value); }} value={email} data-testid='custom-email-input' /> { branchSetter(event.target.value); }} value={branch} placeholder='main' data-testid='custom-branch-input' /> ); }