EditProfile: fix formdata submission
This commit is contained in:
parent
300efe3259
commit
81938ec4d0
|
@ -59,18 +59,12 @@ const persistAuthAccount = (account, params) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function patchMe(params, formData = false) {
|
export function patchMe(params) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch(patchMeRequest());
|
dispatch(patchMeRequest());
|
||||||
|
|
||||||
const options = formData ? {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'multipart/form-data',
|
|
||||||
},
|
|
||||||
} : {};
|
|
||||||
|
|
||||||
return api(getState)
|
return api(getState)
|
||||||
.patch('/api/v1/accounts/update_credentials', params, options)
|
.patch('/api/v1/accounts/update_credentials', params)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
persistAuthAccount(response.data, params);
|
persistAuthAccount(response.data, params);
|
||||||
dispatch(patchMeSuccess(response.data));
|
dispatch(patchMeSuccess(response.data));
|
||||||
|
|
|
@ -27,6 +27,25 @@ const hidesNetwork = (account: Account): boolean => {
|
||||||
return Boolean(hide_followers && hide_follows && hide_followers_count && hide_follows_count);
|
return Boolean(hide_followers && hide_follows && hide_followers_count && hide_follows_count);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Converts JSON objects to FormData. */
|
||||||
|
// https://stackoverflow.com/a/60286175/8811886
|
||||||
|
// @ts-ignore
|
||||||
|
const toFormData = (f => f(f))(h => f => f(x => h(h)(f)(x)))(f => fd => pk => d => {
|
||||||
|
if (d instanceof Object) {
|
||||||
|
// eslint-disable-next-line consistent-return
|
||||||
|
Object.keys(d).forEach(k => {
|
||||||
|
const v = d[k];
|
||||||
|
if (pk) k = `${pk}[${k}]`;
|
||||||
|
if (v instanceof Object && !(v instanceof Date) && !(v instanceof File)) {
|
||||||
|
return f(fd)(k)(v);
|
||||||
|
} else {
|
||||||
|
fd.append(k, v);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return fd;
|
||||||
|
})(new FormData())();
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
heading: { id: 'column.edit_profile', defaultMessage: 'Edit profile' },
|
heading: { id: 'column.edit_profile', defaultMessage: 'Edit profile' },
|
||||||
header: { id: 'edit_profile.header', defaultMessage: 'Edit Profile' },
|
header: { id: 'edit_profile.header', defaultMessage: 'Edit Profile' },
|
||||||
|
@ -193,8 +212,9 @@ const EditProfile: React.FC = () => {
|
||||||
|
|
||||||
const handleSubmit: React.FormEventHandler = (event) => {
|
const handleSubmit: React.FormEventHandler = (event) => {
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
const formData = toFormData(data);
|
||||||
|
|
||||||
promises.push(dispatch(patchMe(data, true)));
|
promises.push(dispatch(patchMe(formData)));
|
||||||
|
|
||||||
if (features.muteStrangers) {
|
if (features.muteStrangers) {
|
||||||
promises.push(
|
promises.push(
|
||||||
|
|
Loading…
Reference in New Issue