From 35f7661f45791f616756c9092983bfc30cceedfd Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Fri, 9 May 2025 07:25:31 +0700 Subject: [PATCH] fixed PUT of env_vars in Applications should not stringify (#513) --- src/api/types.ts | 2 +- .../internal/views/applications/form.tsx | 26 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/api/types.ts b/src/api/types.ts index dc25bcc..1f71b40 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -338,7 +338,7 @@ export interface Application { fallback_speech_recognizer_vendor: null | string; fallback_speech_recognizer_language: null | string; fallback_speech_recognizer_label: null | string; - env_vars: null | string; + env_vars: null | Record; } export interface PhoneNumber { diff --git a/src/containers/internal/views/applications/form.tsx b/src/containers/internal/views/applications/form.tsx index 934a922..aee2001 100644 --- a/src/containers/internal/views/applications/form.tsx +++ b/src/containers/internal/views/applications/form.tsx @@ -207,13 +207,23 @@ export const ApplicationForm = ({ application }: ApplicationFormProps) => { record_all_calls: recordAllCalls ? 1 : 0, use_for_fallback_speech: useForFallbackSpeech ? 1 : 0, env_vars: envVars - ? JSON.stringify( - Object.keys(envVars).reduce( - (acc, key) => - appEnv && appEnv[key] ? { ...acc, [key]: envVars[key] } : acc, - {}, - ), - ) + ? Object.keys(envVars).reduce((acc, key) => { + const value = envVars[key]; + // Keep only values that: + // 1. Are defined in appEnv schema + // 2. Are not empty strings, undefined, or null + // 3. For booleans and numbers, keep them even if they're false or 0 + if ( + appEnv && + appEnv[key] && + (value === false || + value === 0 || + (value !== "" && value != null)) + ) { + return { ...acc, [key]: value }; + } + return acc; + }, {}) : null, fallback_speech_synthesis_vendor: useForFallbackSpeech ? fallbackSpeechSynthsisVendor || null @@ -532,7 +542,7 @@ export const ApplicationForm = ({ application }: ApplicationFormProps) => { ); } if (application.data.env_vars) { - setEnvVars(JSON.parse(application.data.env_vars)); + setEnvVars(application.data.env_vars); } } }, [application]);