1
0
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:
David Leek 2025-05-08 09:20:19 +02:00 committed by GitHub
parent dac5a5e596
commit d15456a76a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 29 additions and 29 deletions

View File

@ -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
/>
</>

View File

@ -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,

View File

@ -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}
/>

View File

@ -164,7 +164,7 @@ export const EnvironmentCloneModal = ({
});
const getApiTokenCreatePayload = (): IApiTokenCreate => ({
username: `${name}_token`,
tokenName: `${name}_token`,
type: 'CLIENT',
environment: name,
projects: tokenProjects,

View File

@ -217,7 +217,7 @@ export const GenerateApiKey = ({
environment,
type: sdkType,
projects: [project],
username: `api-key-${project}-${environment}`,
tokenName: `api-key-${project}-${environment}`,
},
project,
);

View File

@ -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}
/>

View File

@ -1,7 +1,7 @@
import useAPI from '../useApi/useApi';
export interface IApiTokenCreate {
username: string;
tokenName: string;
type: string;
environment?: string;
projects: string[];

View File

@ -1,7 +1,7 @@
import useAPI from '../useApi/useApi';
export interface IApiTokenCreate {
username: string;
tokenName: string;
type: string;
environment?: string;
projects: string[];