mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-26 13:48:33 +02:00
chore: use tokenname instead of username in frontend for api-token creation (#9891)
This commit is contained in:
parent
dac5a5e596
commit
d15456a76a
@ -3,15 +3,15 @@ import { StyledInput, StyledInputDescription } from '../ApiTokenForm.styles';
|
||||
import type { ApiTokenFormErrorType } from '../useApiTokenForm';
|
||||
|
||||
interface ITokenInfoProps {
|
||||
username: string;
|
||||
setUsername: React.Dispatch<React.SetStateAction<string>>;
|
||||
tokenName: string;
|
||||
setTokenName: React.Dispatch<React.SetStateAction<string>>;
|
||||
|
||||
errors: { [key: string]: string };
|
||||
clearErrors: (error?: ApiTokenFormErrorType) => void;
|
||||
}
|
||||
export const TokenInfo = ({
|
||||
username,
|
||||
setUsername,
|
||||
tokenName,
|
||||
setTokenName,
|
||||
errors,
|
||||
clearErrors,
|
||||
}: ITokenInfoProps) => {
|
||||
@ -21,13 +21,13 @@ export const TokenInfo = ({
|
||||
What would you like to call this token?
|
||||
</StyledInputDescription>
|
||||
<StyledInput
|
||||
value={username}
|
||||
name='username'
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
value={tokenName}
|
||||
name='tokenName'
|
||||
onChange={(e) => setTokenName(e.target.value)}
|
||||
label='Token name'
|
||||
error={errors.username !== undefined}
|
||||
errorText={errors.username}
|
||||
onFocus={() => clearErrors('username')}
|
||||
error={errors.tokenName !== undefined}
|
||||
errorText={errors.tokenName}
|
||||
onFocus={() => clearErrors('tokenName')}
|
||||
autoFocus
|
||||
/>
|
||||
</>
|
||||
|
@ -11,7 +11,7 @@ import {
|
||||
import { useHasRootAccess } from 'hooks/useHasAccess';
|
||||
import type { SelectOption } from './TokenTypeSelector/TokenTypeSelector';
|
||||
|
||||
export type ApiTokenFormErrorType = 'username' | 'projects';
|
||||
export type ApiTokenFormErrorType = 'tokenName' | 'projects';
|
||||
export const useApiTokenForm = (project?: string) => {
|
||||
const { environments } = useEnvironments();
|
||||
const { uiConfig } = useUiConfig();
|
||||
@ -50,7 +50,7 @@ export const useApiTokenForm = (project?: string) => {
|
||||
|
||||
const firstAccessibleType = apiTokenTypes.find((t) => t.enabled)?.key;
|
||||
|
||||
const [username, setUsername] = useState('');
|
||||
const [tokenName, setTokenName] = useState('');
|
||||
const [type, setType] = useState(firstAccessibleType || TokenType.CLIENT);
|
||||
const [projects, setProjects] = useState<string[]>([
|
||||
project ? project : '*',
|
||||
@ -80,7 +80,7 @@ export const useApiTokenForm = (project?: string) => {
|
||||
};
|
||||
|
||||
const getApiTokenPayload = (): IApiTokenCreate => ({
|
||||
username,
|
||||
tokenName,
|
||||
type,
|
||||
environment,
|
||||
projects,
|
||||
@ -88,8 +88,8 @@ export const useApiTokenForm = (project?: string) => {
|
||||
|
||||
const isValid = () => {
|
||||
const newErrors: Partial<Record<ApiTokenFormErrorType, string>> = {};
|
||||
if (!username) {
|
||||
newErrors.username = 'Username is required';
|
||||
if (!tokenName) {
|
||||
newErrors.tokenName = 'Token name is required';
|
||||
}
|
||||
if (projects.length === 0) {
|
||||
newErrors.projects = 'At least one project is required';
|
||||
@ -110,12 +110,12 @@ export const useApiTokenForm = (project?: string) => {
|
||||
};
|
||||
|
||||
return {
|
||||
username,
|
||||
tokenName,
|
||||
type,
|
||||
apiTokenTypes,
|
||||
projects,
|
||||
environment,
|
||||
setUsername,
|
||||
setTokenName,
|
||||
setTokenType,
|
||||
setProjects,
|
||||
setEnvironment,
|
||||
|
@ -62,11 +62,11 @@ export const CreateApiToken = ({ modal = false }: ICreateApiTokenProps) => {
|
||||
|
||||
const {
|
||||
getApiTokenPayload,
|
||||
username,
|
||||
tokenName,
|
||||
type,
|
||||
projects,
|
||||
environment,
|
||||
setUsername,
|
||||
setTokenName,
|
||||
setTokenType,
|
||||
setProjects,
|
||||
setEnvironment,
|
||||
@ -149,8 +149,8 @@ export const CreateApiToken = ({ modal = false }: ICreateApiTokenProps) => {
|
||||
}
|
||||
>
|
||||
<TokenInfo
|
||||
username={username}
|
||||
setUsername={setUsername}
|
||||
tokenName={tokenName}
|
||||
setTokenName={setTokenName}
|
||||
errors={errors}
|
||||
clearErrors={clearErrors}
|
||||
/>
|
||||
|
@ -164,7 +164,7 @@ export const EnvironmentCloneModal = ({
|
||||
});
|
||||
|
||||
const getApiTokenCreatePayload = (): IApiTokenCreate => ({
|
||||
username: `${name}_token`,
|
||||
tokenName: `${name}_token`,
|
||||
type: 'CLIENT',
|
||||
environment: name,
|
||||
projects: tokenProjects,
|
||||
|
@ -217,7 +217,7 @@ export const GenerateApiKey = ({
|
||||
environment,
|
||||
type: sdkType,
|
||||
projects: [project],
|
||||
username: `api-key-${project}-${environment}`,
|
||||
tokenName: `api-key-${project}-${environment}`,
|
||||
},
|
||||
project,
|
||||
);
|
||||
|
@ -34,11 +34,11 @@ export const CreateProjectApiTokenForm = () => {
|
||||
|
||||
const {
|
||||
getApiTokenPayload,
|
||||
username,
|
||||
tokenName,
|
||||
type,
|
||||
apiTokenTypes,
|
||||
environment,
|
||||
setUsername,
|
||||
setTokenName,
|
||||
setTokenType,
|
||||
setEnvironment,
|
||||
isValid,
|
||||
@ -120,8 +120,8 @@ export const CreateProjectApiTokenForm = () => {
|
||||
}
|
||||
>
|
||||
<TokenInfo
|
||||
username={username}
|
||||
setUsername={setUsername}
|
||||
tokenName={tokenName}
|
||||
setTokenName={setTokenName}
|
||||
errors={errors}
|
||||
clearErrors={clearErrors}
|
||||
/>
|
||||
|
@ -1,7 +1,7 @@
|
||||
import useAPI from '../useApi/useApi';
|
||||
|
||||
export interface IApiTokenCreate {
|
||||
username: string;
|
||||
tokenName: string;
|
||||
type: string;
|
||||
environment?: string;
|
||||
projects: string[];
|
||||
|
@ -1,7 +1,7 @@
|
||||
import useAPI from '../useApi/useApi';
|
||||
|
||||
export interface IApiTokenCreate {
|
||||
username: string;
|
||||
tokenName: string;
|
||||
type: string;
|
||||
environment?: string;
|
||||
projects: string[];
|
||||
|
Loading…
Reference in New Issue
Block a user