admin settings panel
This commit is contained in:
parent
a84971af84
commit
8c1f05159e
|
@ -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>
|
||||||
);
|
);
|
||||||
|
|
|
@ -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 {
|
||||||
|
updateInstance: function updateInstance() {
|
||||||
return function (dispatch, getState) {
|
return function (dispatch, getState) {
|
||||||
return Promise.try(() => {
|
return Promise.try(() => {
|
||||||
const state = selector(getState());
|
const state = getState().instances.adminSettings;
|
||||||
|
|
||||||
const update = getChanges(state, keys);
|
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"));
|
return dispatch(apiCall("PATCH", "/api/v1/instance", update, "form"));
|
||||||
}).then((account) => {
|
}).then((data) => {
|
||||||
return dispatch(user.setAccount(account));
|
return dispatch(instance.setInstanceInfo(data));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
|
||||||
fetchAccount: function fetchAccount() {
|
|
||||||
return function (dispatch, _getState) {
|
|
||||||
return Promise.try(() => {
|
|
||||||
return dispatch(apiCall("GET", "/api/v1/accounts/verify_credentials"));
|
|
||||||
}).then((account) => {
|
|
||||||
return dispatch(user.setAccount(account));
|
|
||||||
});
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
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),
|
oauth: require("./oauth")(submoduleArgs),
|
||||||
user: require("./user")(submoduleArgs),
|
user: require("./user")(submoduleArgs),
|
||||||
|
admin: require("./admin")(submoduleArgs),
|
||||||
apiCall,
|
apiCall,
|
||||||
getChanges
|
getChanges
|
||||||
};
|
};
|
Loading…
Reference in New Issue