plugin updates

This commit is contained in:
Tony Volpe
2024-06-17 15:33:26 -04:00
parent 3751a5a1a6
commit e4e274a9a7
2674 changed files with 0 additions and 507851 deletions

View File

@@ -1,86 +0,0 @@
import React, { useState, useEffect, Fragment } from 'react';
import { portalId, refreshToken } from '../../constants/leadinConfig';
import ElementorBanner from '../Common/ElementorBanner';
import UISpinner from '../../shared/UIComponents/UISpinner';
import { __ } from '@wordpress/i18n';
import {
BackgroudAppContext,
useBackgroundAppContext,
} from '../../iframe/useBackgroundApp';
import useForms from './hooks/useForms';
import { getOrCreateBackgroundApp } from '../../utils/backgroundAppUtils';
interface IElementorFormSelectProps {
formId: string;
setAttributes: Function;
}
function ElementorFormSelect({
formId,
setAttributes,
}: IElementorFormSelectProps) {
const { hasError, forms, loading } = useForms();
return loading ? (
<div>
<UISpinner />
</div>
) : hasError ? (
<ElementorBanner type="danger">
{__('Please refresh your forms or try again in a few minutes', 'leadin')}
</ElementorBanner>
) : (
<select
value={formId}
onChange={event => {
const selectedForm = forms.find(
form => form.value === event.target.value
);
if (selectedForm) {
setAttributes({
portalId,
formId: selectedForm.value,
formName: selectedForm.label,
});
}
}}
>
<option value="" disabled={true} selected={true}>
{__('Search for a form', 'leadin')}
</option>
{forms.map(form => (
<option key={form.value} value={form.value}>
{form.label}
</option>
))}
</select>
);
}
function ElementorFormSelectWrapper(props: IElementorFormSelectProps) {
const isBackgroundAppReady = useBackgroundAppContext();
return (
<Fragment>
{!isBackgroundAppReady ? (
<div>
<UISpinner />
</div>
) : (
<ElementorFormSelect {...props} />
)}
</Fragment>
);
}
export default function ElementorFormSelectContainer(
props: IElementorFormSelectProps
) {
return (
<BackgroudAppContext.Provider
value={refreshToken && getOrCreateBackgroundApp(refreshToken)}
>
<ElementorFormSelectWrapper {...props} />
</BackgroudAppContext.Provider>
);
}

View File

@@ -1,31 +0,0 @@
import React, { Fragment } from 'react';
import { connectionStatus } from '../../constants/leadinConfig';
import ConnectPluginBanner from '../Common/ConnectPluginBanner';
import ElementorFormSelect from './ElementorFormSelect';
import { IFormAttributes } from './registerFormWidget';
const ConnectionStatus = {
Connected: 'Connected',
NotConnected: 'NotConnected',
};
export default function FormControlController(
attributes: IFormAttributes,
setValue: Function
) {
return () => {
const render = () => {
if (connectionStatus === ConnectionStatus.Connected) {
return (
<ElementorFormSelect
formId={attributes.formId}
setAttributes={setValue}
/>
);
} else {
return <ConnectPluginBanner />;
}
};
return <Fragment>{render()}</Fragment>;
};
}

View File

@@ -1,30 +0,0 @@
import React, { Fragment } from 'react';
import { connectionStatus } from '../../constants/leadinConfig';
import ErrorHandler from '../../shared/Common/ErrorHandler';
import FormEdit from '../../shared/Form/FormEdit';
import ConnectionStatus from '../../shared/enums/connectionStatus';
import { IFormAttributes } from './registerFormWidget';
export default function FormWidgetController(
attributes: IFormAttributes,
setValue: Function
) {
return () => {
const render = () => {
if (connectionStatus === ConnectionStatus.Connected) {
return (
<FormEdit
attributes={attributes}
isSelected={true}
setAttributes={setValue}
preview={false}
origin="elementor"
/>
);
} else {
return <ErrorHandler status={401} />;
}
};
return <Fragment>{render()}</Fragment>;
};
}

View File

@@ -1,45 +0,0 @@
import { useState, useEffect } from 'react';
import LoadState, { LoadStateType } from '../../../shared/enums/loadState';
import { ProxyMessages } from '../../../iframe/integratedMessages';
import { usePostAsyncBackgroundMessage } from '../../../iframe/useBackgroundApp';
import { IForm } from '../../../shared/types';
interface FormOption {
label: string;
value: string;
}
export default function useForms() {
const proxy = usePostAsyncBackgroundMessage();
const [loadState, setLoadState] = useState<LoadStateType>(
LoadState.NotLoaded
);
const [hasError, setError] = useState(null);
const [forms, setForms] = useState<FormOption[]>([]);
useEffect(() => {
if (loadState === LoadState.NotLoaded) {
proxy({
key: ProxyMessages.FetchForms,
payload: {
search: '',
},
})
.then(data => {
setForms(
data.map((form: IForm) => ({
label: form.name,
value: form.guid,
}))
);
setLoadState(LoadState.Loaded);
})
.catch(error => {
setError(error);
setLoadState(LoadState.Failed);
});
}
}, [loadState]);
return { forms, loading: loadState === LoadState.Loading, hasError };
}

View File

@@ -1,44 +0,0 @@
import ReactDOM from 'react-dom';
import FormControlController from './FormControlController';
import FormWidgetController from './FormWidgetController';
export interface IFormAttributes {
formId: string;
formName: string;
portalId: string;
}
export default class registerFormWidget {
widgetContainer: Element;
attributes: IFormAttributes;
controlContainer: Element;
setValue: Function;
constructor(controlContainer: any, widgetContainer: any, setValue: Function) {
const attributes = widgetContainer.dataset.attributes
? JSON.parse(widgetContainer.dataset.attributes)
: {};
this.widgetContainer = widgetContainer;
this.controlContainer = controlContainer;
this.setValue = setValue;
this.attributes = attributes;
}
render() {
ReactDOM.render(
FormWidgetController(this.attributes, this.setValue)(),
this.widgetContainer
);
ReactDOM.render(
FormControlController(this.attributes, this.setValue)(),
this.controlContainer
);
}
done() {
ReactDOM.unmountComponentAtNode(this.widgetContainer);
ReactDOM.unmountComponentAtNode(this.controlContainer);
}
}