Login component working

This commit is contained in:
John Lyon-Smith
2018-02-27 14:44:37 -08:00
parent 73b5cf6caa
commit c79df7722b
25 changed files with 112 additions and 321 deletions

View File

@@ -1,6 +1,6 @@
import React from 'react'
import { ProfileForm } from './ProfileForm'
import { Constants, api } from '../helpers'
import { api } from 'src/API'
import { WaitModal, MessageModal, ChangePasswordModal, ChangeEmailModal } from '../Modal'
import { autoBind } from 'auto-bind2'
@@ -17,8 +17,7 @@ export class Profile extends React.Component {
changeEmailModal: null,
progressModal: null,
uploadPercent: 0,
user,
userImageUrl: api.makeImageUrl(user.imageId, Constants.bigUserImageSize)
user
}
}
@@ -30,10 +29,6 @@ export class Profile extends React.Component {
api.removeListener('newProfileImage', this.handleNewProfileImage)
}
handleNewProfileImage(data) {
this.setState({ userImageUrl: api.makeImageUrl(data.imageId, Constants.bigUserImageSize) })
}
handleSaved(user) {
this.setState({ waitModal: { message: 'Updating Profile' } })
api.updateUser(user).then((updatedUser) => {
@@ -57,25 +52,6 @@ export class Profile extends React.Component {
this.setState({ changePasswordModal: true })
}
handleSelectImage(file) {
this.setState({ progressModal: { message: `Uploading image '${file.name}'...`, file }, uploadPercent: 0 })
api.upload(file, this.handleProgress).then((uploadData) => {
this.setState({ progressModal: null })
return api.setUserImage({
_id: api.loggedInUser._id,
imageId: uploadData.assetId,
bigSize: Profile.bigUserImageSize,
smallSize: Constants.smallUserImageSize
})
}).catch((error) => {
// TODO: if the upload succeeds but the setUserImage fails, delete the uploaded image
this.setState({
progressModal: null,
messageModal: { title: 'Upload Error...', message: `Unable to upload the file. ${error.message}` }
})
})
}
handleProgress(uploadData) {
if (this.state.progressModal) {
this.setState({ uploadPercent: Math.round(uploadData.uploadedChunks / uploadData.numberOfChunks * 100) })