From 23be6acc40623c36897c6b9a5552012ab483a01a Mon Sep 17 00:00:00 2001 From: tsng Date: Tue, 2 Apr 2024 14:55:03 +0700 Subject: [PATCH] Fix reset element logic not working properly Fixes: AFORM-4013 --- .npmrc | 4 +-- .../Alloy.ManagementSite.csproj | 8 ++++-- .../Controllers/ReactController.cs | 13 +++++---- samples/ManagementSite/Nuget.config | 28 +++++++++++++++++++ .../forms-react/src/hooks/useElement.ts | 12 ++++++-- 5 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 samples/ManagementSite/Nuget.config diff --git a/.npmrc b/.npmrc index 9205035..1dbaa4c 100644 --- a/.npmrc +++ b/.npmrc @@ -2,9 +2,9 @@ always-auth=true ; begin auth token //pkgs.dev.azure.com/EpiserverEngineering/netCore/_packaging/headless_forms_beta/npm/registry/:username=buildbot -//pkgs.dev.azure.com/EpiserverEngineering/netCore/_packaging/headless_forms_beta/npm/registry/:_password=${AZURE_TOKEN} +//pkgs.dev.azure.com/EpiserverEngineering/netCore/_packaging/headless_forms_beta/npm/registry/:_password=$AZURE_TOKEN //pkgs.dev.azure.com/EpiserverEngineering/netCore/_packaging/headless_forms_beta/npm/registry/:email=buildbot@optimizely.com //pkgs.dev.azure.com/EpiserverEngineering/netCore/_packaging/headless_forms_beta/npm/:username=[ANY_VALUE_BUT_NOT_AN_EMPTY_STRING] -//pkgs.dev.azure.com/EpiserverEngineering/netCore/_packaging/headless_forms_beta/npm/:_password=${AZURE_TOKEN} +//pkgs.dev.azure.com/EpiserverEngineering/netCore/_packaging/headless_forms_beta/npm/:_password=$AZURE_TOKEN //pkgs.dev.azure.com/EpiserverEngineering/netCore/_packaging/headless_forms_beta/npm/:email=buildbot@optimizely.com ; end auth token \ No newline at end of file diff --git a/samples/ManagementSite/Alloy.ManagementSite.csproj b/samples/ManagementSite/Alloy.ManagementSite.csproj index b2eee6b..0fcc2c7 100644 --- a/samples/ManagementSite/Alloy.ManagementSite.csproj +++ b/samples/ManagementSite/Alloy.ManagementSite.csproj @@ -4,6 +4,7 @@ NU5100;NU1803;NU1605;NU1504; 12.23.0 12.20.1 + 5.8.0 @@ -11,7 +12,8 @@ - + + @@ -20,7 +22,7 @@ - + @@ -32,7 +34,7 @@ - + diff --git a/samples/ManagementSite/Controllers/ReactController.cs b/samples/ManagementSite/Controllers/ReactController.cs index a20956b..ea74ae3 100644 --- a/samples/ManagementSite/Controllers/ReactController.cs +++ b/samples/ManagementSite/Controllers/ReactController.cs @@ -36,12 +36,15 @@ public async Task GetFormInPageByUrl(string url) var pageModel = new PageModel(); var contentHeadless = await _contentRepositoryInteApi.GetAsync(key, content.LanguageBranch()); - pageModel.Title = contentHeadless.DisplayName; - pageModel.PageUrl = UrlResolver.Current.GetUrl(content.ContentLink); - - if (contentHeadless.Properties.ContainsKey("MainContentArea")) + if (contentHeadless is not null) { - pageModel.Childrens.AddRange(contentHeadless.Properties["MainContentArea"] as IList); + pageModel.Title = contentHeadless.DisplayName; + pageModel.PageUrl = UrlResolver.Current.GetUrl(content.ContentLink); + + if (contentHeadless.Properties.ContainsKey("MainContentArea")) + { + pageModel.Childrens.AddRange(contentHeadless.Properties["MainContentArea"] as IList); + } } return Ok(pageModel); diff --git a/samples/ManagementSite/Nuget.config b/samples/ManagementSite/Nuget.config new file mode 100644 index 0000000..23886a5 --- /dev/null +++ b/samples/ManagementSite/Nuget.config @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/@episerver/forms-react/src/hooks/useElement.ts b/src/@episerver/forms-react/src/hooks/useElement.ts index 5c925cc..491750c 100644 --- a/src/@episerver/forms-react/src/hooks/useElement.ts +++ b/src/@episerver/forms-react/src/hooks/useElement.ts @@ -74,6 +74,11 @@ export const useElement = (element: FormElementBase) => { //reset form useEffect(()=>{ if(formContext?.isReset){ + // Reset input file upload ref value + if(equals(element.contentType, "FileUploadElementBlock") && elementRef.current){ + elementRef.current.value = null; + } + //update form state dispatchFuncs.resetFormDone(); } @@ -192,9 +197,12 @@ export const useElement = (element: FormElementBase) => { e.preventDefault() const form = formContext?.formContainer ?? {} as FormContainer if (shouldResetForm(form.properties.resetConfirmationMessage)) { - dispatchFuncs.resetForm(form); + // Remove data from form storage + formCache.remove(FormConstants.FormCurrentStep + form.key); + formCache.remove(form.key); - formCache.set(FormConstants.FormCurrentStep + form.key, 0); + // Dispatch func to reset Form state + dispatchFuncs.resetForm(form); dispatchFuncs.updateCurrentStepIndex(0); var attachedContentLink = form.steps[0]?.formStep?.properties?.attachedContentLink;