From 7d41967cada646e1e42bc81f5b6e1be25ab66978 Mon Sep 17 00:00:00 2001 From: crockwave Date: Tue, 28 Jul 2020 19:29:20 -0500 Subject: [PATCH] corrected editing error in features/edit_profile. edited getFormdata to start producing a JSON data format. Changed actions/soapbox to use post instead of patch --- app/soapbox/actions/soapbox.js | 2 +- app/soapbox/features/configuration/index.js | 35 +++++++++++++-------- app/soapbox/features/edit_profile/index.js | 7 +++-- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/app/soapbox/actions/soapbox.js b/app/soapbox/actions/soapbox.js index df172ed14..91038cca0 100644 --- a/app/soapbox/actions/soapbox.js +++ b/app/soapbox/actions/soapbox.js @@ -48,7 +48,7 @@ export function soapboxConfigFail(error) { } export function patchSoapbox(params) { - console.log(JSON.stringify(params)); + console.log(params); return (dispatch, getState) => { dispatch(patchSoapboxRequest()); return api(getState) diff --git a/app/soapbox/features/configuration/index.js b/app/soapbox/features/configuration/index.js index d7b16e3e4..7f4964452 100644 --- a/app/soapbox/features/configuration/index.js +++ b/app/soapbox/features/configuration/index.js @@ -17,7 +17,7 @@ import { Map as ImmutableMap, List as ImmutableList, } from 'immutable'; -import { patchMe } from 'soapbox/actions/me'; +import { patchSoapbox } from 'soapbox/actions/soapbox'; //import { generateThemeCss } from 'soapbox/utils/theme'; const messages = defineMessages({ @@ -74,9 +74,11 @@ class ConfigSoapbox extends ImmutablePureComponent { this.state = { logo: props.logo, banner: props.banner, + brandColor: props.brandColor, + customCssItems: props.customCssItems, promoItems: props.promoItems, homeFooterItems: props.homeFooterItems, - customCssItems: props.customCssItems, + copyright: props.copyright, patronEnabled: false, autoPlayGif: false, }; @@ -107,9 +109,10 @@ class ConfigSoapbox extends ImmutablePureComponent { this.state.customCssItems = ImmutableList([]); }; this.handlecustomCSSChange = this.handleCustomCSSChange.bind(this); - // this.handleAddPromoPanelItem = this.handleAddPromoPanelItem.bind(this); + this.handleAddPromoPanelItem = this.handleAddPromoPanelItem.bind(this); this.handleAddHomeFooterItem = this.handleAddHomeFooterItem.bind(this); - this.handleAddCSSItem = this.handleAddCSSItem.bind(this); + this.handleAddCssItem = this.handleAddCssItem.bind(this); + this.getCustomCssParams = this.getCustomCssParams.bind(this); } getPromoItemsParams = () => { @@ -145,30 +148,36 @@ class ConfigSoapbox extends ImmutablePureComponent { getParams = () => { const { state } = this; return Object.assign({ + logo: state.logo, + banner: state.banner, brandColor: state.brandColor, - logoFile: state.logoFile, patronEnabled: state.patronEnabled, - displayMode: state.displayMode, + autoPlayGif: state.autoPlayGif, copyright: state.copyright, }, this.getHomeFooterParams().toJS(), - this.getPromoItemsParams().toJS()), - this.getCustomCSSParams().toJS(); + this.getPromoItemsParams().toJS(), + this.getCustomCssParams().toJS()); } getFormdata = () => { const data = this.getParams(); let formData = new FormData(); for (let key in data) { - const shouldAppend = Boolean(data[key] || key.startsWith('promo_panel_attributes') || key.startsWith('home_footer_attributes') || key.startsWith('custom_css_attributes')); + const shouldAppend = Boolean(data[key] + || key.startsWith('promo_panel_attributes') + || key.startsWith('home_footer_attributes') + || key.startsWith('custom_css_attributes') + || (key === 'patronEnabled' && data.patronEnabled !== undefined) + || (key === 'autoPlayGif' && data.autoPlayGif !== undefined)); if (shouldAppend) formData.append(key, data[key] || ''); } - return formData; + return JSON.stringify(formData); } handleSubmit = (event) => { const { dispatch } = this.props; - dispatch(patchMe(this.getFormdata())).then(() => { + dispatch(patchSoapbox(this.getFormdata())).then(() => { this.setState({ isLoading: false }); }).catch((error) => { this.setState({ isLoading: false }); @@ -247,7 +256,7 @@ class ConfigSoapbox extends ImmutablePureComponent { }); } - handleAddCSSItem = () => { + handleAddCssItem = () => { this.setState({ customCssItems: this.state.customCssItems.concat(['']), }); @@ -399,7 +408,7 @@ class ConfigSoapbox extends ImmutablePureComponent { )) }
-
diff --git a/app/soapbox/features/edit_profile/index.js b/app/soapbox/features/edit_profile/index.js index 00344595c..c4126d92d 100644 --- a/app/soapbox/features/edit_profile/index.js +++ b/app/soapbox/features/edit_profile/index.js @@ -17,7 +17,7 @@ import { Map as ImmutableMap, List as ImmutableList, } from 'immutable'; -import { patchSoapbox } from 'soapbox/actions/soapbox'; +import { patchMe } from 'soapbox/actions/me'; import { unescape } from 'lodash'; const MAX_FIELDS = 4; // TODO: Make this dynamic by the instance @@ -111,7 +111,8 @@ class EditProfile extends ImmutablePureComponent { const data = this.getParams(); let formData = new FormData(); for (let key in data) { - const shouldAppend = Boolean(data[key] || key.startsWith('fields_attributes')); + const shouldAppend = Boolean(data[key] + || key.startsWith('fields_attributes')); if (shouldAppend) formData.append(key, data[key] || ''); } return formData; @@ -119,7 +120,7 @@ class EditProfile extends ImmutablePureComponent { handleSubmit = (event) => { const { dispatch } = this.props; - dispatch(patchSoapbox(this.getFormdata())).then(() => { + dispatch(patchMe(this.getFormdata())).then(() => { this.setState({ isLoading: false }); }).catch((error) => { this.setState({ isLoading: false });