diff --git a/frontend/src/component/api-token/ApiTokenCreate/ApiTokenCreate.tsx b/frontend/src/component/api-token/ApiTokenCreate/ApiTokenCreate.tsx index 0041dd4c5d..96db6120d6 100644 --- a/frontend/src/component/api-token/ApiTokenCreate/ApiTokenCreate.tsx +++ b/frontend/src/component/api-token/ApiTokenCreate/ApiTokenCreate.tsx @@ -42,13 +42,14 @@ const ApiTokenCreate = ({ const { environments } = useEnvironments(); useEffect(() => { - if(environments && data.type === TYPE_CLIENT && !data.environment) { + if(environments && environments.length > 0 && data.type === TYPE_CLIENT && !data.environment) { setData({...data, environment: environments[0].name}) } }, [data, environments]); const clear = () => { - setData({...INITIAL_DATA}); + const environment = environments && environments.length > 0 ? environments[0].name : undefined; + setData({...INITIAL_DATA, environment }); setError({}); }