Skip to content

Commit

Permalink
fix: added a few use client and if provider is not used asContainer, …
Browse files Browse the repository at this point in the history
…the consumer needs to create a container themself
  • Loading branch information
pksorensen committed Apr 19, 2024
1 parent 8d872c8 commit 005f5fe
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/core/src/components/error-popup/ErrorPopup.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use client";
import React, { useState, useEffect } from 'react';
import { useQuickForm } from "../../state/QuickFormContext";
import { quickformtokens } from '../../style/quickFormTokensDefinition';
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/components/paragraph/Paragraph.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use client";
import { ReactNode } from "react";
import React from "react";
import { quickformtokens } from "../../style/quickFormTokensDefinition";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use client";
import React, { useEffect, useRef, useState } from 'react';
import { useQuickForm } from '../../../state/QuickFormContext';
import { Button } from '../../button/Button';
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/state/QuickFormContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface IQuickFormContext {
isFirstQuestionInCurrentSlide: (questionLogicalName: string) => boolean;
getCurrentSlide: () => SlideModel;
onSubmitAsync: (formdata: any) => Promise<string>;
cssVariables: { [key: string]: string };
}

export const QuickFormContext = React.createContext<IQuickFormContext>(
Expand All @@ -33,6 +34,7 @@ export const QuickFormContext = React.createContext<IQuickFormContext>(
{ questions: [], rows: [], isAnswered: false, addQuestion: () => ({ type: "question", ref: "" }) }
),
onSubmitAsync: async (formdata) => { return "" },
cssVariables: {}
}
);

Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/state/QuickformProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { kbaQuickFormTokens } from "../style/kbaQuickFormTokens";
import { isFirstQInCurrentSlide } from "../utils/isFirstQuestionInSlide";

type QuickFormProviderProps = {
className?:string,
children: React.ReactNode;
definition: QuickFormDefinition;
tokens?: Partial<QuickFormTokens>;
Expand All @@ -20,6 +21,7 @@ type QuickFormProviderProps = {

export const QuickFormProvider: React.FC<QuickFormProviderProps> = (
{
className,
children,
definition,
payload,
Expand Down Expand Up @@ -50,7 +52,7 @@ export const QuickFormProvider: React.FC<QuickFormProviderProps> = (
const setErrorMsg = (msg: string) => { dispatch({ type: "SET_ERROR_MSG", msg: msg }) };
const isFirstQuestionInCurrentSlide = (questionLogicalName: string) => { return isFirstQInCurrentSlide(questionLogicalName, state); }
const getCurrentSlide = () => (state.slides[state.currIdx]);

console.log("children", children);
return (
<QuickFormContext.Provider value={{
state,
Expand All @@ -64,6 +66,7 @@ export const QuickFormProvider: React.FC<QuickFormProviderProps> = (
isFirstQuestionInCurrentSlide,
getCurrentSlide,
onSubmitAsync,
cssVariables
}}>

{asContainer ? (
Expand All @@ -72,10 +75,8 @@ export const QuickFormProvider: React.FC<QuickFormProviderProps> = (
{children}
</QuickFormContainer>
) : (
<div style={cssVariables}>
<ErrorPopup message={state.errorMsg} />
{children}
</div>
children

)
}
</QuickFormContext.Provider>
Expand Down

0 comments on commit 005f5fe

Please sign in to comment.