daily-report-edit-state.js
1006 Bytes
const { isReportSubmitted, normalizeReportStatus } = require('./report-status.js')
function isDailyReportSubmitted({ reportStatus, reportDate, weeklyList = [] }) {
if (isReportSubmitted(reportStatus)) return true
if (reportDate && weeklyList.includes(reportDate)) return true
return false
}
function isDailyReportFormDisabled({
isDateWithinEditableWindow,
isTodayReport,
isReportSubmitted: submitted,
isEditReport
}) {
const editable =
isDateWithinEditableWindow !== undefined
? isDateWithinEditableWindow
: isTodayReport
if (!editable) return true
return submitted && !isEditReport
}
function resolveReportSubmittedPatch({ detail = {}, reportDate, weeklyList = [] }) {
const reportStatus = normalizeReportStatus(detail.reportStatus)
const submitted = isDailyReportSubmitted({ reportStatus, reportDate, weeklyList })
return {
reportStatus,
isReportSubmitted: submitted
}
}
module.exports = {
isDailyReportSubmitted,
isDailyReportFormDisabled,
resolveReportSubmittedPatch
}