Skip to content
Open
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
2 changes: 2 additions & 0 deletions example/src/features/SubmitHandling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const SubmitHandling = (e: any) => {

useEffect(() => {
setFormInstance(form);
console.log('formInstance', formInstance, form)
}, [form]);

useEffect(() => {
Expand Down Expand Up @@ -75,6 +76,7 @@ const SubmitHandling = (e: any) => {

const customHandling = (event: any) => {
event.preventDefault();
console.log('HERE', formInstance)
if (!isFormSubmitting && formInstance) {
setFormSubmitting(true);
formInstance.submit(
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@
"postcss": "8.4.21",
"webpack": "5.76.0"
},
"dependencies": {}
"dependencies": {},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
18 changes: 14 additions & 4 deletions src/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ function CollectForm(props: ICollectFormProps) {

const isProviderExists =
typeof dispatchFormStateUpdate === 'function' &&
typeof dispatchResponseUpdate === 'function';

typeof dispatchResponseUpdate === 'function'; // typeof dispatchFormInstanceContextUpdate === 'function';
useEffect(() => {
if (
isBrowser &&
Expand All @@ -69,11 +69,13 @@ function CollectForm(props: ICollectFormProps) {
onUpdateCallback(state);
}
isProviderExists && dispatchFormStateUpdate(state);
// isProviderExists && dispatchFormInstanceContextUpdate({qwe:1});
// console.log('tyoe of dispatchFormСontext', typeof dispatchFormСontext, '-->', typeof dispatchFormStateUpdate, '--->dispatchFormInstanceContextUpdate', typeof dispatchFormInstanceContextUpdate)
}
);

dispatchFormСontext({ type: 'FORM_MOUNTED' });

if (cname) {
form.useCname(cname);
}
Expand All @@ -83,7 +85,13 @@ function CollectForm(props: ICollectFormProps) {
}

setFormInstance(form);
dispatchFormInstanceContextUpdate(getFormInstance());

// console.log('qweqweqw',dispatchFormСontext, dispatchFormInstanceContextUpdate)
// if (typeof dispatchFormInstanceContextUpdate === 'function') {
dispatchFormInstanceContextUpdate(getFormInstance());
// } else {
// console.log('ELSE', dispatchFormInstanceContextUpdate, dispatchResponseUpdate, dispatchFormStateUpdate, getFormInstance())
// }
}

return () => {
Expand All @@ -102,6 +110,7 @@ function CollectForm(props: ICollectFormProps) {

const submitHandler = (e: React.SyntheticEvent) => {
e.preventDefault();
console.log('Default submitHandler SDK', submitHandler)
const form: IVGSCollectForm = getFormInstance();

if (!form) {
Expand Down Expand Up @@ -145,6 +154,7 @@ function CollectForm(props: ICollectFormProps) {
return (
<form
onSubmit={(event) => (onCustomSubmit || submitHandler)(event)}
// onSubmit={(event) => {submitHandler(event)}}
>
{children}
</form>
Expand Down
16 changes: 9 additions & 7 deletions src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ export const GlobalSubmitContext = createContext<GlobalSubmitContext>(initialSta
export const DispatchSubmitContext = createContext({} as Dispatch<any>);
export const GlobalStateContext = createContext<GlobalStateContext>(initialState);
export const DispatchStateContext = createContext({} as Dispatch<any>);
export const GlobalFormInstanceContext = createContext<GlobalFormInstanceContext>(false);
export const GlobalFormInstanceContext = createContext<GlobalFormInstanceContext>(null);
export const DispatchFormInstanceContext = createContext({} as Dispatch<any>);


export const GlobalStateProvider = ({ children }: any) => {
const [state, dispatch] = useReducer(
(_state: GlobalStateContext, newValue: any) => {
Expand All @@ -31,10 +30,11 @@ export const GlobalStateProvider = ({ children }: any) => {
);

const [formInstance, dispatchFormInstance] = useReducer(
(_form: any, formInstance: any) => {
(_form: GlobalFormInstanceContext, formInstance: any) => {
console.log('--->', _form, formInstance)
return formInstance ? formInstance : null
},
null
initialState
);

const memoState = useMemo(
Expand Down Expand Up @@ -79,9 +79,11 @@ export const useVGSCollectResponse = () => [
useContext(GlobalSubmitContext)
];

export const useVGSCollectFormInstance = () => [
useContext(GlobalFormInstanceContext)
];
export const useVGSCollectFormInstance = () => {
return [
useContext(GlobalFormInstanceContext)
];
}

export const VGSCollectProvider = ({ children }: any) => {
return <GlobalStateProvider>{children}</GlobalStateProvider>;
Expand Down