* Basic implementation * Nit fix * Using existing profile update api * API call working * Basic full implementation * Nit fixes in design * UI changes * Image upload limit set * Removed drag & drop * Image size issue fix * Minor naming fixes * Removed native mobile code * Nit fix * Added few tests * Added test * Added test * Added image upload error * Added validateFileInput test failure case * Updated code to test fix * Revert db changes * Minor design fixes * Minor updated test * Added validateFileInputs test temporarily * Added processImageUpload test temporarily * Aded files count test * Minor warning fixes * Updated placeholder text * Added tests for TextInput and TextArea * Removed un-required test file * Removed un-required code * Minor code cleaning
33 lines
902 B
JavaScript
33 lines
902 B
JavaScript
function generateUploadFormdata(image) {
|
|
const token = window.csrfToken;
|
|
const formData = new FormData();
|
|
formData.append('authenticity_token', token);
|
|
formData.append('user[profile_image]', image);
|
|
return formData;
|
|
}
|
|
|
|
export function generateMainImage({ payload, successCb, failureCb, signal }) {
|
|
const image = payload.image[0];
|
|
const { userId } = payload;
|
|
|
|
if (image) {
|
|
fetch(`/users/${userId}`, {
|
|
method: 'PUT',
|
|
headers: {
|
|
'X-CSRF-Token': window.csrfToken,
|
|
Accept: 'application/json',
|
|
},
|
|
body: generateUploadFormdata(image),
|
|
credentials: 'same-origin',
|
|
signal,
|
|
})
|
|
.then((response) => response.json())
|
|
.then((json) => {
|
|
if (json.error) {
|
|
throw new Error(json.error);
|
|
}
|
|
return successCb(json.user.profile_image.url);
|
|
})
|
|
.catch((message) => failureCb(message));
|
|
}
|
|
}
|