import React, { useState, useRef } from 'react';
import PropTypes from 'prop-types';
import { useI18nContext } from '../../../hooks/useI18nContext';
import {
AlignItems,
DISPLAY,
BorderColor,
BLOCK_SIZES,
FLEX_DIRECTION,
} from '../../../helpers/constants/design-system';
import { Text } from '../../component-library';
import JwtDropdown from '../jwt-dropdown';
import Button from '../../ui/button';
import Box from '../../ui/box';
const JwtUrlForm = (props) => {
const t = useI18nContext();
const inputRef = useRef();
const [addNewTokenClicked, setAddNewTokenClicked] = useState(false);
const [fileTooBigError, setFileTooBigError] = useState();
const renderJWTInput = () => {
const showAddNewToken = addNewTokenClicked;
const showJwtDropdown = props.jwtList.length >= 1;
return (
{showJwtDropdown && (
{
props.onJwtChange(value);
setFileTooBigError(false);
}}
/>
)}
{showJwtDropdown && !showAddNewToken && (
{t('or')}
)}
{(!showJwtDropdown || showAddNewToken) && (
{props.jwtInputText}
{fileTooBigError && (
{t('fileTooBig')}
)}
)}
);
};
const renderAPIURLInput = () => {
return (
{props.urlInputText}
{
props.onUrlChange(e.target.value);
}}
value={props.apiUrl}
/>
);
};
return (
{renderJWTInput()}
{renderAPIURLInput()}
);
};
JwtUrlForm.propTypes = {
jwtList: PropTypes.array,
currentJwt: PropTypes.string,
onJwtChange: PropTypes.func,
jwtInputText: PropTypes.string,
apiUrl: PropTypes.string,
urlInputText: PropTypes.string,
onUrlChange: PropTypes.func,
};
export default JwtUrlForm;