Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uploadFile(file) {
- this.setState({
- uploading: true,
- dragIn: false,
- });
- const url = `${API_URL}/co_request/attached_document`;
- const docUrl = `${DOC_URL}/document`;
- const uploadDocUrl = `${DOC_URL}/upload/`;
- const formData = new FormData();
- const { intl } = this.props;
- const owners = [];
- if(!owners.includes(this.props.ownerKey)){
- owners.push(this.props.ownerKey);
- }
- if(!owners.includes(this.props.userInfo.person.person_key)){
- owners.push(this.props.userInfo.person.person_key);
- }
- if(!owners.includes(this.props.operation.requester_key)){
- owners.push(this.props.operation.requester_key);
- }
- fetchAuthorized(
- docUrl,
- { method: 'POST',
- body: JSON.stringify({
- document: {
- type: this.props.documentType,
- observation: "",
- owners,
- certifier: 'notary_office',
- refer_to: this.props.ownerDocument,
- },
- signatories: [],
- }),
- },
- null,
- this.props.userInfo.person.person_key,
- true,
- ).then(
- (document) => {
- formData.append('file', file[0]);
- fetchAuthorized(
- `${uploadDocUrl}${document.document_key}`,
- { method: 'PUT', body: formData },
- null,
- this.props.userInfo.person.person_key,
- true,
- )
- .then(responseUp => {
- fetchAuthorized(
- url,
- { method: 'POST',
- body: JSON.stringify({
- related_party_key: this.props.relatedPartyKey,
- attached_document_list: [
- {
- document_type: this.props.documentType,
- document_key: responseUp.document_key,
- document_url: responseUp.url,
- },
- ],
- }),
- },
- null,
- this.props.userInfo.person.person_key,
- true,
- ).then(
- (response) => {
- this.setState({
- uploading: false,
- dragIn: false,
- uploaded: true,
- });
- toast.success(
- `${file[0].name} ${intl.formatMessage(messages.uploaded)}`,
- );
- this.props.updateAfterUpload(response);
- }
- ).catch(error => {
- console.log(error);
- this.setState({ uploading: false, uploaded: false, dragIn: true });
- toast.error(
- `${file[0].name} ${intl.formatMessage(
- messages.uploadFailed,
- )} ${JSON.stringify(error.response.description)}`,
- );
- });
- })
- .catch(error => {
- console.log(error);
- this.setState({ uploading: false, uploaded: false, dragIn: true });
- toast.error(
- `${file[0].name} ${intl.formatMessage(
- messages.uploadFailed,
- )} ${JSON.stringify(error.response.description)}`,
- );
- });
- }
- ).catch(error => {
- console.log(error);
- this.setState({ uploading: false, uploaded: false, dragIn: false });
- toast.error(
- `${file[0].name} ${intl.formatMessage(
- messages.uploadFailed,
- )} ${JSON.stringify(error.response.description)}`,
- );
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement