refactor(web): remove typescript
This commit is contained in:
24
packages/web/src/contexts/Authentication.jsx
Normal file
24
packages/web/src/contexts/Authentication.jsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import * as React from 'react';
|
||||
import { getItem, setItem } from 'helpers/storage';
|
||||
export const AuthenticationContext = React.createContext({
|
||||
token: null,
|
||||
updateToken: () => void 0,
|
||||
});
|
||||
export const AuthenticationProvider = (props) => {
|
||||
const { children } = props;
|
||||
const [token, setToken] = React.useState(() => getItem('token'));
|
||||
const value = React.useMemo(() => {
|
||||
return {
|
||||
token,
|
||||
updateToken: (newToken) => {
|
||||
setToken(newToken);
|
||||
setItem('token', newToken);
|
||||
},
|
||||
};
|
||||
}, [token]);
|
||||
return (
|
||||
<AuthenticationContext.Provider value={value}>
|
||||
{children}
|
||||
</AuthenticationContext.Provider>
|
||||
);
|
||||
};
|
@@ -1,40 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import { getItem, setItem } from 'helpers/storage';
|
||||
|
||||
export type AuthenticationContextParams = {
|
||||
token: string | null;
|
||||
updateToken: (token: string) => void;
|
||||
};
|
||||
|
||||
export const AuthenticationContext =
|
||||
React.createContext<AuthenticationContextParams>({
|
||||
token: null,
|
||||
updateToken: () => void 0,
|
||||
});
|
||||
|
||||
type AuthenticationProviderProps = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export const AuthenticationProvider = (
|
||||
props: AuthenticationProviderProps
|
||||
): React.ReactElement => {
|
||||
const { children } = props;
|
||||
const [token, setToken] = React.useState(() => getItem('token'));
|
||||
|
||||
const value = React.useMemo(() => {
|
||||
return {
|
||||
token,
|
||||
updateToken: (newToken: string) => {
|
||||
setToken(newToken);
|
||||
setItem('token', newToken);
|
||||
},
|
||||
};
|
||||
}, [token]);
|
||||
|
||||
return (
|
||||
<AuthenticationContext.Provider value={value}>
|
||||
{children}
|
||||
</AuthenticationContext.Provider>
|
||||
);
|
||||
};
|
@@ -1,34 +1,16 @@
|
||||
import * as React from 'react';
|
||||
import { useQuery } from '@apollo/client';
|
||||
|
||||
import { GET_AUTOMATISCH_INFO } from 'graphql/queries/get-automatisch-info';
|
||||
|
||||
export type AutomatischInfoContextParams = {
|
||||
isCloud: boolean;
|
||||
isMation: boolean;
|
||||
loading: boolean;
|
||||
};
|
||||
|
||||
export const AutomatischInfoContext =
|
||||
React.createContext<AutomatischInfoContextParams>({
|
||||
isCloud: false,
|
||||
isMation: false,
|
||||
loading: true,
|
||||
});
|
||||
|
||||
type AutomatischInfoProviderProps = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export const AutomatischInfoProvider = (
|
||||
props: AutomatischInfoProviderProps
|
||||
): React.ReactElement => {
|
||||
export const AutomatischInfoContext = React.createContext({
|
||||
isCloud: false,
|
||||
isMation: false,
|
||||
loading: true,
|
||||
});
|
||||
export const AutomatischInfoProvider = (props) => {
|
||||
const { children } = props;
|
||||
const { data, loading } = useQuery(GET_AUTOMATISCH_INFO);
|
||||
|
||||
const isCloud = data?.getAutomatischInfo?.isCloud;
|
||||
const isMation = data?.getAutomatischInfo?.isMation;
|
||||
|
||||
const value = React.useMemo(() => {
|
||||
return {
|
||||
isCloud,
|
||||
@@ -36,7 +18,6 @@ export const AutomatischInfoProvider = (
|
||||
loading,
|
||||
};
|
||||
}, [isCloud, isMation, loading]);
|
||||
|
||||
return (
|
||||
<AutomatischInfoContext.Provider value={value}>
|
||||
{children}
|
10
packages/web/src/contexts/Editor.jsx
Normal file
10
packages/web/src/contexts/Editor.jsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import * as React from 'react';
|
||||
export const EditorContext = React.createContext({
|
||||
readOnly: false,
|
||||
});
|
||||
export const EditorProvider = (props) => {
|
||||
const { children, value } = props;
|
||||
return (
|
||||
<EditorContext.Provider value={value}>{children}</EditorContext.Provider>
|
||||
);
|
||||
};
|
@@ -1,23 +0,0 @@
|
||||
import * as React from 'react';
|
||||
|
||||
interface IEditorContext {
|
||||
readOnly: boolean;
|
||||
}
|
||||
|
||||
export const EditorContext = React.createContext<IEditorContext>({
|
||||
readOnly: false,
|
||||
});
|
||||
|
||||
type EditorProviderProps = {
|
||||
children: React.ReactNode;
|
||||
value: IEditorContext;
|
||||
};
|
||||
|
||||
export const EditorProvider = (
|
||||
props: EditorProviderProps
|
||||
): React.ReactElement => {
|
||||
const { children, value } = props;
|
||||
return (
|
||||
<EditorContext.Provider value={value}>{children}</EditorContext.Provider>
|
||||
);
|
||||
};
|
79
packages/web/src/contexts/Paddle.ee.jsx
Normal file
79
packages/web/src/contexts/Paddle.ee.jsx
Normal file
@@ -0,0 +1,79 @@
|
||||
import * as React from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import * as URLS from 'config/urls';
|
||||
import useCloud from 'hooks/useCloud';
|
||||
import usePaddleInfo from 'hooks/usePaddleInfo.ee';
|
||||
import apolloClient from 'graphql/client';
|
||||
export const PaddleContext = React.createContext({
|
||||
loaded: false,
|
||||
});
|
||||
export const PaddleProvider = (props) => {
|
||||
const { children } = props;
|
||||
const isCloud = useCloud();
|
||||
const navigate = useNavigate();
|
||||
const { sandbox, vendorId } = usePaddleInfo();
|
||||
const [loaded, setLoaded] = React.useState(false);
|
||||
const paddleEventHandler = React.useCallback(
|
||||
async (payload) => {
|
||||
const { event, eventData } = payload;
|
||||
if (event === 'Checkout.Close') {
|
||||
const completed = eventData.checkout?.completed;
|
||||
if (completed) {
|
||||
// Paddle has side effects in the background,
|
||||
// so we need to refetch the relevant queries
|
||||
await apolloClient.refetchQueries({
|
||||
include: ['GetTrialStatus', 'GetBillingAndUsage'],
|
||||
});
|
||||
navigate(URLS.SETTINGS_BILLING_AND_USAGE, {
|
||||
state: { checkoutCompleted: true },
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
[navigate],
|
||||
);
|
||||
const value = React.useMemo(() => {
|
||||
return {
|
||||
loaded,
|
||||
};
|
||||
}, [loaded]);
|
||||
React.useEffect(
|
||||
function loadPaddleScript() {
|
||||
if (!isCloud) return;
|
||||
const isInjected = document.getElementById('paddle-js');
|
||||
if (isInjected) {
|
||||
setLoaded(true);
|
||||
return;
|
||||
}
|
||||
const g = document.createElement('script');
|
||||
const s = document.getElementsByTagName('script')[0];
|
||||
g.src = 'https://cdn.paddle.com/paddle/paddle.js';
|
||||
g.defer = true;
|
||||
g.async = true;
|
||||
g.id = 'paddle-js';
|
||||
if (s.parentNode) {
|
||||
s.parentNode.insertBefore(g, s);
|
||||
}
|
||||
g.onload = function () {
|
||||
setLoaded(true);
|
||||
};
|
||||
},
|
||||
[isCloud],
|
||||
);
|
||||
React.useEffect(
|
||||
function initPaddleScript() {
|
||||
if (!loaded || !vendorId) return;
|
||||
if (sandbox) {
|
||||
window.Paddle.Environment.set('sandbox');
|
||||
}
|
||||
window.Paddle.Setup({
|
||||
vendor: vendorId,
|
||||
eventCallback: paddleEventHandler,
|
||||
});
|
||||
},
|
||||
[loaded, sandbox, vendorId, paddleEventHandler],
|
||||
);
|
||||
return (
|
||||
<PaddleContext.Provider value={value}>{children}</PaddleContext.Provider>
|
||||
);
|
||||
};
|
@@ -1,109 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
import * as URLS from 'config/urls';
|
||||
import useCloud from 'hooks/useCloud';
|
||||
import usePaddleInfo from 'hooks/usePaddleInfo.ee';
|
||||
import apolloClient from 'graphql/client';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
Paddle: any;
|
||||
}
|
||||
}
|
||||
|
||||
export type PaddleContextParams = {
|
||||
loaded: boolean;
|
||||
};
|
||||
|
||||
export const PaddleContext =
|
||||
React.createContext<PaddleContextParams>({
|
||||
loaded: false,
|
||||
});
|
||||
|
||||
type PaddleProviderProps = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export const PaddleProvider = (
|
||||
props: PaddleProviderProps
|
||||
): React.ReactElement => {
|
||||
const { children } = props;
|
||||
const isCloud = useCloud();
|
||||
const navigate = useNavigate();
|
||||
const { sandbox, vendorId } = usePaddleInfo();
|
||||
const [loaded, setLoaded] = React.useState(false);
|
||||
|
||||
const paddleEventHandler = React.useCallback(async (payload) => {
|
||||
const { event, eventData } = payload;
|
||||
if (event === 'Checkout.Close') {
|
||||
const completed = eventData.checkout?.completed;
|
||||
|
||||
if (completed) {
|
||||
// Paddle has side effects in the background,
|
||||
// so we need to refetch the relevant queries
|
||||
await apolloClient.refetchQueries({
|
||||
include: ['GetTrialStatus', 'GetBillingAndUsage'],
|
||||
});
|
||||
|
||||
navigate(
|
||||
URLS.SETTINGS_BILLING_AND_USAGE,
|
||||
{
|
||||
state: { checkoutCompleted: true }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}, [navigate]);
|
||||
|
||||
const value = React.useMemo(() => {
|
||||
return {
|
||||
loaded,
|
||||
};
|
||||
}, [loaded]);
|
||||
|
||||
React.useEffect(function loadPaddleScript() {
|
||||
if (!isCloud) return;
|
||||
|
||||
const isInjected = document.getElementById('paddle-js');
|
||||
|
||||
if (isInjected) {
|
||||
setLoaded(true);
|
||||
return;
|
||||
}
|
||||
|
||||
const g = document.createElement('script')
|
||||
const s = document.getElementsByTagName('script')[0];
|
||||
g.src = 'https://cdn.paddle.com/paddle/paddle.js';
|
||||
g.defer = true;
|
||||
g.async = true;
|
||||
g.id = 'paddle-js';
|
||||
|
||||
if (s.parentNode) {
|
||||
s.parentNode.insertBefore(g, s);
|
||||
}
|
||||
|
||||
g.onload = function () {
|
||||
setLoaded(true);
|
||||
}
|
||||
}, [isCloud]);
|
||||
|
||||
React.useEffect(function initPaddleScript() {
|
||||
if (!loaded || !vendorId) return;
|
||||
|
||||
if (sandbox) {
|
||||
window.Paddle.Environment.set('sandbox');
|
||||
}
|
||||
|
||||
window.Paddle.Setup({
|
||||
vendor: vendorId,
|
||||
eventCallback: paddleEventHandler,
|
||||
});
|
||||
}, [loaded, sandbox, vendorId, paddleEventHandler])
|
||||
|
||||
return (
|
||||
<PaddleContext.Provider value={value}>
|
||||
{children}
|
||||
</PaddleContext.Provider>
|
||||
);
|
||||
};
|
10
packages/web/src/contexts/StepExecutions.jsx
Normal file
10
packages/web/src/contexts/StepExecutions.jsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import * as React from 'react';
|
||||
export const StepExecutionsContext = React.createContext([]);
|
||||
export const StepExecutionsProvider = (props) => {
|
||||
const { children, value } = props;
|
||||
return (
|
||||
<StepExecutionsContext.Provider value={value}>
|
||||
{children}
|
||||
</StepExecutionsContext.Provider>
|
||||
);
|
||||
};
|
@@ -1,20 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import type { IStep } from 'types';
|
||||
|
||||
export const StepExecutionsContext = React.createContext<IStep[]>([]);
|
||||
|
||||
type StepExecutionsProviderProps = {
|
||||
children: React.ReactNode;
|
||||
value: IStep[];
|
||||
};
|
||||
|
||||
export const StepExecutionsProvider = (
|
||||
props: StepExecutionsProviderProps
|
||||
): React.ReactElement => {
|
||||
const { children, value } = props;
|
||||
return (
|
||||
<StepExecutionsContext.Provider value={value}>
|
||||
{children}
|
||||
</StepExecutionsContext.Provider>
|
||||
);
|
||||
};
|
Reference in New Issue
Block a user