Edit the structure of the context
[MAILPOET-2388]
This commit is contained in:
committed by
Jack Kitterhing
parent
84708f5154
commit
a95e03cb01
@@ -1,6 +0,0 @@
|
|||||||
export default function getConstantsContext(data) {
|
|
||||||
return {
|
|
||||||
isNewUser: data.mailpoet_is_new_user,
|
|
||||||
segments: data.mailpoetSegments,
|
|
||||||
};
|
|
||||||
}
|
|
5
assets/js/src/context/getSegmentsContext.jsx
Normal file
5
assets/js/src/context/getSegmentsContext.jsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export default function getSegmentsContext(data) {
|
||||||
|
return {
|
||||||
|
all: data.mailpoetSegments,
|
||||||
|
};
|
||||||
|
}
|
5
assets/js/src/context/getUsersContext.jsx
Normal file
5
assets/js/src/context/getUsersContext.jsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export default function getUsersContext(data) {
|
||||||
|
return {
|
||||||
|
isNewUser: data.mailpoet_is_new_user,
|
||||||
|
};
|
||||||
|
}
|
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import getFeaturesContext from './getFeaturesContext.jsx';
|
import getFeaturesContext from './getFeaturesContext.jsx';
|
||||||
import getConstantsContext from './getConstantsContext.jsx';
|
import getSegmentsContext from './getSegmentsContext.jsx';
|
||||||
|
import getUsersContext from './getUsersContext.jsx';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the value of the global context.
|
* Builds the value of the global context.
|
||||||
@@ -9,8 +10,9 @@ import getConstantsContext from './getConstantsContext.jsx';
|
|||||||
*/
|
*/
|
||||||
export function useGlobalContextValue(data) {
|
export function useGlobalContextValue(data) {
|
||||||
const features = getFeaturesContext(data);
|
const features = getFeaturesContext(data);
|
||||||
const constants = getConstantsContext(data);
|
const segments = getSegmentsContext(data);
|
||||||
return { features, constants };
|
const users = getUsersContext(data);
|
||||||
|
return { features, segments, users };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GlobalContext = React.createContext(useGlobalContextValue(window));
|
export const GlobalContext = React.createContext(useGlobalContextValue(window));
|
||||||
|
@@ -8,8 +8,8 @@ import { createSelection, destroySelection } from './generate_segment_selection.
|
|||||||
import createNewSegment from './create_new_segment.jsx';
|
import createNewSegment from './create_new_segment.jsx';
|
||||||
|
|
||||||
function SelectSegment({ setSelectedSegments }) {
|
function SelectSegment({ setSelectedSegments }) {
|
||||||
const { constants } = useContext(GlobalContext);
|
const { segments: segmentsContext } = useContext(GlobalContext);
|
||||||
const { segments: originalSegments } = constants;
|
const { all: originalSegments } = segmentsContext;
|
||||||
const [selectionSegments, setSelectionSegments] = useState(originalSegments);
|
const [selectionSegments, setSelectionSegments] = useState(originalSegments);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
|
@@ -8,8 +8,8 @@ function SelectImportMethod({
|
|||||||
activeMethod,
|
activeMethod,
|
||||||
onMethodChange,
|
onMethodChange,
|
||||||
}) {
|
}) {
|
||||||
const { constants } = React.useContext(GlobalContext);
|
const { users } = React.useContext(GlobalContext);
|
||||||
const { isNewUser } = constants;
|
const { isNewUser } = users;
|
||||||
const badgeClasses = classNames(
|
const badgeClasses = classNames(
|
||||||
'mailpoet_badge',
|
'mailpoet_badge',
|
||||||
'mailpoet_badge_video',
|
'mailpoet_badge_video',
|
||||||
|
Reference in New Issue
Block a user