|
@@ -1,4 +1,4 @@
|
|
-import React, { useState } from 'react';
|
|
|
|
|
|
+import React, { useEffect, useState } from 'react';
|
|
import { View } from 'react-native';
|
|
import { View } from 'react-native';
|
|
import moment from 'moment';
|
|
import moment from 'moment';
|
|
import { Modal } from '../../Modal';
|
|
import { Modal } from '../../Modal';
|
|
@@ -14,14 +14,24 @@ export default function RangeCalendar({
|
|
closeModal,
|
|
closeModal,
|
|
allowRangeSelection = true,
|
|
allowRangeSelection = true,
|
|
disableFutureDates = false,
|
|
disableFutureDates = false,
|
|
|
|
+ highlightedDates,
|
|
|
|
+ selectedDate
|
|
}: {
|
|
}: {
|
|
isModalVisible: boolean;
|
|
isModalVisible: boolean;
|
|
- closeModal: (startDate?: Date | null, endDate?: Date | null) => void;
|
|
|
|
|
|
+ closeModal: (startDate?: string | null, endDate?: string | null) => void;
|
|
allowRangeSelection?: boolean;
|
|
allowRangeSelection?: boolean;
|
|
disableFutureDates?: boolean;
|
|
disableFutureDates?: boolean;
|
|
|
|
+ highlightedDates?: string[];
|
|
|
|
+ selectedDate?: string;
|
|
}) {
|
|
}) {
|
|
- const [selectedStartDate, setSelectedStartDate] = useState<Date | null>(null);
|
|
|
|
- const [selectedEndDate, setSelectedEndDate] = useState<Date | null>(null);
|
|
|
|
|
|
+ const [selectedStartDate, setSelectedStartDate] = useState<string | null>(null);
|
|
|
|
+ const [selectedEndDate, setSelectedEndDate] = useState<string | null>(null);
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if (selectedDate) {
|
|
|
|
+ setSelectedStartDate(selectedDate);
|
|
|
|
+ }
|
|
|
|
+ }, [selectedDate]);
|
|
|
|
|
|
const customThemeStyles = {
|
|
const customThemeStyles = {
|
|
textSectionTitleColor: Colors.ORANGE,
|
|
textSectionTitleColor: Colors.ORANGE,
|
|
@@ -66,6 +76,15 @@ export default function RangeCalendar({
|
|
const marked: { [key: string]: any } = {};
|
|
const marked: { [key: string]: any } = {};
|
|
let start = selectedStartDate as unknown as string;
|
|
let start = selectedStartDate as unknown as string;
|
|
let end = selectedEndDate as unknown as string;
|
|
let end = selectedEndDate as unknown as string;
|
|
|
|
+ if (selectedDate && !selectedStartDate) {
|
|
|
|
+ marked[selectedDate] = {
|
|
|
|
+ selected: true,
|
|
|
|
+ startingDay: true,
|
|
|
|
+ endingDay: true,
|
|
|
|
+ color: Colors.ORANGE,
|
|
|
|
+ textColor: 'white',
|
|
|
|
+ };
|
|
|
|
+ }
|
|
if (disableFutureDates) {
|
|
if (disableFutureDates) {
|
|
const today = moment().add(1, 'day');
|
|
const today = moment().add(1, 'day');
|
|
const lastDay = moment().add(2, 'years');
|
|
const lastDay = moment().add(2, 'years');
|
|
@@ -77,6 +96,20 @@ export default function RangeCalendar({
|
|
today.add(1, 'day');
|
|
today.add(1, 'day');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if (highlightedDates) {
|
|
|
|
+ const datesSet = new Set(highlightedDates);
|
|
|
|
+
|
|
|
|
+ const startDateMoment = moment(highlightedDates[0]);
|
|
|
|
+ const endDateMoment = moment(highlightedDates[highlightedDates.length - 1]);
|
|
|
|
+
|
|
|
|
+ for (let m = moment(startDateMoment); m.diff(endDateMoment, 'days') <= 0; m.add(1, 'days')) {
|
|
|
|
+ const dateString = m.format('YYYY-MM-DD');
|
|
|
|
+ if (!datesSet.has(dateString)) {
|
|
|
|
+ marked[dateString] = { disableTouchEvent: true, disabled: true };
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
if (start && end) {
|
|
if (start && end) {
|
|
marked[start] = { startingDay: true, color: Colors.ORANGE, textColor: 'white' };
|
|
marked[start] = { startingDay: true, color: Colors.ORANGE, textColor: 'white' };
|
|
let day = start;
|
|
let day = start;
|
|
@@ -129,6 +162,9 @@ export default function RangeCalendar({
|
|
theme={{
|
|
theme={{
|
|
...customThemeStyles,
|
|
...customThemeStyles,
|
|
}}
|
|
}}
|
|
|
|
+ minDate={highlightedDates ? highlightedDates[0] : undefined}
|
|
|
|
+ maxDate={highlightedDates ? highlightedDates[highlightedDates.length - 1] : undefined}
|
|
|
|
+ current={selectedDate}
|
|
/>
|
|
/>
|
|
</View>
|
|
</View>
|
|
<View style={styles.modalFooter}>
|
|
<View style={styles.modalFooter}>
|