Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Colorize DueDate badge and add toggleable completion flag. #845

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion client/src/components/Card/Card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const Card = React.memo(
index,
name,
dueDate,
dueCompleted,
stopwatch,
coverUrl,
boardId,
Expand Down Expand Up @@ -81,6 +82,15 @@ const Card = React.memo(
[onUpdate],
);

const handleDueDateCompletionUpdate = useCallback(
(dueDateCompleted) => {
onUpdate({
dueDateCompleted,
});
},
[onUpdate],
);

const handleNameEdit = useCallback(() => {
nameEdit.current.open();
}, []);
Expand Down Expand Up @@ -120,7 +130,12 @@ const Card = React.memo(
)}
{dueDate && (
<span className={classNames(styles.attachment, styles.attachmentLeft)}>
<DueDate value={dueDate} size="tiny" />
<DueDate
value={dueDate}
completed={dueCompleted}
size="tiny"
onUpdateCompletion={handleDueDateCompletionUpdate}
/>
</span>
)}
{stopwatch && (
Expand Down Expand Up @@ -221,6 +236,7 @@ Card.propTypes = {
index: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
dueDate: PropTypes.instanceOf(Date),
dueCompleted: PropTypes.bool.isRequired,
stopwatch: PropTypes.object, // eslint-disable-line react/forbid-prop-types
coverUrl: PropTypes.string,
boardId: PropTypes.string.isRequired,
Expand Down
20 changes: 18 additions & 2 deletions client/src/components/CardModal/CardModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const CardModal = React.memo(
name,
description,
dueDate,
dueCompleted,
stopwatch,
isSubscribed,
isActivitiesFetching,
Expand Down Expand Up @@ -171,6 +172,15 @@ const CardModal = React.memo(
onClose();
}, [onClose]);

const handleDueDateCompletion = useCallback(
(completion) => {
onUpdate({
dueCompleted: completion,
});
},
[onUpdate],
);

const AttachmentAddPopup = usePopup(AttachmentAddStep);
const BoardMembershipsPopup = usePopup(BoardMembershipsStep);
const LabelsPopup = usePopup(LabelsStep);
Expand Down Expand Up @@ -303,10 +313,14 @@ const CardModal = React.memo(
<span className={styles.attachment}>
{canEdit ? (
<DueDateEditPopup defaultValue={dueDate} onUpdate={handleDueDateUpdate}>
<DueDate value={dueDate} />
<DueDate
value={dueDate}
completed={dueCompleted}
onUpdateCompletion={handleDueDateCompletion}
/>
</DueDateEditPopup>
) : (
<DueDate value={dueDate} />
<DueDate value={dueDate} completed={dueCompleted} />
)}
</span>
</div>
Expand Down Expand Up @@ -562,6 +576,7 @@ CardModal.propTypes = {
name: PropTypes.string.isRequired,
description: PropTypes.string,
dueDate: PropTypes.instanceOf(Date),
dueCompleted: PropTypes.bool,
stopwatch: PropTypes.object, // eslint-disable-line react/forbid-prop-types
isSubscribed: PropTypes.bool.isRequired,
isActivitiesFetching: PropTypes.bool.isRequired,
Expand Down Expand Up @@ -616,6 +631,7 @@ CardModal.propTypes = {
CardModal.defaultProps = {
description: undefined,
dueDate: undefined,
dueCompleted: false,
stopwatch: undefined,
};

Expand Down
107 changes: 77 additions & 30 deletions client/src/components/DueDate/DueDate.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import upperFirst from 'lodash/upperFirst';
import React from 'react';
import React, { useCallback } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';
import { Checkbox } from 'semantic-ui-react';

import getDateFormat from '../../utils/get-date-format';

Expand All @@ -26,50 +27,96 @@ const FULL_DATE_FORMAT_BY_SIZE = {
medium: 'fullDateTime',
};

const DueDate = React.memo(({ value, size, isDisabled, onClick }) => {
const [t] = useTranslation();
const getDueClass = (value) => {
const now = new Date();
const tomorrow = new Date(now).setDate(now.getDate() + 1);

const dateFormat = getDateFormat(
value,
LONG_DATE_FORMAT_BY_SIZE[size],
FULL_DATE_FORMAT_BY_SIZE[size],
);
if (now > value) return styles.overdue;
if (tomorrow > value) return styles.soon;
return null;
};

const DueDate = React.memo(
({ value, completed, size, isDisabled, onClick, onUpdateCompletion }) => {
const [t] = useTranslation();

const dateFormat = getDateFormat(
value,
LONG_DATE_FORMAT_BY_SIZE[size],
FULL_DATE_FORMAT_BY_SIZE[size],
);

const classes = [
styles.wrapper,
styles[`wrapper${upperFirst(size)}`],
onClick && styles.wrapperHoverable,
completed ? styles.completed : getDueClass(value),
];

const contentNode = (
<span
className={classNames(
styles.wrapper,
styles[`wrapper${upperFirst(size)}`],
onClick && styles.wrapperHoverable,
)}
>
{t(`format:${dateFormat}`, {
value,
postProcess: 'formatDate',
})}
</span>
);
const handleToggleChange = useCallback(
(event) => {
event.preventDefault();
event.stopPropagation();
if (!isDisabled) onUpdateCompletion(!completed);
},
[onUpdateCompletion, completed, isDisabled],
);

return onClick ? (
<button type="button" disabled={isDisabled} className={styles.button} onClick={onClick}>
{contentNode}
</button>
) : (
contentNode
);
});
return onClick ? (
<div className={styles.wrapperGroup}>
<button
type="button"
aria-label="Toggle completion"
className={classNames(...classes, styles.wrapperCheckbox)}
onClick={handleToggleChange}
>
<Checkbox
className={styles.checkbox}
checked={completed}
disabled={isDisabled}
onChange={handleToggleChange}
/>
</button>
<button
type="button"
disabled={isDisabled}
className={classNames(...classes, styles.wrapperButton)}
onClick={onClick}
>
<span>
{t(`format:${dateFormat}`, {
value,
postProcess: 'formatDate',
})}
</span>
</button>
</div>
) : (
<span className={classNames(...classes)}>
{t(`format:${dateFormat}`, {
value,
postProcess: 'formatDate',
})}
</span>
);
},
);

DueDate.propTypes = {
value: PropTypes.instanceOf(Date).isRequired,
size: PropTypes.oneOf(Object.values(SIZES)),
isDisabled: PropTypes.bool,
completed: PropTypes.bool,
onClick: PropTypes.func,
onUpdateCompletion: PropTypes.func,
};

DueDate.defaultProps = {
size: SIZES.MEDIUM,
isDisabled: false,
completed: false,
onClick: undefined,
onUpdateCompletion: undefined,
};

export default DueDate;
53 changes: 53 additions & 0 deletions client/src/components/DueDate/DueDate.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,75 @@
color: #17394d;
}

.wrapperGroup {
display: flex;
align-items: stretch;
justify-content: stretch;
}

.overdue {
background: #db2828;
color: #ffffff;
&.wrapperHoverable:hover {
background: #d01919;
color: #ffffff;
}
}

.soon {
background: #fbbd08;
color: #ffffff;
&.wrapperHoverable:hover {
background: #eaae00;
color: #ffffff;
}
}

.completed {
background: #21ba45;
color: #ffffff;
&.wrapperHoverable:hover {
background: #16ab39;
color: #ffffff;
}
}

/* Sizes */

.wrapperTiny {
font-size: 12px;
line-height: 20px;
padding: 0px 6px;
&.wrapperCheckbox {
padding-right: 6px;
}
}

.wrapperSmall {
font-size: 12px;
line-height: 20px;
padding: 2px 6px;
&.wrapperCheckbox {
padding-right: 6px;
}
}

.wrapperMedium {
line-height: 20px;
padding: 6px 12px;
}

.wrapperCheckbox {
padding-right: 12px;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
cursor: pointer;
}
.checkbox {
display: block;
}
.wrapperButton {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
}
7 changes: 3 additions & 4 deletions client/src/containers/CardContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ const makeMapStateToProps = () => {
const allLabels = selectors.selectLabelsForCurrentBoard(state);
const currentUserMembership = selectors.selectCurrentUserMembershipForCurrentBoard(state);

const { name, dueDate, stopwatch, coverUrl, boardId, listId, isPersisted } = selectCardById(
state,
id,
);
const { name, dueDate, dueCompleted, stopwatch, coverUrl, boardId, listId, isPersisted } =
selectCardById(state, id);

const users = selectUsersByCardId(state, id);
const labels = selectLabelsByCardId(state, id);
Expand All @@ -38,6 +36,7 @@ const makeMapStateToProps = () => {
index,
name,
dueDate,
dueCompleted,
stopwatch,
coverUrl,
boardId,
Expand Down
2 changes: 2 additions & 0 deletions client/src/containers/CardModalContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const mapStateToProps = (state) => {
name,
description,
dueDate,
dueCompleted,
stopwatch,
isSubscribed,
isActivitiesFetching,
Expand Down Expand Up @@ -49,6 +50,7 @@ const mapStateToProps = (state) => {
name,
description,
dueDate,
dueCompleted,
stopwatch,
isSubscribed,
isActivitiesFetching,
Expand Down
4 changes: 4 additions & 0 deletions client/src/models/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default class extends BaseModel {
relatedName: 'ownCards',
}),
dueDate: attr(),
dueCompleted: attr({
getDefault: () => false,
}),
stopwatch: attr(),
isSubscribed: attr({
getDefault: () => false,
Expand Down Expand Up @@ -248,6 +251,7 @@ export default class extends BaseModel {
'name',
'description',
'dueDate',
'dueCompleted',
'stopwatch',
]),
...payload.card,
Expand Down
12 changes: 11 additions & 1 deletion server/api/controllers/cards/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ module.exports = {
type: 'string',
custom: dueDateValidator,
},
dueCompleted: {
type: 'boolean',
},
stopwatch: {
type: 'json',
custom: stopwatchValidator,
Expand Down Expand Up @@ -95,7 +98,14 @@ module.exports = {
throw Errors.NOT_ENOUGH_RIGHTS;
}

const values = _.pick(inputs, ['position', 'name', 'description', 'dueDate', 'stopwatch']);
const values = _.pick(inputs, [
'position',
'name',
'description',
'dueDate',
'dueCompleted',
'stopwatch',
]);

const card = await sails.helpers.cards.createOne
.with({
Expand Down
Loading