Skip to content

Commit

Permalink
CQ-4343453 minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
barshatr committed Jun 21, 2022
1 parent 714ce0d commit f967c1b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
cq:lastModifiedBy="admin"
cq:templateType="/conf/${appId}/settings/wcm/template-types/af-page-v2"
jcr:primaryType="cq:PageContent"
jcr:title="${appId} - Blank With Core Components"
jcr:title="Blank With Core Components"
status="enabled"/>
</jcr:root>
30 changes: 25 additions & 5 deletions src/main/archetype/ui.frontend.react.forms.af/src/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ import ReactDOM from "react-dom";
//@ts-ignore
import {Provider as Spectrum3Provider, defaultTheme} from '@adobe/react-spectrum'

const base64url = (s: any) => {
var to64url = btoa(s);
// Replace non-url compatible chars with base64url standard chars and remove leading =
return to64url.replace(/\+/g, '_').replace(/\//g, '-').replace(/=+${symbol_dollar}/g, '');
}


export const getId = () => {
let id = ""
if (!process.env.FORMPATH) {
debugger;
const parent = document.querySelector(".cmp-formcontainer")
id = parent.getAttribute("data-form-id")
} else {
id = base64url(process.env.FORMPATH)
}
return id;
}

const getForm = async (id: string) => {
const resp = await fetch(`/adobe/forms/af/v1/${symbol_dollar}{id}`)
Expand All @@ -14,21 +32,23 @@ const getForm = async (id: string) => {
}

const Form = (props: any) => {
const {id} = props;
const [form, setForm] = useState("")
const [state, setState] = useEditorEvents()
const fetchForm = async () => {
const json:any = await getForm(id);
setForm(JSON.stringify(json.afModelDefinition))
let id = getId();
if (id) {
const json:any = await getForm(id);
setForm(JSON.stringify(json.afModelDefinition))
}
}
useEffect(() => {
fetchForm()
}, [state]);
if (form != "") {
const element = document.querySelector(".cmp-formcontainer__content")
const retVal = (<Spectrum3Provider theme={defaultTheme}>
<AdaptiveForm formJson={JSON.parse(form)} mappings={mappings} />
</Spectrum3Provider>)
<AdaptiveForm formJson={JSON.parse(form)} mappings={mappings} />
</Spectrum3Provider>)
return ReactDOM.createPortal(retVal, element)
}
return null
Expand Down
21 changes: 1 addition & 20 deletions src/main/archetype/ui.frontend.react.forms.af/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,6 @@ import ReactDOM from 'react-dom';
// @ts-ignore
import AForm from './Form'

const base64url = (s: any) => {
var to64url = btoa(s);
// Replace non-url compatible chars with base64url standard chars and remove leading =
return to64url.replace(/\+/g, '_').replace(/\//g, '-').replace(/=+${symbol_dollar}/g, '');
}


const getId = () => {
let id = ""
if (!process.env.FORMPATH) {
const parent = document.querySelector(".cmp-formcontainer")
id = parent.getAttribute("data-form-id")
} else {
id = base64url(process.env.FORMPATH)
}
return id;
}


window.onload = async () => {
let div = document.getElementById("form-app");
if (!div) {
Expand All @@ -30,7 +11,7 @@ window.onload = async () => {
document.body.appendChild(div)
}
ReactDOM.render(
<AForm id={getId()}/>,
<AForm/>,
div
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ module.exports = {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
clean: true,
//sourceMapFilename: `forms-react-components/resources/[name].map[ext]` uncomment for debugging
//sourceMapFilename: `clientlib-forms-react/resources/[name].map[ext]` // uncomment for debugging
}
};

0 comments on commit f967c1b

Please sign in to comment.