reportState.ts 951 B

12345678910111213141516171819202122232425
  1. import { Report, ReportDTO, ReportState, SchedulingFrequency } from '../../types';
  2. import { isPast } from './dateTime';
  3. export const getReportState = (report: ReportDTO) => {
  4. const { endDate, startDate, frequency } = report.schedule;
  5. if (frequency === SchedulingFrequency.Never) {
  6. return ReportState.Never;
  7. }
  8. if (isPast(endDate) || (frequency === SchedulingFrequency.Once && isPast(startDate))) {
  9. return ReportState.Expired;
  10. }
  11. return report.state || ReportState.Scheduled;
  12. };
  13. export const getReportStateInfo = (report: Report) => {
  14. const reportState = getReportState(report);
  15. const isNever = report.schedule.frequency === SchedulingFrequency.Never;
  16. const showPlay = isNever || [ReportState.Draft, ReportState.Expired, ReportState.Paused].includes(reportState);
  17. const disableEdit = isNever || [ReportState.Draft, ReportState.Expired].includes(reportState);
  18. return { isNever, showPlay, disableEdit, reportState };
  19. };