Skip to content

Commit

Permalink
[#5104] Implement sending report via email frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
zuhdil committed Sep 9, 2022
1 parent 2d3eab5 commit 8c8190a
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions akvo/rsr/spa/app/modules/reports/reports.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* global window, document */
import React, { useState, useEffect, useReducer } from 'react'
import { connect } from 'react-redux'
import { Button, Spin, Icon, Card, Select, DatePicker, Checkbox } from 'antd'
import { Button, Spin, Icon, Card, Select, DatePicker, Checkbox, Modal } from 'antd'
import { useTranslation } from 'react-i18next'
import Cookie from 'js-cookie'
import moment from 'moment'
import classNames from 'classnames'
import axios from 'axios'
import { useFetch } from '../../utils/hooks'
import api from '../../utils/api'
import SUOrgSelect from '../users/su-org-select'
Expand Down Expand Up @@ -132,21 +133,43 @@ const Report = ({ report, currentOrg, projectId, programId, setDownloading }) =>
if (programId) {
downloadUrl = downloadUrl.replace('{program}', programId)
}
if (downloadUrl.includes('download=true')) {
return (e) => {
e.stopPropagation()
const token = uid()
let timerId = setTimeout(function tick() {
if (Cookie.get(token)) {
clearTimeout(timerId)
setDownloading(false)
} else {
timerId = setTimeout(tick, 1000)
}
}, 1000)
setDownloading(true)
setTimeout(() => {
window.location.assign(`${downloadUrl}&did=${token}`)
}, 500)
}
}
return (e) => {
e.stopPropagation()
const token = uid()
let timerId = setTimeout(function tick() {
if (Cookie.get(token)) {
clearTimeout(timerId)
const handler = async function () {
try {
const { data } = await axios.get(downloadUrl)
Modal.success({
content: data,
});
} catch {
Modal.error({
title: 'Failed connecting to server',
content: 'Please try again in a few minutes...',
});
} finally {
setDownloading(false)
} else {
timerId = setTimeout(tick, 1000)
}
}, 1000)
}
setDownloading(true)
setTimeout(() => {
window.location.assign(`${downloadUrl}&did=${token}`)
}, 500)
handler()
}
}
return (
Expand Down

0 comments on commit 8c8190a

Please sign in to comment.