From 5ddab3467b2b5105e7459361c8492d191ff2f53c Mon Sep 17 00:00:00 2001 From: flor Date: Thu, 12 Dec 2024 20:44:14 +0200 Subject: [PATCH 1/2] test --- example/src/features/SubmitHandling.tsx | 4 +++- package.json | 3 ++- src/Form.tsx | 18 ++++++++++++++---- src/provider.tsx | 17 +++++++++-------- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/example/src/features/SubmitHandling.tsx b/example/src/features/SubmitHandling.tsx index b29dd62..6da9c02 100644 --- a/example/src/features/SubmitHandling.tsx +++ b/example/src/features/SubmitHandling.tsx @@ -46,6 +46,7 @@ const SubmitHandling = (e: any) => { useEffect(() => { setFormInstance(form); + console.log('formInstance', formInstance) }, [form]); useEffect(() => { @@ -75,6 +76,7 @@ const SubmitHandling = (e: any) => { const customHandling = (event: any) => { event.preventDefault(); + console.log('HERE') if (!isFormSubmitting && formInstance) { setFormSubmitting(true); formInstance.submit( @@ -104,7 +106,7 @@ const SubmitHandling = (e: any) => { diff --git a/package.json b/package.json index 01d1e0e..450159c 100644 --- a/package.json +++ b/package.json @@ -78,5 +78,6 @@ "postcss": "8.4.21", "webpack": "5.76.0" }, - "dependencies": {} + "dependencies": {}, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/src/Form.tsx b/src/Form.tsx index c43b582..1a399f7 100644 --- a/src/Form.tsx +++ b/src/Form.tsx @@ -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 && @@ -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); } @@ -83,7 +85,13 @@ function CollectForm(props: ICollectFormProps) { } setFormInstance(form); - dispatchFormInstanceContextUpdate(getFormInstance()); + + // console.log('qweqweqw',dispatchFormСontext, dispatchFormInstanceContextUpdate) + // if (typeof dispatchFormInstanceContextUpdate === 'function') { + dispatchFormInstanceContextUpdate({qwe: 1}); + // } else { + // console.log('ELSE', dispatchFormInstanceContextUpdate, dispatchResponseUpdate, dispatchFormStateUpdate, getFormInstance()) + // } } return () => { @@ -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) { @@ -145,6 +154,7 @@ function CollectForm(props: ICollectFormProps) { return (
(onCustomSubmit || submitHandler)(event)} + // onSubmit={(event) => {submitHandler(event)}} > {children}
diff --git a/src/provider.tsx b/src/provider.tsx index 47312ae..cbef550 100644 --- a/src/provider.tsx +++ b/src/provider.tsx @@ -12,10 +12,9 @@ export const GlobalSubmitContext = createContext(initialSta export const DispatchSubmitContext = createContext({} as Dispatch); export const GlobalStateContext = createContext(initialState); export const DispatchStateContext = createContext({} as Dispatch); -export const GlobalFormInstanceContext = createContext(false); +export const GlobalFormInstanceContext = createContext(null); export const DispatchFormInstanceContext = createContext({} as Dispatch); - export const GlobalStateProvider = ({ children }: any) => { const [state, dispatch] = useReducer( (_state: GlobalStateContext, newValue: any) => { @@ -31,10 +30,10 @@ export const GlobalStateProvider = ({ children }: any) => { ); const [formInstance, dispatchFormInstance] = useReducer( - (_form: any, formInstance: any) => { - return formInstance ? formInstance : null + (_form: GlobalFormInstanceContext, formInstance: any) => { + return formInstance ? {...formInstance} : null }, - null + initialState ); const memoState = useMemo( @@ -79,9 +78,11 @@ export const useVGSCollectResponse = () => [ useContext(GlobalSubmitContext) ]; -export const useVGSCollectFormInstance = () => [ - useContext(GlobalFormInstanceContext) -]; +export const useVGSCollectFormInstance = () => { + return [ + useContext(GlobalFormInstanceContext) + ]; +} export const VGSCollectProvider = ({ children }: any) => { return {children}; From dd7677e92d72a076815cc19c39313b7c8d244b4a Mon Sep 17 00:00:00 2001 From: flor Date: Mon, 16 Dec 2024 14:34:38 +0200 Subject: [PATCH 2/2] test form --- example/src/features/SubmitHandling.tsx | 6 +++--- src/Form.tsx | 2 +- src/provider.tsx | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/example/src/features/SubmitHandling.tsx b/example/src/features/SubmitHandling.tsx index 6da9c02..4095966 100644 --- a/example/src/features/SubmitHandling.tsx +++ b/example/src/features/SubmitHandling.tsx @@ -46,7 +46,7 @@ const SubmitHandling = (e: any) => { useEffect(() => { setFormInstance(form); - console.log('formInstance', formInstance) + console.log('formInstance', formInstance, form) }, [form]); useEffect(() => { @@ -76,7 +76,7 @@ const SubmitHandling = (e: any) => { const customHandling = (event: any) => { event.preventDefault(); - console.log('HERE') + console.log('HERE', formInstance) if (!isFormSubmitting && formInstance) { setFormSubmitting(true); formInstance.submit( @@ -106,7 +106,7 @@ const SubmitHandling = (e: any) => { diff --git a/src/Form.tsx b/src/Form.tsx index 1a399f7..dca4225 100644 --- a/src/Form.tsx +++ b/src/Form.tsx @@ -88,7 +88,7 @@ function CollectForm(props: ICollectFormProps) { // console.log('qweqweqw',dispatchFormСontext, dispatchFormInstanceContextUpdate) // if (typeof dispatchFormInstanceContextUpdate === 'function') { - dispatchFormInstanceContextUpdate({qwe: 1}); + dispatchFormInstanceContextUpdate(getFormInstance()); // } else { // console.log('ELSE', dispatchFormInstanceContextUpdate, dispatchResponseUpdate, dispatchFormStateUpdate, getFormInstance()) // } diff --git a/src/provider.tsx b/src/provider.tsx index cbef550..958fb00 100644 --- a/src/provider.tsx +++ b/src/provider.tsx @@ -31,7 +31,8 @@ export const GlobalStateProvider = ({ children }: any) => { const [formInstance, dispatchFormInstance] = useReducer( (_form: GlobalFormInstanceContext, formInstance: any) => { - return formInstance ? {...formInstance} : null + console.log('--->', _form, formInstance) + return formInstance ? formInstance : null }, initialState );