better display Task has only due date without time
This commit is contained in:
62
src/utils/ChoreCardHelpers.jsx
Normal file
62
src/utils/ChoreCardHelpers.jsx
Normal file
@@ -0,0 +1,62 @@
|
||||
import moment from 'moment'
|
||||
|
||||
/**
|
||||
* Get the text to display for a chore's due date
|
||||
* @param {string|null} nextDueDate - The next due date of the chore
|
||||
* @param {Object} chore - The chore object (needed for nextDueDate null check)
|
||||
* @returns {string} The formatted due date text
|
||||
*/
|
||||
export const getDueDateChipText = (nextDueDate, chore) => {
|
||||
if (chore?.nextDueDate === null || nextDueDate === null) return 'No Due Date'
|
||||
|
||||
const dueDate = moment(nextDueDate)
|
||||
const diff = moment(nextDueDate).diff(moment(), 'hours')
|
||||
|
||||
// if seconds and minutes set to 59, treat as no time (date only)
|
||||
if (dueDate.seconds() === 59 && dueDate.minutes() === 59) {
|
||||
if (diff < 0) {
|
||||
// For overdue dates, show calendar format for recent dates
|
||||
const absDiff = Math.abs(diff)
|
||||
if (absDiff <= 48) {
|
||||
return (
|
||||
'Overdue ' +
|
||||
moment(nextDueDate).calendar().split(' at ')[0].toLowerCase()
|
||||
)
|
||||
}
|
||||
return 'Overdue ' + dueDate.fromNow()
|
||||
}
|
||||
// if due in next 48 hours, show calendar format without time (e.g., "Tomorrow")
|
||||
if (diff < 48 && diff > 0) {
|
||||
return moment(nextDueDate).calendar().split(' at ')[0]
|
||||
}
|
||||
// if due date is after 48 hours, show it in format: Due in 3 days
|
||||
return 'Due ' + dueDate.fromNow()
|
||||
}
|
||||
|
||||
// if due in next 48 hours, we should show it in this format: Tomorrow 11:00 AM
|
||||
if (diff < 48 && diff > 0) {
|
||||
return moment(nextDueDate).calendar().replace(' at', '')
|
||||
}
|
||||
return 'Due ' + moment(nextDueDate).fromNow()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color to use for a chore's due date chip
|
||||
* @param {string|null} nextDueDate - The next due date of the chore
|
||||
* @param {Object} chore - The chore object (needed for nextDueDate null check)
|
||||
* @returns {string} The color name for the chip
|
||||
*/
|
||||
export const getDueDateChipColor = (nextDueDate, chore) => {
|
||||
if (chore?.nextDueDate === null || nextDueDate === null) return 'neutral'
|
||||
|
||||
const diff = moment(nextDueDate).diff(moment(), 'hours')
|
||||
|
||||
if (diff < 48 && diff > 0) {
|
||||
return 'warning'
|
||||
}
|
||||
if (diff < 0) {
|
||||
return 'danger'
|
||||
}
|
||||
|
||||
return 'neutral'
|
||||
}
|
||||
@@ -23,6 +23,10 @@ import {
|
||||
import moment from 'moment'
|
||||
import { useImpersonateUser } from '../../contexts/ImpersonateUserContext.jsx'
|
||||
import { useUserProfile } from '../../queries/UserQueries.jsx'
|
||||
import {
|
||||
getDueDateChipColor,
|
||||
getDueDateChipText,
|
||||
} from '../../utils/ChoreCardHelpers.jsx'
|
||||
import { notInCompletionWindow } from '../../utils/Chores.jsx'
|
||||
import { getTextColorFromBackgroundColor } from '../../utils/Colors.jsx'
|
||||
import Priorities from '../../utils/Priorities'
|
||||
@@ -62,28 +66,6 @@ const ChoreCard = ({
|
||||
)
|
||||
}
|
||||
|
||||
const getDueDateChipText = nextDueDate => {
|
||||
if (chore.nextDueDate === null) return 'No Due Date'
|
||||
// if due in next 48 hours, we should it in this format : Tomorrow 11:00 AM
|
||||
const diff = moment(nextDueDate).diff(moment(), 'hours')
|
||||
if (diff < 48 && diff > 0) {
|
||||
return moment(nextDueDate).calendar().replace(' at', '')
|
||||
}
|
||||
return 'Due ' + moment(nextDueDate).fromNow()
|
||||
}
|
||||
const getDueDateChipColor = nextDueDate => {
|
||||
if (chore.nextDueDate === null) return 'neutral'
|
||||
const diff = moment(nextDueDate).diff(moment(), 'hours')
|
||||
if (diff < 48 && diff > 0) {
|
||||
return 'warning'
|
||||
}
|
||||
if (diff < 0) {
|
||||
return 'danger'
|
||||
}
|
||||
|
||||
return 'neutral'
|
||||
}
|
||||
|
||||
const getRecurrentChipText = chore => {
|
||||
// if chore.frequencyMetadata is type string then parse it otherwise assigned to the metadata:
|
||||
const metadata =
|
||||
@@ -216,9 +198,9 @@ const ChoreCard = ({
|
||||
zIndex: 3,
|
||||
left: 10,
|
||||
}}
|
||||
color={getDueDateChipColor(chore.nextDueDate)}
|
||||
color={getDueDateChipColor(chore.nextDueDate, chore)}
|
||||
>
|
||||
{getDueDateChipText(chore.nextDueDate)}
|
||||
{getDueDateChipText(chore.nextDueDate, chore)}
|
||||
</Chip>
|
||||
|
||||
<Chip
|
||||
|
||||
@@ -13,6 +13,10 @@ import moment from 'moment'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useImpersonateUser } from '../../contexts/ImpersonateUserContext.jsx'
|
||||
import { useCircleMembers, useUserProfile } from '../../queries/UserQueries.jsx'
|
||||
import {
|
||||
getDueDateChipColor,
|
||||
getDueDateChipText,
|
||||
} from '../../utils/ChoreCardHelpers.jsx'
|
||||
import { notInCompletionWindow } from '../../utils/Chores.jsx'
|
||||
import {
|
||||
getPriorityColor,
|
||||
@@ -60,28 +64,6 @@ const CompactChoreCard = ({
|
||||
}
|
||||
|
||||
// Utility functions
|
||||
const getDueDateText = nextDueDate => {
|
||||
if (chore.nextDueDate === null) return 'No Due Date'
|
||||
// if due in next 48 hours, we should it in this format : Tomorrow 11:00 AM
|
||||
const diff = moment(nextDueDate).diff(moment(), 'hours')
|
||||
if (diff < 48 && diff > 0) {
|
||||
return moment(nextDueDate).calendar().replace(' at', '')
|
||||
}
|
||||
|
||||
return moment(nextDueDate).fromNow()
|
||||
}
|
||||
|
||||
const getDueDateColor = nextDueDate => {
|
||||
if (chore.nextDueDate === null) return 'neutral'
|
||||
const diff = moment(nextDueDate).diff(moment(), 'hours')
|
||||
if (diff < 48 && diff > 0) {
|
||||
return 'warning'
|
||||
}
|
||||
if (diff < 0) {
|
||||
return 'danger'
|
||||
}
|
||||
return 'neutral'
|
||||
}
|
||||
|
||||
const getRecurrentText = chore => {
|
||||
// if chore.frequencyMetadata is type string then parse it otherwise assigned to the metadata:
|
||||
@@ -509,7 +491,7 @@ const CompactChoreCard = ({
|
||||
<Chip
|
||||
variant='soft'
|
||||
size='sm'
|
||||
color={getDueDateColor(chore.nextDueDate)}
|
||||
color={getDueDateChipColor(chore.nextDueDate, chore)}
|
||||
sx={{
|
||||
fontSize: 10,
|
||||
height: 18,
|
||||
@@ -518,7 +500,7 @@ const CompactChoreCard = ({
|
||||
ml: 1,
|
||||
}}
|
||||
>
|
||||
{getDueDateText(chore.nextDueDate)}
|
||||
{getDueDateChipText(chore.nextDueDate, chore)}
|
||||
</Chip>
|
||||
</Box>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user