import { Button, TextField } from '@mui/material'; import { styled } from '@mui/material/styles'; import { useTranslation } from 'react-i18next'; import { SupportedStorageServices } from '@services/types'; 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 GitTokenForm(props: { children?: React.JSX.Element | Array; storageService: SupportedStorageServices; }): React.JSX.Element { const { children, storageService } = props; const { t } = useTranslation(); const [onClickLogin, onClickLogout] = useAuth(storageService); useGetGithubUserInfoOnLoad(); const { token, userName, email, branch, isLoggedIn, isReady, tokenSetter, userNameSetter, emailSetter, branchSetter } = useTokenForm(storageService); if (!isReady) { return
{t('Loading')}
; } return ( <> {!isLoggedIn && ( {t('AddWorkspace.LogoutToGetStorageServiceToken')} )} {isLoggedIn && {t('Preference.Logout')}} ) => { tokenSetter(event.target.value); }} value={token} data-testid={`${storageService}-token-input`} /> ) => { userNameSetter(event.target.value); }} value={userName} data-testid={`${storageService}-userName-input`} /> ) => { emailSetter(event.target.value); }} value={email} data-testid={`${storageService}-email-input`} /> ) => { branchSetter(event.target.value); }} value={branch} data-testid={`${storageService}-branch-input`} /> {children} ); }