Skip to content

Commit

Permalink
[CQ-4347128] addthankyoumessage & thankyoupage post submit
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit Kumar authored and Amit Kumar committed Aug 29, 2022
1 parent 09b5cf9 commit fbb5523
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/archetype/ui.frontend.react.forms.af/src/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {AdaptiveForm} from "@aemforms/af-react-renderer";
import {mappings} from "@aemforms/af-react-components";
import useEditorEvents from "./hooks/useEditorEvents";
import ReactDOM from "react-dom";
import {Action} from "@aemforms/af-core";
//@ts-ignore
import {Provider as Spectrum3Provider, defaultTheme} from '@adobe/react-spectrum'

Expand Down Expand Up @@ -42,13 +43,22 @@ const Form = (props: any) => {
setForm(JSON.stringify(json.afModelDefinition))
}
}
const onSubmit= (action: Action) => {
const thankyouPage = action?.payload?.redirectUrl;
const thankYouMessage = action?.payload?.thankYouMessage;
if(thankyouPage){
window.location.replace(thankyouPage);
}else if(thankYouMessage){
alert(thankYouMessage);
}
};
useEffect(() => {
fetchForm()
}, [state]);
if (form != "") {
const element = document.querySelector(".cmp-formcontainer__content")
const retVal = (<Spectrum3Provider theme={defaultTheme}>
<AdaptiveForm formJson={JSON.parse(form)} mappings={mappings} />
<AdaptiveForm formJson={JSON.parse(form)} mappings={mappings} onSubmit={onSubmit}/>
</Spectrum3Provider>)
return ReactDOM.createPortal(retVal, element)
}
Expand Down

0 comments on commit fbb5523

Please sign in to comment.