fix: template literal type is not working properly

This commit is contained in:
林一二 2021-08-07 20:44:49 +08:00
parent e8b36edd1c
commit 41f064fa9c
2 changed files with 7 additions and 3 deletions

View file

@ -7,6 +7,7 @@ import { TextField, Button } from '@material-ui/core';
import { SupportedStorageServices } from '@services/types';
import { useUserInfoObservable } from '@services/auth/hooks';
import { useAuth } from './gitTokenHooks';
import { getServiceEmailTypes, getServiceTokenTypes, getServiceUserNameTypes } from '@services/auth/interface';
const AuthingLoginButton = styled(Button)`
width: 100%;
@ -38,21 +39,21 @@ export function GitTokenForm(props: {
onChange={(event) => {
void window.service.auth.set(`${storageService}-token`, event.target.value);
}}
value={userInfo[`${storageService}-token`] ?? ''}
value={userInfo[getServiceTokenTypes(storageService)] ?? ''}
/>
<GitTokenInput
helperText={t('AddWorkspace.GitUserNameDescription')}
onChange={(event) => {
void window.service.auth.set(`${storageService}-userName`, event.target.value);
}}
value={userInfo[`${storageService}-userName`] ?? ''}
value={userInfo[getServiceUserNameTypes(storageService)] ?? ''}
/>
<GitTokenInput
helperText={t('AddWorkspace.GitEmailDescription')}
onChange={(event) => {
void window.service.auth.set(`${storageService}-email`, event.target.value);
}}
value={userInfo[`${storageService}-email`] ?? ''}
value={userInfo[getServiceEmailTypes(storageService)] ?? ''}
/>
{children}
</>

View file

@ -6,14 +6,17 @@ import { IGitUserInfos } from '@services/git/interface';
import { SupportedStorageServices } from '@services/types';
export type ServiceTokenTypes = `${SupportedStorageServices}-token`;
export const getServiceTokenTypes = (serviceType: SupportedStorageServices): ServiceTokenTypes => `${serviceType}-token`;
/** Git Login: token */
type TokenRecord = Record<ServiceTokenTypes, string>;
export type ServiceUserNameTypes = `${SupportedStorageServices}-userName`;
export const getServiceUserNameTypes = (serviceType: SupportedStorageServices): ServiceUserNameTypes => `${serviceType}-userName`;
/** Git Login: username , this is also used to filter user's repo when searching repo */
type UserNameRecord = Record<ServiceUserNameTypes, string>;
export type ServiceEmailTypes = `${SupportedStorageServices}-email`;
export const getServiceEmailTypes = (serviceType: SupportedStorageServices): ServiceEmailTypes => `${serviceType}-email`;
/** Git push: Git commit message email, you may use different email for different storage service */
type EmailRecord = Record<ServiceEmailTypes, string>;