From 5f257d84b64a83b56332ed0b1f31901c2818a0f2 Mon Sep 17 00:00:00 2001 From: Anbraten Date: Wed, 8 Nov 2023 19:33:37 +0100 Subject: [PATCH] fix: correct function env settings --- .../lib/pages/function/FunctionSettings.tsx | 66 +++++++++++-------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/packages/dashboard/lib/pages/function/FunctionSettings.tsx b/packages/dashboard/lib/pages/function/FunctionSettings.tsx index a4fa5821e..bf0ba2a89 100644 --- a/packages/dashboard/lib/pages/function/FunctionSettings.tsx +++ b/packages/dashboard/lib/pages/function/FunctionSettings.tsx @@ -390,22 +390,30 @@ const FunctionSettings = ({ func, refetch }: FunctionSettingsProps) => { initialValues={{ env: func?.env || {}, }} - onSubmit={async ({ env }) => { + onSubmit={async ({ env, envKey, envValue }) => { if (!func) { return; } + const newEnv = Object.entries(env).reduce( + (acc, [key, value]) => [...acc, { key, value }], + [] as { key: string; value: string }[], + ); + + if (envKey && envValue) { + newEnv.push({ key: envKey, value: envValue }); + } + await updateFunction.mutateAsync({ functionId: func.id, - env: Object.entries(env).reduce( - (acc, [key, value]) => [...acc, { key, value }], - [] as { key: string; value: string }[], - ), + env: newEnv, }); }} - onSubmitSuccess={async () => { + onSubmitSuccess={async (_, form) => { toast.success('Function environment variables updated successfully.'); await refetch(); + form.change('envKey', ''); + form.change('envValue', ''); }} > {({ values, form }) => ( @@ -421,6 +429,29 @@ const FunctionSettings = ({ func, refetch }: FunctionSettingsProps) => { } >
+ {Object.entries(values.env).map(([key, value], index) => { + return ( +
+ + + +
+ ); + })}
{ {t('env.add')}
- {Object.entries(values.env).map(([key, value], index) => { - return ( -
- - - -
- ); - })}