Skip to content

Commit 0903fbe

Browse files
gmjuhaszmatticbot
authored andcommitted
Social: Add social note toggle admin page (#35681)
* Add endpoints and change setter function * Add the initial state * Add new store functions * Add 'beta' property to ToggleSection * Add new toggle component * changelog * Fix tests * Fixup versions * Move to use social/settings endpoint * Get rid of social-notes endpoint Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/8018622024
1 parent dc2dd8b commit 0903fbe

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
This is an alpha version! The changes listed here are not final.
1111

12+
### Added
13+
- Added toggle to Social admin page for the Social Notes
14+
1215
### Removed
1316
- Removed a notice to tell users that instagram is new nad can be connected
1417

src/social-store/actions/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import * as connectionData from './connection-data';
33
import siteSettingActions from './jetpack-settings';
44
import jetpackSocialSettings from './jetpack-social-settings';
55
import socialImageGeneratorSettingActions from './social-image-generator-settings';
6+
import socialNotesSettings from './social-notes-settings';
67

78
const actions = {
89
...siteSettingActions,
910
...socialImageGeneratorSettingActions,
1011
...autoConversionSettingActions,
1112
...jetpackSocialSettings,
1213
...connectionData,
14+
...socialNotesSettings,
1315
};
1416

1517
export default actions;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { select } from '@wordpress/data';
2+
import { SOCIAL_STORE_ID } from '../../social-store';
3+
import {
4+
fetchJetpackSettings,
5+
updateJetpackSettings as updateJetpackSettingsControl,
6+
} from '../controls';
7+
import { setJetpackSettings } from './jetpack-settings';
8+
9+
/**
10+
* Yield actions to update settings
11+
*
12+
* @param {object} settings - settings to apply.
13+
* @yields {object} - an action object.
14+
* @returns {object} - an action object.
15+
*/
16+
export function* updateSocialNotesSettings( settings ) {
17+
try {
18+
yield setUpdatingSocialNotesSettings();
19+
yield setJetpackSettings( settings );
20+
yield updateJetpackSettingsControl( settings );
21+
const updatedSettings = yield fetchJetpackSettings();
22+
yield setJetpackSettings( updatedSettings );
23+
return true;
24+
} catch ( e ) {
25+
const oldSettings = select( SOCIAL_STORE_ID ).getSocialNotesSettings();
26+
yield setJetpackSettings( oldSettings );
27+
return false;
28+
} finally {
29+
yield setUpdatingSocialNotesSettingsDone();
30+
}
31+
}
32+
33+
/**
34+
* Yield actions to refresh settings
35+
*
36+
* @yields {object} - an action object.
37+
* @returns {object} - an action object.
38+
*/
39+
export function* refreshSocialNotesSettings() {
40+
try {
41+
yield setUpdatingSocialNotesSettings();
42+
const updatedSettings = yield fetchJetpackSettings();
43+
yield setJetpackSettings( updatedSettings );
44+
return true;
45+
} catch ( e ) {
46+
return false;
47+
} finally {
48+
yield setUpdatingSocialNotesSettingsDone();
49+
}
50+
}
51+
52+
/**
53+
* Set state updating action
54+
*
55+
* @returns {object} - an action object.
56+
*/
57+
export function setUpdatingSocialNotesSettings() {
58+
return setJetpackSettings( { social_notes_is_updating: true } );
59+
}
60+
61+
/**
62+
* Set state updating finished
63+
*
64+
* @returns {object} - an action object.
65+
*/
66+
export function setUpdatingSocialNotesSettingsDone() {
67+
return setJetpackSettings( { social_notes_is_updating: false } );
68+
}
69+
70+
export default {
71+
updateSocialNotesSettings,
72+
refreshSocialNotesSettings,
73+
};

src/social-store/selectors/jetpack-settings.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const jetpackSettingSelectors = {
66
hasPaidPlan: state => ! ( state.jetpackSettings?.showNudge ?? true ),
77
isEnhancedPublishingEnabled: state => state.jetpackSettings?.isEnhancedPublishingEnabled ?? false,
88
getDismissedNotices: state => state.jetpackSettings?.dismissedNotices,
9+
isSocialNotesEnabled: state => state.jetpackSettings?.social_notes_enabled,
10+
isSocialNotesSettingsUpdating: state => state.jetpackSettings?.social_notes_is_updating,
911
};
1012

1113
export default jetpackSettingSelectors;

0 commit comments

Comments
 (0)