Skip to content

Instantly share code, notes, and snippets.

@jackcallister
Created September 23, 2015 14:49
Show Gist options
  • Save jackcallister/cea861879917e269fc0f to your computer and use it in GitHub Desktop.
Save jackcallister/cea861879917e269fc0f to your computer and use it in GitHub Desktop.
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