From 58481d2e075816b730fbb653888581238ec9b184 Mon Sep 17 00:00:00 2001 From: Curtis ROck Date: Mon, 27 Jul 2020 22:30:53 -0500 Subject: [PATCH] added patch functions to actions/soapbox. edited features/configuration to support patchSoapbox method. Data not properly formattted yet. --- app/soapbox/actions/soapbox.js | 40 ++++++++++++++++++++++ app/soapbox/features/edit_profile/index.js | 4 +-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/soapbox/actions/soapbox.js b/app/soapbox/actions/soapbox.js index 6430e90c3..df172ed14 100644 --- a/app/soapbox/actions/soapbox.js +++ b/app/soapbox/actions/soapbox.js @@ -3,6 +3,10 @@ import api from '../api'; export const SOAPBOX_CONFIG_REQUEST_SUCCESS = 'SOAPBOX_CONFIG_REQUEST_SUCCESS'; export const SOAPBOX_CONFIG_REQUEST_FAIL = 'SOAPBOX_CONFIG_REQUEST_FAIL'; +export const SOAPBOX_PATCH_REQUEST = 'SOAPBOX_PATCH_REQUEST'; +export const SOAPBOX_PATCH_SUCCESS = 'SOAPBOX_PATCH_SUCCESS'; +export const SOAPBOX_PATCH_FAIL = 'SOAPBOX_PATCH_FAIL'; + export function fetchSoapboxConfig() { return (dispatch, getState) => { api(getState).get('/api/pleroma/frontend_configurations').then(response => { @@ -42,3 +46,39 @@ export function soapboxConfigFail(error) { skipAlert: true, }; } + +export function patchSoapbox(params) { + console.log(JSON.stringify(params)); + return (dispatch, getState) => { + dispatch(patchSoapboxRequest()); + return api(getState) + .patch('/api/pleroma/admin/config', params) + .then(response => { + dispatch(patchSoapboxSuccess(response.data)); + }).catch(error => { + dispatch(patchSoapboxFail(error)); + }); + }; +} + +export function patchSoapboxRequest() { + return { + type: SOAPBOX_PATCH_REQUEST, + }; +} + +export function patchSoapboxSuccess(me) { + return (dispatch, getState) => { + dispatch({ + type: SOAPBOX_PATCH_SUCCESS, + me, + }); + }; +} + +export function patchSoapboxFail(error) { + return { + type: SOAPBOX_PATCH_FAIL, + error, + }; +}; diff --git a/app/soapbox/features/edit_profile/index.js b/app/soapbox/features/edit_profile/index.js index 02972cb6d..00344595c 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 { patchMe } from 'soapbox/actions/me'; +import { patchSoapbox } from 'soapbox/actions/soapbox'; import { unescape } from 'lodash'; const MAX_FIELDS = 4; // TODO: Make this dynamic by the instance @@ -119,7 +119,7 @@ class EditProfile extends ImmutablePureComponent { 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 });