chore: setting initialstate

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2023-01-10 12:35:40 +01:00
parent fc73e5aee8
commit d1deceb410
2 changed files with 10 additions and 2 deletions
@@ -59,6 +59,7 @@ export type StepperProps = {
extensions: NextFieldExtensionOptions<any, any>[];
templateName?: string;
FormProps?: FormProps;
initialState?: Record<string, JsonValue>;
onComplete: (values: Record<string, JsonValue>) => Promise<void>;
};
@@ -77,7 +78,7 @@ export const Stepper = (props: StepperProps) => {
const { steps } = useTemplateSchema(props.manifest);
const apiHolder = useApiHolder();
const [activeStep, setActiveStep] = useState(0);
const [formState, setFormState] = useFormDataFromQuery();
const [formState, setFormState] = useFormDataFromQuery(props.initialState);
const [errors, setErrors] = useState<
undefined | Record<string, FieldValidation>
@@ -14,6 +14,7 @@
* limitations under the License.
*/
import { JsonValue } from '@backstage/types';
import qs from 'qs';
import { useState } from 'react';
@@ -21,8 +22,14 @@ import { useState } from 'react';
* This hook is used to get the formData from the query string.
* @alpha
*/
export const useFormDataFromQuery = () => {
export const useFormDataFromQuery = (
initialState?: Record<string, JsonValue>,
) => {
return useState<Record<string, any>>(() => {
if (initialState) {
return initialState;
}
const query = qs.parse(window.location.search, {
ignoreQueryPrefix: true,
});