itizawa 6 lat temu
rodzic
commit
b4f90e1134

+ 10 - 2
src/client/js/components/Me/ProfileImageSettings.jsx

@@ -56,8 +56,16 @@ class ProfileImageSettings extends React.Component {
     }
   }
 
-  onCropCompleted(croppedImageUrl) {
-    this.props.personalContainer.setState({ croppedImageUrl });
+  async onCropCompleted(croppedImageUrl) {
+    const { t, personalContainer } = this.props;
+    personalContainer.setState({ croppedImageUrl });
+    try {
+      await personalContainer.uploadAttachment(croppedImageUrl);
+      toastSuccess(t('toaster.update_successed', { target: t('Upload Image') }));
+    }
+    catch (err) {
+      toastError(err);
+    }
     this.hideModal();
   }
 

+ 16 - 0
src/client/js/services/PersonalContainer.js

@@ -181,4 +181,20 @@ export default class PersonalContainer extends Container {
     }
   }
 
+  /**
+   * Upload image
+   */
+  async uploadAttachment(file) {
+
+    try {
+      // TODO create apiV3
+      // await this.appContainer.apiPost('/attachments.uploadProfileImage', { data: formData });
+    }
+    catch (err) {
+      this.setState({ retrieveError: err });
+      logger.error(err);
+      throw new Error('Failed to upload profile image');
+    }
+  }
+
 }