Skip to content

Commit

Permalink
Issue #000 chore: Resolved When a user cancels selecting a custom ran…
Browse files Browse the repository at this point in the history
…ge, the custom range filter should not get selected and applied
  • Loading branch information
Rushikesh-Sonawane99 committed Jun 4, 2024
1 parent 538bac0 commit 4fbb757
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/components/DateRangePopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Modal,
Select,
Typography,
useStepContext,
} from '@mui/material';
import React, { useState } from 'react';
import { getDayAndMonthName, getTodayDate } from '@/utils/Helper';
Expand Down Expand Up @@ -79,6 +80,7 @@ const DateRangePopup: React.FC<CustomSelectModalProps> = ({
const [displayCalendarToDate, setDisplayCalendarToDate] = React.useState(
getDayAndMonthName(getTodayDate())
);
const [cancelClicked, setCancelClicked] = React.useState(false)

const toggleModal = () => setIsModalOpen(!isModalOpen);
const toggleCalendarModal = () =>
Expand All @@ -91,18 +93,24 @@ const DateRangePopup: React.FC<CustomSelectModalProps> = ({
if (index === 4) {
toggleCalendarModal();
}
if (index === 4) {
toggleCalendarModal();
}
};
const handleCancelClicked = ()=>{
toggleCalendarModal();
setCancelClicked(true)
}

const onApply = () => {
console.log('applied', selectedIndex, selectedValue);
const values = getDateRange(selectedIndex);
const { toDate, fromDate } = values;
console.log(toDate, fromDate);
onDateRangeSelected({ fromDate, toDate });
toggleModal();
if (cancelClicked){
toggleModal();
setCancelClicked(false)
}else{
console.log('applied', selectedIndex, selectedValue);
const values = getDateRange(selectedIndex);
const { toDate, fromDate } = values;
console.log(toDate, fromDate);
onDateRangeSelected({ fromDate, toDate });
toggleModal();
}
};

const getDateRange = (index: number | null) => {
Expand Down Expand Up @@ -264,7 +272,7 @@ const DateRangePopup: React.FC<CustomSelectModalProps> = ({
</Box>
</Modal>

{/* CustomeCalendarModal */}
{/* Custom CalendarModal */}
<Modal
open={isCalendarModalOpen}
onClose={toggleCalendarModal}
Expand All @@ -287,15 +295,15 @@ const DateRangePopup: React.FC<CustomSelectModalProps> = ({
>
<Box>
<WestIcon
onClick={toggleCalendarModal}
onClick={()=> handleCancelClicked()}
style={{ cursor: 'pointer' }}
/>
</Box>
<Box className="text-4D">{t('COMMON.CUSTOM_RANGE')}</Box>
</Box>
<Box>
<CloseIcon
onClick={toggleCalendarModal}
onClick={()=> handleCancelClicked()}
style={{ cursor: 'pointer' }}
/>
</Box>
Expand Down Expand Up @@ -324,7 +332,7 @@ const DateRangePopup: React.FC<CustomSelectModalProps> = ({
justifyContent: 'end',
}}
>
<Box className="text-0D fs-14 fw-500" onClick={toggleCalendarModal}>
<Box className="text-0D fs-14 fw-500" onClick={()=> handleCancelClicked()}>
{t('COMMON.CANCEL')}
</Box>
<Box className="text-0D fs-14 fw-500" onClick={toggleCalendarModal}>
Expand Down

0 comments on commit 4fbb757

Please sign in to comment.