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