Skip to content

Commit

Permalink
Fix reset element logic not working properly
Browse files Browse the repository at this point in the history
Fixes: AFORM-4013
  • Loading branch information
Tson-optimizely committed Apr 2, 2024
1 parent 2596edd commit 23be6ac
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -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=[email protected]
//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=[email protected]
; end auth token
8 changes: 5 additions & 3 deletions samples/ManagementSite/Alloy.ManagementSite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
<NoWarn>NU5100;NU1803;NU1605;NU1504;</NoWarn>
<CmsUIVersion>12.23.0</CmsUIVersion>
<CmsCoreVersion>12.20.1</CmsCoreVersion>
<FormVersion>5.8.0</FormVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EPiServer.CMS.AspNetCore" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.AspNetCore.HtmlHelpers" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.AspNetCore.MVC" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.AspNetCore.Routing" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.AspNetCore.Templating" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.Core" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.Core" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.Forms" Version="$(FormVersion)" />
<PackageReference Include="EPiServer.Framework" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.Framework.AspNetCore" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.Hosting" Version="$(CmsCoreVersion)" />
Expand All @@ -20,7 +22,7 @@
<PackageReference Include="EPiServer.CMS.UI.Core" Version="$(CmsUIVersion)" />
<PackageReference Include="EPiServer.CMS.UI.VisitorGroups" Version="$(CmsUIVersion)" />
<PackageReference Include="EPiServer.CMS.UI.AspNetIdentity" Version="$(CmsUIVersion)" />
<PackageReference Include="EPiServer.ImageLibrary.ImageSharp" Version="2.0.1" />
<PackageReference Include="EPiServer.ImageLibrary.ImageSharp" Version="2.0.1" />
</ItemGroup>
<ItemGroup Label="HeadlessForm">
<PackageReference Include="Optimizely.Headless.Form.Service" Version="0.1.0--inte-256" />
Expand All @@ -32,7 +34,7 @@
<PackageReference Include="EPiServer.ContentDefinitionsApi" Version="3.3.0" />
<PackageReference Include="EPiServer.ContentDeliveryApi.Cms" Version="3.9.1" />
<PackageReference Include="EPiServer.OpenIDConnect" Version="3.3.0" />
<PackageReference Include="EPiServer.CloudPlatform.Cms" Version="1.1.0" />
<PackageReference Include="EPiServer.CloudPlatform.Cms" Version="1.2.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
Expand Down
13 changes: 8 additions & 5 deletions samples/ManagementSite/Controllers/ReactController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ public async Task<IActionResult> 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<IContentComponent>);
pageModel.Title = contentHeadless.DisplayName;
pageModel.PageUrl = UrlResolver.Current.GetUrl(content.ContentLink);

if (contentHeadless.Properties.ContainsKey("MainContentArea"))
{
pageModel.Childrens.AddRange(contentHeadless.Properties["MainContentArea"] as IList<IContentComponent>);
}
}

return Ok(pageModel);
Expand Down
28 changes: 28 additions & 0 deletions samples/ManagementSite/Nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="optimizely" value="https://api.nuget.optimizely.com/v3/index.json" />
<add key="github.episerver" value="https://nuget.pkg.github.com/episerver/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
<packageSource key="optimizely">
<package pattern="EPiServer.*" />
<package pattern="Optimizely.*" />
</packageSource>
<packageSource key="github.episerver">
<package pattern="Optimizely.Headless.Form.*" />
<package pattern="Optimizely.Cms.*" />
</packageSource>
</packageSourceMapping>
<packageSourceCredentials>
<github.episerver>
<add key="Username" value="Ignored" />
<add key="ClearTextPassword" value="%GitHubEpiserverPAT%" />
</github.episerver>
</packageSourceCredentials>
</configuration>
12 changes: 10 additions & 2 deletions src/@episerver/forms-react/src/hooks/useElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<number>(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;
Expand Down

0 comments on commit 23be6ac

Please sign in to comment.