|
|
@@ -198,29 +198,53 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
const updated = [...list];
|
|
|
|
|
|
let lastWithDateIndex: number | null = null;
|
|
|
+ let lastYearOnlyIndex: number | null = null;
|
|
|
+
|
|
|
for (let i = updated.length - 1; i >= 0; i--) {
|
|
|
const r = updated[i];
|
|
|
r._instanceId = `r-${instanceCounterRef.current++}`;
|
|
|
- if (isFullDate(r.visitStartDate) && isFullDate(r.visitEndDate)) {
|
|
|
+ if (lastWithDateIndex === null && isFullDate(r.visitStartDate) && isFullDate(r.visitEndDate)) {
|
|
|
lastWithDateIndex = i;
|
|
|
break;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (lastWithDateIndex === null || lastWithDateIndex < oldCount - 1) return updated;
|
|
|
+ if (
|
|
|
+ lastYearOnlyIndex === null &&
|
|
|
+ r.visitStartDate?.year &&
|
|
|
+ !r.visitStartDate?.month
|
|
|
+ ) {
|
|
|
+ lastYearOnlyIndex = i;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- const lastDate: DateValue = updated[lastWithDateIndex].visitEndDate as DateValue;
|
|
|
+ if (lastWithDateIndex !== null && lastWithDateIndex >= oldCount - 1) {
|
|
|
+ const lastDate: DateValue = updated[lastWithDateIndex].visitEndDate as DateValue;
|
|
|
+ for (let i = lastWithDateIndex + 1; i < updated.length; i++) {
|
|
|
+ const r = updated[i];
|
|
|
+ if (!isFullDate(r.visitStartDate) || !isFullDate(r.visitEndDate)) {
|
|
|
+ updated[i] = {
|
|
|
+ ...r,
|
|
|
+ visitStartDate: lastDate,
|
|
|
+ visitEndDate: lastDate
|
|
|
+ };
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return updated;
|
|
|
+ }
|
|
|
|
|
|
- for (let i = lastWithDateIndex + 1; i < updated.length; i++) {
|
|
|
- const r = updated[i];
|
|
|
- if (!isFullDate(r.visitStartDate) || !isFullDate(r.visitEndDate)) {
|
|
|
- updated[i] = {
|
|
|
- ...r,
|
|
|
- _instanceId: `r-${instanceCounterRef.current++}`,
|
|
|
- visitStartDate: lastDate,
|
|
|
- visitEndDate: lastDate
|
|
|
- };
|
|
|
- break;
|
|
|
+ if (lastYearOnlyIndex !== null && lastYearOnlyIndex >= oldCount - 1) {
|
|
|
+ const year = updated[lastYearOnlyIndex].visitStartDate!.year!;
|
|
|
+ for (let i = oldCount; i < updated.length; i++) {
|
|
|
+ const r = updated[i];
|
|
|
+ if (!r.visitStartDate?.year) {
|
|
|
+ updated[i] = {
|
|
|
+ ...r,
|
|
|
+ visitStartDate: { year, month: null, day: null },
|
|
|
+ visitEndDate: { year, month: null, day: null },
|
|
|
+ dateMode: 'approx' as CalendarMode
|
|
|
+ };
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|