From 41f064fa9c6b6d5cff2baa8457e975bc2c2b9a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=80=E4=BA=8C?= Date: Sat, 7 Aug 2021 20:44:49 +0800 Subject: [PATCH] fix: template literal type is not working properly --- src/components/TokenForm/GitTokenForm.tsx | 7 ++++--- src/services/auth/interface.ts | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/TokenForm/GitTokenForm.tsx b/src/components/TokenForm/GitTokenForm.tsx index 8d35b52c..5878bc3c 100644 --- a/src/components/TokenForm/GitTokenForm.tsx +++ b/src/components/TokenForm/GitTokenForm.tsx @@ -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)] ?? ''} /> { void window.service.auth.set(`${storageService}-userName`, event.target.value); }} - value={userInfo[`${storageService}-userName`] ?? ''} + value={userInfo[getServiceUserNameTypes(storageService)] ?? ''} /> { void window.service.auth.set(`${storageService}-email`, event.target.value); }} - value={userInfo[`${storageService}-email`] ?? ''} + value={userInfo[getServiceEmailTypes(storageService)] ?? ''} /> {children} diff --git a/src/services/auth/interface.ts b/src/services/auth/interface.ts index 480c9004..f81a30a8 100644 --- a/src/services/auth/interface.ts +++ b/src/services/auth/interface.ts @@ -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; 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; 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;