Upgrade axios to v0.27, fix EditProfile uploads

This commit is contained in:
Alex Gleason
2022-04-29 16:01:46 -05:00
parent f808d93209
commit 2cbea4aa5b
9 changed files with 40 additions and 15 deletions

View File

@@ -46,11 +46,21 @@ export function fetchMe() {
};
}
export function patchMe(params) {
export function patchMe(params, formData = false) {
return (dispatch, getState) => {
dispatch(patchMeRequest());
let options = {};
if (formData) {
options = {
headers: {
'Content-Type': 'multipart/form-data',
},
};
}
return api(getState)
.patch('/api/v1/accounts/update_credentials', params)
.patch('/api/v1/accounts/update_credentials', params, options)
.then(response => {
dispatch(patchMeSuccess(response.data));
}).catch(error => {

View File

@@ -169,7 +169,7 @@ const EditProfile: React.FC = () => {
};
const handleSubmit: React.FormEventHandler = (event) => {
const credentials = dispatch(patchMe(data));
const credentials = dispatch(patchMe(data, true));
/* Bad API url, was causing errors in the promise call below blocking the success message after making edits. */
/* const notifications = dispatch(updateNotificationSettings({
block_from_strangers: this.state.stranger_notifications || false,

View File

@@ -61,7 +61,7 @@ const AvatarSelectionStep = ({ onNext }: { onNext: () => void }) => {
setSelectedFile(null);
if (error.response?.status === 422) {
dispatch(snackbar.error(error.response.data.error.replace('Validation failed: ', '')));
dispatch(snackbar.error((error.response.data as any).error.replace('Validation failed: ', '')));
} else {
dispatch(snackbar.error('An unexpected error occurred. Please try again or skip this step.'));
}

View File

@@ -33,7 +33,7 @@ const BioStep = ({ onNext }: { onNext: () => void }) => {
setSubmitting(false);
if (error.response?.status === 422) {
setErrors([error.response.data.error.replace('Validation failed: ', '')]);
setErrors([(error.response.data as any).error.replace('Validation failed: ', '')]);
} else {
dispatch(snackbar.error('An unexpected error occurred. Please try again or skip this step.'));
}

View File

@@ -62,7 +62,7 @@ const CoverPhotoSelectionStep = ({ onNext }: { onNext: () => void }) => {
setSelectedFile(null);
if (error.response?.status === 422) {
dispatch(snackbar.error(error.response.data.error.replace('Validation failed: ', '')));
dispatch(snackbar.error((error.response.data as any).error.replace('Validation failed: ', '')));
} else {
dispatch(snackbar.error('An unexpected error occurred. Please try again or skip this step.'));
}

View File

@@ -40,7 +40,7 @@ const DisplayNameStep = ({ onNext }: { onNext: () => void }) => {
setSubmitting(false);
if (error.response?.status === 422) {
setErrors([error.response.data.error.replace('Validation failed: ', '')]);
setErrors([(error.response.data as any).error.replace('Validation failed: ', '')]);
} else {
dispatch(snackbar.error('An unexpected error occurred. Please try again or skip this step.'));
}

View File

@@ -57,7 +57,7 @@ const Header = () => {
.catch((error: AxiosError) => {
setLoading(false);
const data = error.response?.data;
const data: any = error.response?.data;
if (data?.error === 'mfa_required') {
setMfaToken(data.mfa_token);
}