fixed PUT of env_vars in Applications should not stringify (#513)

This commit is contained in:
Hoan Luu Huu
2025-05-09 07:25:31 +07:00
committed by GitHub
parent 0a91bb09a5
commit 35f7661f45
2 changed files with 19 additions and 9 deletions

View File

@@ -338,7 +338,7 @@ export interface Application {
fallback_speech_recognizer_vendor: null | string; fallback_speech_recognizer_vendor: null | string;
fallback_speech_recognizer_language: null | string; fallback_speech_recognizer_language: null | string;
fallback_speech_recognizer_label: null | string; fallback_speech_recognizer_label: null | string;
env_vars: null | string; env_vars: null | Record<string, string | number | boolean>;
} }
export interface PhoneNumber { export interface PhoneNumber {

View File

@@ -207,13 +207,23 @@ export const ApplicationForm = ({ application }: ApplicationFormProps) => {
record_all_calls: recordAllCalls ? 1 : 0, record_all_calls: recordAllCalls ? 1 : 0,
use_for_fallback_speech: useForFallbackSpeech ? 1 : 0, use_for_fallback_speech: useForFallbackSpeech ? 1 : 0,
env_vars: envVars env_vars: envVars
? JSON.stringify( ? Object.keys(envVars).reduce((acc, key) => {
Object.keys(envVars).reduce( const value = envVars[key];
(acc, key) => // Keep only values that:
appEnv && appEnv[key] ? { ...acc, [key]: envVars[key] } : acc, // 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, : null,
fallback_speech_synthesis_vendor: useForFallbackSpeech fallback_speech_synthesis_vendor: useForFallbackSpeech
? fallbackSpeechSynthsisVendor || null ? fallbackSpeechSynthsisVendor || null
@@ -532,7 +542,7 @@ export const ApplicationForm = ({ application }: ApplicationFormProps) => {
); );
} }
if (application.data.env_vars) { if (application.data.env_vars) {
setEnvVars(JSON.parse(application.data.env_vars)); setEnvVars(application.data.env_vars);
} }
} }
}, [application]); }, [application]);