admin settings panel
This commit is contained in:
parent
a84971af84
commit
8c1f05159e
|
@ -30,7 +30,6 @@ const adminActions = require("../redux/reducers/instances").actions;
|
|||
const {
|
||||
TextInput,
|
||||
TextArea,
|
||||
Checkbox,
|
||||
File
|
||||
} = require("../components/form-fields").formFields(adminActions.setAdminSettingsVal, (state) => state.instances.adminSettings);
|
||||
|
||||
|
@ -45,7 +44,7 @@ module.exports = function AdminSettings() {
|
|||
setStatus("PATCHing");
|
||||
setError("");
|
||||
return Promise.try(() => {
|
||||
return dispatch(api.admin.updateProfile());
|
||||
return dispatch(api.admin.updateInstance());
|
||||
}).then(() => {
|
||||
setStatus("Saved!");
|
||||
}).catch((e) => {
|
||||
|
@ -91,7 +90,7 @@ module.exports = function AdminSettings() {
|
|||
placeHolder=""
|
||||
/>
|
||||
|
||||
<div className="file-upload">
|
||||
{/* <div className="file-upload">
|
||||
<h3>Instance avatar</h3>
|
||||
<div>
|
||||
<img className="preview avatar" src={instance.avatar} alt={instance.avatar ? `Avatar image for the instance` : "No instance avatar image set"} />
|
||||
|
@ -111,7 +110,7 @@ module.exports = function AdminSettings() {
|
|||
fileType="image/*"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div> */}
|
||||
<Submit onClick={submit} label="Save" errorMsg={errorMsg} statusMsg={statusMsg} />
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -19,52 +19,26 @@
|
|||
"use strict";
|
||||
|
||||
const Promise = require("bluebird");
|
||||
const d = require("dotty");
|
||||
|
||||
const user = require("../../redux/reducers/user").actions;
|
||||
const instance = require("../../redux/reducers/instances").actions;
|
||||
|
||||
module.exports = function ({ apiCall, getChanges }) {
|
||||
function updateInstance(selector, keys) {
|
||||
return function (dispatch, getState) {
|
||||
return Promise.try(() => {
|
||||
const state = selector(getState());
|
||||
|
||||
const update = getChanges(state, keys);
|
||||
|
||||
return dispatch(apiCall("PATCH", "/api/v1/instance", update, "form"));
|
||||
}).then((account) => {
|
||||
return dispatch(user.setAccount(account));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
fetchAccount: function fetchAccount() {
|
||||
return function (dispatch, _getState) {
|
||||
updateInstance: function updateInstance() {
|
||||
return function (dispatch, getState) {
|
||||
return Promise.try(() => {
|
||||
return dispatch(apiCall("GET", "/api/v1/accounts/verify_credentials"));
|
||||
}).then((account) => {
|
||||
return dispatch(user.setAccount(account));
|
||||
const state = getState().instances.adminSettings;
|
||||
|
||||
const update = getChanges(state, {
|
||||
formKeys: ["title", "short_description", "description", "contact_username", "email", "terms"],
|
||||
// fileKeys: ["avatar", "header"]
|
||||
});
|
||||
|
||||
return dispatch(apiCall("PATCH", "/api/v1/instance", update, "form"));
|
||||
}).then((data) => {
|
||||
return dispatch(instance.setInstanceInfo(data));
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
updateProfile: function updateProfile() {
|
||||
const formKeys = ["display_name", "locked", "source", "custom_css", "note"];
|
||||
|
||||
const renamedKeys = {
|
||||
note: "source.note"
|
||||
};
|
||||
|
||||
const fileKeys = ["header", "avatar"];
|
||||
|
||||
return updateCredentials((state) => state.user.profile, {formKeys, renamedKeys, fileKeys});
|
||||
},
|
||||
|
||||
updateSettings: function updateProfile() {
|
||||
const formKeys = ["source"];
|
||||
|
||||
return updateCredentials((state) => state.user.settings, {formKeys});
|
||||
}
|
||||
};
|
||||
};
|
|
@ -175,6 +175,7 @@ module.exports = {
|
|||
},
|
||||
oauth: require("./oauth")(submoduleArgs),
|
||||
user: require("./user")(submoduleArgs),
|
||||
admin: require("./admin")(submoduleArgs),
|
||||
apiCall,
|
||||
getChanges
|
||||
};
|
Loading…
Reference in New Issue