STEP-5 Creating Extension, Base Redux Store
In this step finally, we going to begin scandipwa extension development
Last updated
In this step finally, we going to begin scandipwa extension development
Last updated
"dependencies": {
"@scandipwa/scandipwa": "4.4.0",
"scandipwa-socialshare": "file:../app/code/ScandiPWA/SocialShareGraphQl/scandipwa-socialshare"
},
"scandipwa": {
"type": "theme",
"locales": {
"en_US": true
},
"parentTheme": "@scandipwa/scandipwa",
"extensions": {
"scandipwa-socialshare": true
}
},"dependencies": {
"@scandipwa/scandipwa": "4.4.0",
"scandipwa-socialshare": "file:packages/scandipwa-socialshare"
},
"scandipwa": {
"type": "theme",
"locales": {
"en_US": true
},
"parentTheme": "@scandipwa/scandipwa",
"extensions": {
"scandipwa-socialshare": true
}
},import { Field } from 'Util/Query';
/** @namespace ScandipwaSocialshare/Query/SocialShare/Query/SocialShareQuery */
export class SocialShareQuery {
getQuery() {
return new Field('socialShare')
.addFieldList(['enabled']);
}
}
export default new SocialShareQuery();export const UPDATE_SOCIAL_SHARE = 'UPDATE_SOCIAL_SHARE';
/** @namespace Store/SocialShare/Action/updateSocialShare */
export const updateSocialShare = (socialShare) => ({
type: UPDATE_SOCIAL_SHARE,
socialShare
});import { UPDATE_SOCIAL_SHARE } from './SocialShare.action';
/** @namespace ScandipwaSocialshare/Store/SocialShare/Reducer/getInitialState */
export const getInitialState = () => ({
socialShare: {
enabled: 'not'
}
});
/** @namespace ScandipwaSocialshare/Store/SocialShare/Reducer/SocialShareReducer */
export const SocialShareReducer = (
state = getInitialState(),
action
) => {
const {
type,
socialShare
} = action;
switch (type) {
case UPDATE_SOCIAL_SHARE:
return {
...state,
...socialShare
};
default:
return state;
}
};
export default SocialShareReducer;import { showNotification } from 'Store/Notification/Notification.action';
import BrowserDatabase from 'Util/BrowserDatabase';
import { QueryDispatcher } from 'Util/Request';
import { ONE_MONTH_IN_SECONDS } from 'Util/Request/QueryDispatcher';
import SocialShareQuery from '../../query/SocialShare.query';
import { updateSocialShare } from './SocialShare.action';
/** @namespace ScandipwaSocialshare/Store/SocialShare/Dispatcher/SocialShareDispatcher */
export class SocialShareDispatcher extends QueryDispatcher {
__construct() {
super.__construct('SocialShare');
}
onSuccess(data, dispatch) {
if (data) {
BrowserDatabase.setItem(data, 'SocialShare', ONE_MONTH_IN_SECONDS);
dispatch(updateSocialShare(data));
}
}
onError(error, dispatch) {
dispatch(showNotification('error', __('Error fetching SocialShare!'), error));
}
prepareRequest() {
return [
SocialShareQuery.getQuery()
];
}
}
export default new SocialShareDispatcher();