Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Form.tsx to form-react sdk #34

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions samples/sample-react-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './App.css';
import { useFetch } from './hooks/useFetch';
import Form from './components/Form';
import { Form } from '@optimizely/forms-react';
import { extractParams } from './helpers/urlHelper';

function App() {
Expand All @@ -16,9 +16,10 @@ function App() {
<h1>{pageData.title}</h1>
{pageData.childrens.map((c: any) => (
<Form
key={c.reference.key}
formKey={c.reference.key}
key={c.reference.key}
language={language ?? "en"}/>
language={language ?? "en"}
baseUrl={process.env.REACT_APP_HEADLESS_FORM_BASE_URL}/>
))}
</>
)}
Expand Down
17 changes: 0 additions & 17 deletions samples/sample-react-app/src/components/Form.tsx

This file was deleted.

29 changes: 29 additions & 0 deletions src/@optimizely/forms-react/src/Form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from "react";
import { FormContainerBlock } from "./components/FormContainerBlock";
import { UseFormLoaderProps, useFormLoader } from "./hooks/useFormLoader";
import "./Form.scss"

interface FormProps {
/**
* The form key that identifies the form
*/
formKey: string,
/**
* The code of the form language
*/
language: string | undefined,
/**
* The base url of Headless Form API
*/
baseUrl: string | undefined
}

export const Form = ({formKey, language, baseUrl}: FormProps) => {
const {data: formData } = useFormLoader({ formKey, language, baseUrl } as UseFormLoaderProps)

return (
<>
{formData && <FormContainerBlock form={formData} key={formData.key} />}
</>
);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { useRef } from "react";
import { FormContainer, StepBuilder } from "@optimizely/forms-sdk";
import { RenderElementInStep } from "./components/RenderElementInStep";
import { SubmitButtonType } from "./models/SubmitButtonType";
import "./FormStyle.scss";
import { FormProvider } from "./context/FormProvider";
import { initState } from "./context/initState";
import { RenderElementInStep } from "./RenderElementInStep";
import { SubmitButtonType } from "../models/SubmitButtonType";
import { FormProvider } from "../context/FormProvider";
import { initState } from "../context/initState";

export interface FormContainerProps {
form: FormContainer
Expand Down
2 changes: 1 addition & 1 deletion src/@optimizely/forms-react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./FormContainerBlock"
export * from "./Form";