Created
September 23, 2015 14:49
-
-
Save jackcallister/cea861879917e269fc0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function beginCreatingAttachment(attachment, type) { | |
return function(dispatch) { | |
const file = attachment.file | |
delete attachment.file | |
return AttachmentWebUtils.postAttachmentForAWSCredentials(attachment).then((response) => { | |
const s3Data = response.uploadSignature.fields | |
const url = response.uploadSignature.host | |
const attachmentId = response.id | |
const parentId = response.parent.id | |
function onProgress(progress) { | |
dispatch(updateUploadProgress(progress, type)) | |
} | |
dispatch({ | |
type: BEGIN_CREATING_ATTACHMENT, | |
payload: { | |
type: type, | |
file: file | |
} | |
}) | |
AttachmentWebUtils.uploadAttachmentToAWS(url, parentId, s3Data, file, onProgress).then(() => { | |
AttachmentWebUtils.put(attachmentId).then((response) => { | |
dispatch(successCreatingAttachment(response, type)) | |
}).catch((error) => { | |
console.log("Error on PUT to attachment-service", error) | |
}) | |
}).catch((error) => { | |
console.log("Error on POST to AWS", error); | |
}) | |
}) | |
} | |
} | |
export function beginLoadingPeople(query) { | |
return { | |
types: [ | |
BEGIN_LOADING_PEOPLE, | |
SUCCESS_LOADING_PEOPLE, | |
ERROR_LOADING_PEOPLE | |
], | |
payload: { | |
data: query, | |
promise: PeopleWebUtils.fetch(query) | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment