Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/PRESS 2 111 extract social media data outside current data #63

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f3930a4
Added Support for API Requests to be queued
officiallygod Aug 19, 2022
92debbb
Added API Queuer to Basic Info Page
officiallygod Aug 19, 2022
3f3d285
added API Queuer Support to Get Started Experience page
officiallygod Aug 19, 2022
3d3e310
Added API Queuer Support for Get Started Welcome Page
officiallygod Aug 19, 2022
58768a7
Added API Queuer Support for Get Started Primary and Secondary Page
officiallygod Aug 19, 2022
1db76ed
Added API Queuer Support for Design Theme
officiallygod Aug 19, 2022
bd07a4a
Added API Queuer Support for Top Priority
officiallygod Aug 19, 2022
110c759
Added API Queuer support to Ecommerce Steps
officiallygod Aug 22, 2022
33d8dfc
added API requests to the api-executer function
officiallygod Aug 22, 2022
6d7d182
Removed earlier based API Requests from App.js component
officiallygod Aug 22, 2022
b3e1e57
Removed Default primary and secondary types in Flows.php
officiallygod Aug 22, 2022
e0c6e06
Extracted Social Media out of CurrentData
officiallygod Aug 22, 2022
1b87e2d
Refactored currentData to flowData
officiallygod Aug 22, 2022
0027b4d
Fixed Ecommerce steps weird deserialisation
officiallygod Aug 22, 2022
c069f2d
Fixed a Typo in Ecommerce/StepProducts
officiallygod Aug 22, 2022
8f0987d
Merge branch 'release/v1.0.0' into add/PRESS2-93-Implement-API-Queuin…
officiallygod Aug 22, 2022
1381509
Refactored name to be more general
officiallygod Aug 22, 2022
0534425
Merge branch 'add/PRESS2-93-Implement-API-Queuing-Sytem' into add/PRE…
officiallygod Aug 23, 2022
dd63813
refactored name from currentData to flowData
officiallygod Aug 23, 2022
c793c68
Refactored names for better understanding
officiallygod Aug 23, 2022
4d81c96
Refactored to use the New API Queuing System
officiallygod Aug 23, 2022
d86222c
Revert "Refactored to use the New API Queuing System"
officiallygod Mar 1, 2023
4a6956b
Revert "Refactored names for better understanding"
officiallygod Mar 1, 2023
750abab
Revert "refactored name from currentData to flowData"
officiallygod Mar 1, 2023
df5f8b4
Revert "Merge branch 'add/PRESS2-93-Implement-API-Queuing-Sytem' into…
officiallygod Mar 1, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
node_modules
vendor
.DS_Store
33 changes: 20 additions & 13 deletions src/OnboardingSPA/components/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,33 @@ const App = () => {
isDrawerOpen,
newfoldBrand,
onboardingFlow,
currentData,
flowData,
socialData,
firstStep
} = useSelect((select) => {
return {
isDrawerOpen: select(nfdOnboardingStore).isDrawerOpened(),
newfoldBrand: select(nfdOnboardingStore).getNewfoldBrand(),
onboardingFlow: select(nfdOnboardingStore).getOnboardingFlow(),
currentData: select(nfdOnboardingStore).getCurrentOnboardingData(),
flowData: select(nfdOnboardingStore).getCurrentOnboardingFlowData(),
socialData: select(nfdOnboardingStore).getCurrentOnboardingSocialData(),
firstStep: select(nfdOnboardingStore).getFirstStep(),
};
}, []);

const [isRequestPlaced, setIsRequestPlaced] = useState(false);
const [didVisitBasicInfo, setDidVisitBasicInfo] = useState(false);
const [didVisitEcommerce, setDidVisitEcommerce] = useState(false);
const { setActiveStep, setActiveFlow, setCurrentOnboardingData } = useDispatch(nfdOnboardingStore);
const {
setActiveStep,
setActiveFlow,
setCurrentOnboardingFlowData,
setCurrentOnboardingSocialData
} = useDispatch(nfdOnboardingStore);

