mirror of
1
Fork 0

admin settings panel

This commit is contained in:
f0x 2022-09-13 22:05:14 +02:00
parent a84971af84
commit 8c1f05159e
3 changed files with 17 additions and 43 deletions

View File

@ -30,7 +30,6 @@ const adminActions = require("../redux/reducers/instances").actions;
const { const {
TextInput, TextInput,
TextArea, TextArea,
Checkbox,
File File
} = require("../components/form-fields").formFields(adminActions.setAdminSettingsVal, (state) => state.instances.adminSettings); } = require("../components/form-fields").formFields(adminActions.setAdminSettingsVal, (state) => state.instances.adminSettings);
@ -45,7 +44,7 @@ module.exports = function AdminSettings() {
setStatus("PATCHing"); setStatus("PATCHing");
setError(""); setError("");
return Promise.try(() => { return Promise.try(() => {
return dispatch(api.admin.updateProfile()); return dispatch(api.admin.updateInstance());
}).then(() => { }).then(() => {
setStatus("Saved!"); setStatus("Saved!");
}).catch((e) => { }).catch((e) => {
@ -91,7 +90,7 @@ module.exports = function AdminSettings() {
placeHolder="" placeHolder=""
/> />
<div className="file-upload"> {/* <div className="file-upload">
<h3>Instance avatar</h3> <h3>Instance avatar</h3>
<div> <div>
<img className="preview avatar" src={instance.avatar} alt={instance.avatar ? `Avatar image for the instance` : "No instance avatar image set"} /> <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/*" fileType="image/*"
/> />
</div> </div>
</div> </div> */}
<Submit onClick={submit} label="Save" errorMsg={errorMsg} statusMsg={statusMsg} /> <Submit onClick={submit} label="Save" errorMsg={errorMsg} statusMsg={statusMsg} />
</div> </div>
); );

View File

@ -19,52 +19,26 @@
"use strict"; "use strict";
const Promise = require("bluebird"); 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 }) { 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 { return {
fetchAccount: function fetchAccount() { updateInstance: function updateInstance() {
return function (dispatch, _getState) { return function (dispatch, getState) {
return Promise.try(() => { return Promise.try(() => {
return dispatch(apiCall("GET", "/api/v1/accounts/verify_credentials")); const state = getState().instances.adminSettings;
}).then((account) => {
return dispatch(user.setAccount(account)); 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});
} }
}; };
}; };

View File

@ -175,6 +175,7 @@ module.exports = {
}, },
oauth: require("./oauth")(submoduleArgs), oauth: require("./oauth")(submoduleArgs),
user: require("./user")(submoduleArgs), user: require("./user")(submoduleArgs),
admin: require("./admin")(submoduleArgs),
apiCall, apiCall,
getChanges getChanges
}; };