From e477f9f25c84f4e3a18f251a5e42205fc9416994 Mon Sep 17 00:00:00 2001 From: vhu-axelor <146069039+vhu-axelor@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:18:23 +0100 Subject: [PATCH] feat: add possibility to create an event from the planning view --- changelogs/unreleased/87524.json | 5 ++++ .../crm/src/hooks/use-crm-header-actions.ts | 23 +++++++++++++++++++ .../src/screens/event/EventPlanningScreen.js | 7 ++++-- packages/apps/crm/src/screens/event/index.js | 1 + 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/87524.json diff --git a/changelogs/unreleased/87524.json b/changelogs/unreleased/87524.json new file mode 100644 index 0000000000..72e280f046 --- /dev/null +++ b/changelogs/unreleased/87524.json @@ -0,0 +1,5 @@ +{ + "title": "Planning view: add possibility to create an event", + "type": "feat", + "packages": "crm" +} diff --git a/packages/apps/crm/src/hooks/use-crm-header-actions.ts b/packages/apps/crm/src/hooks/use-crm-header-actions.ts index 1cb17a351f..01576e8772 100644 --- a/packages/apps/crm/src/hooks/use-crm-header-actions.ts +++ b/packages/apps/crm/src/hooks/use-crm-header-actions.ts @@ -386,11 +386,34 @@ const useEventDetailsActions = () => { }, [mobileSettings, event]); }; +const useEventPlanningActions = () => { + const I18n = useTranslator(); + const navigation = useNavigation(); + const {canCreate} = usePermitted({modelName: 'com.axelor.apps.crm.db.Event'}); + + useEffect(() => { + headerActionsProvider.registerModel('crm_event_planning', { + actions: [ + { + key: 'event-openEventForm', + order: 10, + iconName: 'calendar-plus-fill', + title: I18n.t('Crm_CreateEvent'), + hideIf: !canCreate, + onPress: () => navigation.navigate('EventFormScreen'), + showInHeader: true, + }, + ], + }); + }, [navigation, canCreate, I18n]); +}; + export const useCRMHeaders = () => { useCatalogListActions(); useClientDetailsActions(); useContactDetailsActions(); useEventDetailsActions(); + useEventPlanningActions(); useLeadListActions(); useLeadDetailsActions(); useOpportunityListActions(); diff --git a/packages/apps/crm/src/screens/event/EventPlanningScreen.js b/packages/apps/crm/src/screens/event/EventPlanningScreen.js index 0c7c7c6254..ab1b03c38a 100644 --- a/packages/apps/crm/src/screens/event/EventPlanningScreen.js +++ b/packages/apps/crm/src/screens/event/EventPlanningScreen.js @@ -23,6 +23,7 @@ import { filterChip, PlanningView, useDispatch, + useIsFocused, useSelector, useTranslator, useTypes, @@ -34,6 +35,7 @@ import {EventSearchBar, PlanningEventCard} from '../../components'; function EventPlanningScreen({navigation}) { const dispatch = useDispatch(); const I18n = useTranslator(); + const isFocused = useIsFocused(); const {Event} = useTypes(); const {getItemColor, getSelectionItems} = useTypeHelpers(); @@ -77,9 +79,10 @@ function EventPlanningScreen({navigation}) { const fetchItemsByMonth = useCallback( date => { dateSave === null && setDateSave(date); - dispatch(fetchPlannedEvent({date: date, searchValue: filter})); + isFocused && + dispatch(fetchPlannedEvent({date: date, searchValue: filter})); }, - [dispatch, dateSave, filter], + [dispatch, dateSave, filter, isFocused], ); const filterOnStatus = useCallback( diff --git a/packages/apps/crm/src/screens/event/index.js b/packages/apps/crm/src/screens/event/index.js index fe368df72e..43d332b3af 100644 --- a/packages/apps/crm/src/screens/event/index.js +++ b/packages/apps/crm/src/screens/event/index.js @@ -24,6 +24,7 @@ export default { EventPlanningScreen: { title: 'Crm_Events', component: EventPlanningScreen, + actionID: 'crm_event_planning', options: { shadedHeader: false, },