Skip to content

Commit 6cffaea

Browse files
jenbeckettweskubo-cgi
and
weskubo-cgi
authored
Ccfri 4362 fix closure table validations (#612)
Co-authored-by: weskubo-cgi <[email protected]>
1 parent eb0d66a commit 6cffaea

File tree

3 files changed

+72
-16
lines changed

3 files changed

+72
-16
lines changed

frontend/src/components/ccfriApplication/group/AddNewFees.vue

+56-12
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,16 @@
329329
v-model="obj.formattedStartDate"
330330
:min="fiscalStartAndEndDates.startDate"
331331
:max="fiscalStartAndEndDates.endDate"
332-
:rules="rules.required"
332+
:rules="[
333+
...rules.required,
334+
rules.min(fiscalStartAndEndDates.startDate, 'Must exceed fiscal year start date'),
335+
rules.max(fiscalStartAndEndDates.endDate, 'Must be before fiscal year end date'),
336+
]"
333337
:disabled="isReadOnly"
334338
:hide-details="isReadOnly"
335-
label="Date"
339+
label="Start Date"
336340
clearable
341+
@input="isDateLegal(obj)"
337342
/>
338343
</v-col>
339344

@@ -342,10 +347,15 @@
342347
v-model="obj.formattedEndDate"
343348
:min="obj.formattedStartDate"
344349
:max="fiscalStartAndEndDates.endDate"
345-
:rules="rules.required"
350+
:rules="[
351+
...rules.required,
352+
rules.min(obj.formattedStartDate, 'Must exceed start date'),
353+
rules.max(fiscalStartAndEndDates.endDate, 'Must be before fiscal year end date'),
354+
]"
346355
:disabled="isReadOnly"
347356
:hide-details="isReadOnly"
348357
clearable
358+
label="End Date"
349359
@input="isDateLegal(obj)"
350360
/>
351361
</v-col>
@@ -375,11 +385,19 @@
375385
</v-col>
376386

377387
<span class="text-white"> . </span>
378-
<v-row v-if="obj.isIllegal">
388+
<v-row v-if="obj.datesOverlap || obj.datesInvalid">
379389
<v-card width="100%" class="mx-3 my-10">
380390
<AppAlertBanner type="error" class="mb-4 w-100">Invalid Dates</AppAlertBanner>
381391

382-
<v-card-text>
392+
<v-card-text v-if="obj.datesInvalid">
393+
Closure Start Date: {{ obj.formattedStartDate }}
394+
<br />
395+
Closure End Date: {{ obj.formattedEndDate }} <br /><br />
396+
397+
Please review your facility closure dates.
398+
<br />
399+
</v-card-text>
400+
<v-card-text v-else-if="obj.datesOverlap">
383401
It appears that the closure start and end dates you've selected for this facility overlap with
384402
dates you've previously selected.
385403
<br /><br />
@@ -390,7 +408,6 @@
390408
Please review your existing facility closure dates to ensure consistency and avoid any potential
391409
overlap of Facility closure dates.
392410
<br />
393-
Thank you for your attention
394411
</v-card-text>
395412
</v-card>
396413
</v-row>
@@ -527,12 +544,12 @@ import alertMixin from '@/mixins/alertMixin.js';
527544
import globalMixin from '@/mixins/globalMixin.js';
528545
import ApiService from '@/common/apiService.js';
529546
547+
//builds an array of dates to keep track of all days of the selected closure period.
548+
//this array is used to check if a user selects an overlapping date
530549
function dateFunction(date1, date2) {
531550
const startDate = new Date(date1);
532551
const endDate = new Date(date2);
533-
534552
const dates = [];
535-
536553
const currentDate = new Date(startDate.getTime());
537554
538555
while (currentDate <= endDate) {
@@ -701,17 +718,44 @@ export default {
701718
});
702719
},
703720
isDateLegal(obj) {
721+
// Get all dates from chosenDates except for the currently edited row
722+
const otherChosenDates = this.CCFRIFacilityModel.dates
723+
.filter((dateObj) => dateObj.id !== obj.id)
724+
.reduce((acc, dateObj) => {
725+
return [...acc, ...dateFunction(dateObj.formattedStartDate, dateObj.formattedEndDate)];
726+
}, []);
727+
704728
const dates = dateFunction(obj.formattedStartDate, obj.formattedEndDate);
705-
obj.isIllegal = false;
706729
730+
//datesOverlap flag is true if the selected dates are part of an overlap of other dates.
731+
//datesInvalid is true if user breaks any other date rule.
732+
733+
//We do not let users save invalid dates of any kind so there is no risk of a mis-calculation in Dynamics
734+
//Rules are: end date cannot be before start date
735+
//start date for either field cannot be before the start of fiscal year
736+
//end dates for either field cannot be after end of fiscal year
737+
738+
if (
739+
obj.formattedEndDate < obj.formattedStartDate ||
740+
obj.formattedStartDate < this.fiscalStartAndEndDates.startDate ||
741+
obj.formattedEndDate < this.fiscalStartAndEndDates.startDate ||
742+
obj.formattedStartDate > this.fiscalStartAndEndDates.endDate ||
743+
obj.formattedEndDate > this.fiscalStartAndEndDates.endDate
744+
) {
745+
obj.datesInvalid = true;
746+
return;
747+
}
748+
749+
obj.datesOverlap = false;
750+
obj.datesInvalid = false;
707751
dates.forEach((date) => {
708-
if (this.chosenDates.includes(date)) {
709-
obj.isIllegal = true;
752+
if (otherChosenDates.includes(date)) {
753+
obj.datesOverlap = true;
710754
}
711755
});
712756
},
713757
hasIllegalDates() {
714-
return this.CCFRIFacilityModel?.dates?.some((el) => el.isIllegal);
758+
return this.CCFRIFacilityModel?.dates?.some((el) => el.datesOverlap || el.datesInvalid);
715759
},
716760
hasDataToDelete() {
717761
//checks all care types for the deleteMe flag. If true, we need to run save regardless if the model has been changed by the user.

frontend/src/components/summary/group/CCFRISummary.vue

+12
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,18 @@
302302
<span class="summary-label">Did parents pay for this closure?</span>
303303
</v-col>
304304
</v-row>
305+
306+
<v-text-field
307+
v-if="ccfri.dates.length === 0"
308+
placeholder="Required"
309+
density="compact"
310+
flat
311+
variant="solo"
312+
hide-details
313+
:rules="rules.required"
314+
readonly
315+
/>
316+
305317
<v-row v-for="(obj, index) in ccfri.dates" :key="index">
306318
<v-col class="col-md-3 col-12 px-0">
307319
<v-text-field

frontend/src/utils/rules.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ const rules = {
2626
return (v) => !v || v > hourFrom || 'Hours To must be after Hours From';
2727
},
2828
notRequired: [() => true],
29-
max(number) {
30-
return (v) => !v || v <= number || 'Max exceeded';
29+
max(number, message = 'Max exceeded') {
30+
return (v) => !v || v <= number || message;
3131
},
32-
min(number) {
33-
return (v) => !v || v >= number || 'Min exceeded';
32+
min(number, message = 'Min exceeded') {
33+
return (v) => !v || v >= number || message;
3434
},
3535
maxLength(number) {
3636
return (v) => !v || v.length <= number || 'Max length exceeded';

0 commit comments

Comments
 (0)