Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevents settings menu from closing while clicking on calendar #113

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/components/layouts/SettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ const RealtimeRentMenuItem: FC = () => {
)
}

const RealtimeRentMenuSelectDate: FC = () => {
const RealtimeRentMenuSelectDate: FC<{
isCalendarOpen: boolean
setIsCalendarOpen: (open: boolean) => void
}> = ({ isCalendarOpen, setIsCalendarOpen }) => {
const dispatch = useDispatch()
const rentCalculation = useSelector(selectUserRentCalculation)

const { i18n, t } = useTranslation('common', { keyPrefix: 'settings' })

if (rentCalculation.state !== RentCalculationState.Realtime) return null
Expand All @@ -162,28 +164,39 @@ const RealtimeRentMenuSelectDate: FC = () => {
}),
)
}
const toggleIsCalendarOpen = () => setIsCalendarOpen(!isCalendarOpen)

return (
<>
<Menu.Label pb={0}>{t('date')}</Menu.Label>
<DatePickerInput
p={5}
onClick={() => toggleIsCalendarOpen()}
locale={i18n.language}
valueFormat={t('dateFormat')}
value={new Date(rentCalculation.date)}
onChange={(value) => handleDateChange(value as Date)}
onChange={(value) => {
handleDateChange(value as Date)
toggleIsCalendarOpen()
}}
defaultDate={new Date()}
/>
<Menu.Divider />
</>
)
}

const RealtimeRentMenu = () => {
const RealtimeRentMenu: FC<{
isCalendarOpen: boolean
setIsCalendarOpen: (open: boolean) => void
}> = ({ isCalendarOpen, setIsCalendarOpen }) => {
return (
<>
<RealtimeRentMenuItem />
<RealtimeRentMenuSelectDate />
<RealtimeRentMenuSelectDate
isCalendarOpen={isCalendarOpen}
setIsCalendarOpen={setIsCalendarOpen}
/>
<Menu.Divider />
</>
)
Expand Down Expand Up @@ -341,10 +354,13 @@ const RefreshDataButton: FC = () => {
export const SettingsMenu: FC = () => {
const [isOpen, handlers] = useDisclosure(false)
const version = useSelector(selectVersion)
// Prevent menu from closing when the calendar is open
const [isCalendarOpen, setIsCalendarOpen] = useState(false)

return (
<Menu
closeOnItemClick={false}
closeOnClickOutside={!isCalendarOpen}
opened={isOpen}
onOpen={handlers.open}
onClose={handlers.close}
Expand All @@ -359,7 +375,10 @@ export const SettingsMenu: FC = () => {
<Menu.Divider />
<CurrencySelect />
<Menu.Divider />
<RealtimeRentMenu />
<RealtimeRentMenu
isCalendarOpen={isCalendarOpen}
setIsCalendarOpen={setIsCalendarOpen}
/>
<ColorSchemeMenuItem />
<Menu.Divider />
<FetchDataSettings />
Expand Down
Loading