Skip to content

Commit

Permalink
Refresh on social admin page on module toggle change
Browse files Browse the repository at this point in the history
  • Loading branch information
gmjuhasz committed Nov 15, 2023
1 parent 61facfa commit 1902f5d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions projects/plugins/social/src/js/components/admin-page/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
} from '@automattic/jetpack-components';
import { useConnection } from '@automattic/jetpack-connection';
import { SOCIAL_STORE_ID } from '@automattic/jetpack-publicize-components';
import { useSelect } from '@wordpress/data';
import { useState, useCallback } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { useState, useCallback, useEffect } from '@wordpress/element';
import React from 'react';
import AdvancedUpsellNotice from '../advanced-upsell-notice';
import AutoConversionToggle from '../auto-conversion-toggle';
Expand All @@ -28,6 +28,18 @@ const Admin = () => {
const showConnectionCard = ! isRegistered || ! isUserConnected;
const [ forceDisplayPricingPage, setForceDisplayPricingPage ] = useState( false );

const refreshJetpackSocialSettings = useDispatch( SOCIAL_STORE_ID ).refreshJetpackSocialSettings;

useEffect( () => {
if (
isModuleEnabled &&
isUpdatingJetpackSettings &&
( isAutoConversionAvailable || isSocialImageGeneratorAvailable )
) {
refreshJetpackSocialSettings();
}
} );

const onUpgradeToggle = useCallback( () => setForceDisplayPricingPage( true ), [] );
const onPricingPageDismiss = useCallback( () => setForceDisplayPricingPage( false ), [] );

Expand Down Expand Up @@ -90,10 +102,10 @@ const Admin = () => {
<InstagramNotice onUpgrade={ onUpgradeToggle } />
<SocialModuleToggle />
{ ! isUpdatingJetpackSettings && isModuleEnabled && isAutoConversionAvailable && (
<AutoConversionToggle shouldRefresh />
<AutoConversionToggle />
) }
{ ! isUpdatingJetpackSettings && isModuleEnabled && isSocialImageGeneratorAvailable && (
<SocialImageGeneratorToggle shouldRefresh />
<SocialImageGeneratorToggle />
) }
</AdminSection>
<AdminSectionHero>
Expand Down

0 comments on commit 1902f5d

Please sign in to comment.