Skip to content

Commit

Permalink
feat: add begins date option for datepicker, use for substantial comp…
Browse files Browse the repository at this point in the history
…letion date
  • Loading branch information
mikevespi authored and tmastrom committed Dec 29, 2022
1 parent 7ce9341 commit b493875
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/data/jsonSchemaForm/projectMilestoneUiSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const projectMilestoneUiSchema = {
"ui:col-md": 12,
"bcgov:size": "small",
"ui:widget": "DateWidget",
isBeginsDate: true,
},
maximumAmount: {
"ui:widget": "NumberWidget",
Expand Down
16 changes: 16 additions & 0 deletions app/lib/helpers/reportStatusHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ export const getDisplayDueDateString = (
} (${formattedValue})`;
};

export const getDisplayBeginDateString = (
daysUntilDue: number,
weeksUntilDue: number,
selectedDate: DateTime
) => {
if (selectedDate === null) return null;
const formattedValue = selectedDate.toFormat("MMM dd, yyyy");
return daysUntilDue < 0
? `${formattedValue}`
: daysUntilDue > 60
? `Begins in ${weeksUntilDue} weeks (${formattedValue})`
: `Begins in ${daysUntilDue} ${
daysUntilDue === 1 ? "day" : "days"
} (${formattedValue})`;
};

export const getDisplayDateString = (selectedDate: DateTime) => {
if (!selectedDate) return null;
return selectedDate.toFormat("MMM dd, yyyy");
Expand Down
12 changes: 12 additions & 0 deletions app/lib/theme/widgets/DateWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getDaysUntilDue,
getDisplayDueDateString,
getWeeksUntilDue,
getDisplayBeginDateString,
} from "lib/helpers/reportStatusHelpers";

const DateInput = forwardRef<HTMLDivElement, WidgetProps>(
Expand All @@ -30,6 +31,17 @@ const DateInput = forwardRef<HTMLDivElement, WidgetProps>(
return displayDueDateString;
}

if (uiSchema?.isBeginsDate) {
const daysUntilDue = getDaysUntilDue(selectedDate);
const weeksUntilDue = getWeeksUntilDue(selectedDate);
const displayDueDateString = getDisplayBeginDateString(
daysUntilDue,
weeksUntilDue,
selectedDate
);
return displayDueDateString;
}

if (uiSchema?.isReceivedDate) {
const displayReceivedDateString = getDisplayDateString(selectedDate);
return (
Expand Down

0 comments on commit b493875

Please sign in to comment.