From 7fc641d12a7dd3b360893ddbc993f7167d41fbe0 Mon Sep 17 00:00:00 2001 From: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> Date: Wed, 7 Dec 2022 18:52:37 +0530 Subject: [PATCH] Exposed current view when changing the value of the default value property (#4786) --- frontend/src/Editor/Components/Calendar.jsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/frontend/src/Editor/Components/Calendar.jsx b/frontend/src/Editor/Components/Calendar.jsx index bbd8c4ce8a..824fe7a766 100644 --- a/frontend/src/Editor/Components/Calendar.jsx +++ b/frontend/src/Editor/Components/Calendar.jsx @@ -51,6 +51,7 @@ export const Calendar = function ({ const [currentDate, setCurrentDate] = useState(defaultDate); const [eventPopoverOptions, setEventPopoverOptions] = useState({ show: false }); + const [defaultView, setDefaultValue] = useState(allowedCalendarViews[0]); const eventPropGetter = (event) => { const backgroundColor = event.color; @@ -88,9 +89,16 @@ export const Calendar = function ({ }); } - const defaultView = allowedCalendarViews.includes(properties.defaultView) - ? properties.defaultView - : allowedCalendarViews[0]; + useEffect(() => { + const view = allowedCalendarViews.includes(properties.defaultView) + ? properties.defaultView + : allowedCalendarViews[0]; + if (exposedVariables.currentView !== view) { + setDefaultValue(view); + setExposedVariable('currentView', view); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [properties.defaultView]); useEffect(() => { //check if the default date is a valid date @@ -132,7 +140,9 @@ export const Calendar = function ({ style={style} views={allowedCalendarViews} defaultView={defaultView} + view={defaultView} onView={(view) => { + setDefaultValue(view); setExposedVariable('currentView', view); fireEvent('onCalendarViewChange'); }}