async function syncSocialSettings() {
const initialData = await getSettings();
const result = await setSettings(currentData?.data?.socialData);
const result = await setSettings(socialData);
setDidVisitBasicInfo(false);
if (result?.error != null) {
console.error('Unable to Save Social Data!');
Expand All @@ -61,7 +68,7 @@ const App = () => {
}

async function syncStoreDetails() {
let { address, tax } = currentData.storeDetails;
let { address, tax } = flowData?.storeDetails;
let payload = {};
if (address !== undefined) {
delete address.country;
Expand All @@ -86,15 +93,15 @@ const App = () => {
if (!isEmpty(payload)) {
await updateWPSettings(payload);
}
delete currentData.storeDetails.address;
delete currentData.storeDetails.tax;
delete flowData?.storeDetails?.address;
delete flowData?.storeDetails?.tax;
setDidVisitEcommerce(false);
}

async function syncStoreToDB() {
// The First Welcome Step doesn't have any Store changes
const isFirstStep = location?.pathname === firstStep?.path;
if (currentData && !isFirstStep){
if (flowData && !isFirstStep){
if(!isRequestPlaced){
setIsRequestPlaced(true);

Expand All @@ -104,19 +111,19 @@ const App = () => {

// If Social Data is changed then sync it
if (didVisitBasicInfo){
const socialData = await syncSocialSettings();
const socialDataToBeSaved = await syncSocialSettings();

// If Social Data is changed then Sync that also to the store
if (socialData && currentData?.data)
currentData.data.socialData = socialData;
if (socialDataToBeSaved && flowData?.data)
setCurrentOnboardingSocialData(socialDataToBeSaved);
}

const result = await setFlow(currentData);
const result = await setFlow(flowData);
if (result?.error != null) {
setIsRequestPlaced(false);
console.error('Unable to Save data!');
} else {
setCurrentOnboardingData(result?.body);
setCurrentOnboardingFlowData(result?.body);
setIsRequestPlaced(false);
}

Expand Down
24 changes: 12 additions & 12 deletions src/OnboardingSPA/components/ExitToWordPress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const ExitToWordPress = ({
const closeModal = () => setIsOpen(false);

const location = useLocation();
const { currentData } = useSelect(
const { flowData } = useSelect(
(select) => {
return {
currentData: select(nfdOnboardingStore).getCurrentOnboardingData(),
flowData: select(nfdOnboardingStore).getCurrentOnboardingFlowData(),
};
},
[location.pathname]
Expand All @@ -45,30 +45,30 @@ const ExitToWordPress = ({
'wp-module-onboarding'
);

async function syncSocialSettingsFinish(currentData) {
async function syncSocialSettingsFinish(flowData) {
const initialData = await getSettings();
const result = await setSettings(currentData?.data?.socialData);
const result = await setSettings(flowData?.data?.socialData);
if (result?.error != null) {
console.error('Unable to Save Social Data!');
return initialData?.body;
}
return result?.body;
}

async function saveData(path, currentData) {
async function saveData(path, flowData) {

if (currentData) {
currentData.hasExited = new Date().getTime();
if (flowData) {
flowData.hasExited = new Date().getTime();

// If Social Data is changed then sync it
if (path?.includes('basic-info')) {
const socialData = await syncSocialSettingsFinish(currentData);
const socialData = await syncSocialSettingsFinish(flowData);

// If Social Data is changed then Sync that also to the store
if (socialData && currentData?.data)
currentData.data.socialData = socialData;
if (socialData && flowData?.data)
flowData.data.socialData = socialData;
}
setFlow(currentData);
setFlow(flowData);
}
//Redirect to Admin Page for normal customers
// and Bluehost Dashboard for ecommerce customers
Expand Down Expand Up @@ -98,7 +98,7 @@ const ExitToWordPress = ({
</Button>
<Button
variant="primary"
onClick={(e) => saveData(location.pathname, currentData)} >
onClick={(e) => saveData(location.pathname, flowData)} >
{__('Exit', 'wp-module-onboarding')}
</Button>
</ButtonGroup>
Expand Down
28 changes: 14 additions & 14 deletions src/OnboardingSPA/components/Header/step-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,29 @@ const Next = ({ path }) => {
);
};

async function syncSocialSettingsFinish( currentData ) {
async function syncSocialSettingsFinish( flowData ) {
const initialData = await getSettings();
const result = await setSettings(currentData?.data?.socialData);
const result = await setSettings(flowData?.data?.socialData);
if (result?.error != null) {
console.error('Unable to Save Social Data!');
return initialData?.body;
}
return result?.body;
}

async function saveData(path, currentData) {
async function saveData(path, flowData) {

if (currentData) {
currentData.isComplete = new Date().getTime();
if (flowData) {
flowData.isComplete = new Date().getTime();
// If Social Data is changed then sync it
if (path?.includes('basic-info')) {
const socialData = await syncSocialSettingsFinish(currentData);
const socialData = await syncSocialSettingsFinish(flowData);

// If Social Data is changed then Sync that also to the store
if (socialData && currentData?.data)
currentData.data.socialData = socialData;
if (socialData && flowData?.data)
flowData.data.socialData = socialData;
}
setFlow(currentData);
setFlow(flowData);
}
//Redirect to Admin Page for normal customers
// and Bluehost Dashboard for ecommerce customers
Expand All @@ -81,9 +81,9 @@ async function saveData(path, currentData) {
* Finish step navigation button.
* @returns
*/
const Finish = ({ path, currentData, saveData }) => (
const Finish = ({ path, flowData, saveData }) => (
<Button
onClick={(e) => saveData(path, currentData)}
onClick={(e) => saveData(path, flowData)}
className="navigation-buttons navigation-buttons_finish"
variant="primary">
{__('Finish', 'wp-module-onboarding')}
Expand All @@ -97,12 +97,12 @@ const Finish = ({ path, currentData, saveData }) => (
*/
const StepNavigation = () => {
const location = useLocation();
const { previousStep, nextStep, currentData } = useSelect(
const { previousStep, nextStep, flowData } = useSelect(
(select) => {
return {
nextStep: select(nfdOnboardingStore).getNextStep(),
previousStep: select(nfdOnboardingStore).getPreviousStep(),
currentData: select(nfdOnboardingStore).getCurrentOnboardingData(),
flowData: select(nfdOnboardingStore).getCurrentOnboardingFlowData(),
};
},
[location.pathname]
Expand All @@ -113,7 +113,7 @@ const StepNavigation = () => {
<div className="nfd-onboarding-header__step-navigation">
<ButtonGroup style={{ display: 'flex', columnGap: '0.5rem' }}>
{isFirstStep ? null : <Back path={previousStep.path} />}
{isLastStep ? <Finish path={location.pathname} currentData={currentData} saveData={saveData}/> : <Next path={nextStep.path} />}
{isLastStep ? <Finish path={location.pathname} flowData={flowData} saveData={saveData}/> : <Next path={nextStep.path} />}
</ButtonGroup>
</div>
);
Expand Down
31 changes: 17 additions & 14 deletions src/OnboardingSPA/components/MiniPreview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ const MiniPreview = ({ title, desc, icon, socialData }) => {
const [tiktok, setTikTok] = useState("");

useEffect(() => {
setFacebook((socialData?.facebook_site) ?? "");
setTwitter(socialData?.twitter_site ?? "");
setInstagram(socialData?.instagram_url ?? "");
setYouTube(socialData?.youtube_url ?? "");
setLinkedIn(socialData?.linkedin_url ?? "");
if (Object.keys(socialData).includes("other_social_urls"))
{
const otherURLS = socialData.other_social_urls;
if (Object.keys(otherURLS).includes("yelp_url"))
setYelp(otherURLS["yelp_url"] ?? "");
if( socialData ) {
setFacebook((socialData?.facebook_site) ?? "");
setTwitter(socialData?.twitter_site ?? "");
setInstagram(socialData?.instagram_url ?? "");
setYouTube(socialData?.youtube_url ?? "");
setLinkedIn(socialData?.linkedin_url ?? "");
if (Object.keys(socialData).includes("other_social_urls")) {
const otherURLS = socialData.other_social_urls;
if (Object.keys(otherURLS).includes("yelp_url"))
setYelp(otherURLS["yelp_url"] ?? "");

if (Object.keys(otherURLS).includes("tiktok_url"))
setTikTok(otherURLS["tiktok_url"] ?? "");
if (Object.keys(otherURLS).includes("tiktok_url"))
setTikTok(otherURLS["tiktok_url"] ?? "");
}
}
}, [socialData]);

Expand Down Expand Up @@ -70,11 +71,13 @@ const MiniPreview = ({ title, desc, icon, socialData }) => {

function socialIconList() {
var socialIconList = []
socialDataset.map( (socialInfo) => {
if (socialDataset) {
socialDataset.map( (socialInfo) => {
!socialInfo.url ||
socialIconList.push(
<div key={socialInfo.image} className={`browser-content_social_icon ${isValidUrl(socialInfo.url) || 'invalid-url' }`} style={{ backgroundImage: socialInfo.image }} />)
})
})
}
return socialIconList;
}

Expand Down
24 changes: 12 additions & 12 deletions src/OnboardingSPA/components/SkipButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const SkipButton = () => {

const navigate = useNavigate();
const location = useLocation();
const { previousStep, nextStep, currentData } = useSelect(
const { previousStep, nextStep, flowData } = useSelect(
(select) => {
return {
previousStep: select(nfdOnboardingStore).getPreviousStep(),
nextStep: select(nfdOnboardingStore).getNextStep(),
currentData: select(nfdOnboardingStore).getCurrentOnboardingData(),
flowData: select(nfdOnboardingStore).getCurrentOnboardingFlowData(),
};
},
[]
Expand All @@ -32,30 +32,30 @@ const SkipButton = () => {
const isLastStep = null === nextStep || false === nextStep;


async function syncSocialSettingsFinish(currentData) {
async function syncSocialSettingsFinish(flowData) {
const initialData = await getSettings();
const result = await setSettings(currentData?.data?.socialData);
const result = await setSettings(flowData?.data?.socialData);
if (result?.error != null) {
console.error('Unable to Save Social Data!');
return initialData?.body;
}
return result?.body;
}

async function saveData(path, currentData) {
async function saveData(path, flowData) {

if (currentData) {
currentData.isComplete = new Date().getTime();
if (flowData) {
flowData.isComplete = new Date().getTime();

// If Social Data is changed then sync it
if (path?.includes('basic-info')) {
const socialData = await syncSocialSettingsFinish(currentData);
const socialData = await syncSocialSettingsFinish(flowData);

// If Social Data is changed then Sync that also to the store
if (socialData && currentData?.data)
currentData.data.socialData = socialData;
if (socialData && flowData?.data)
flowData.data.socialData = socialData;
}
setFlow(currentData);
setFlow(flowData);
}
// Redirect to Admin Page for normal customers
// and Bluehost Dashboard for ecommerce customers
Expand All @@ -68,7 +68,7 @@ const SkipButton = () => {
{
return (
<Button className="skip-button"
onClick={(e) => saveData(location.pathname, currentData)} >
onClick={(e) => saveData(location.pathname, flowData)} >
{__('Skip this Step', 'wp-module-onboarding')}
</Button>
);
Expand Down
28 changes: 14 additions & 14 deletions src/OnboardingSPA/components/SocialMediaForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ const SocialMediaForm = ({ socialData, setSocialData, setIsValidSocials }) => {
}

useEffect(() => {
setFacebook(socialData?.facebook_site ?? "");
setTwitter(socialData?.twitter_site ?? "");
setInstagram(socialData?.instagram_url ?? "");
setYouTube(socialData?.youtube_url ?? "");
setLinkedIn(socialData?.linkedin_url ?? "");
if (Object.keys(socialData).includes("other_social_urls"))
{
const otherURLS = socialData.other_social_urls;
if (Object.keys(otherURLS).includes("yelp_url"))
setYelp(otherURLS["yelp_url"] ?? "");

if (Object.keys(otherURLS).includes("tiktok_url"))
setTikTok(otherURLS["tiktok_url"] ?? "");
if( socialData ) {
setFacebook(socialData?.facebook_site ?? "");
setTwitter(socialData?.twitter_site ?? "");
setInstagram(socialData?.instagram_url ?? "");
setYouTube(socialData?.youtube_url ?? "");
setLinkedIn(socialData?.linkedin_url ?? "");
if (Object.keys(socialData).includes("other_social_urls")) {
const otherURLS = socialData.other_social_urls;
if (Object.keys(otherURLS).includes("yelp_url"))
setYelp(otherURLS["yelp_url"] ?? "");

if (Object.keys(otherURLS).includes("tiktok_url"))
setTikTok(otherURLS["tiktok_url"] ?? "");
}
}

}, [socialData]);

const isValidUrl = (urlString) => {
Expand Down
Loading