From 502a65324ef91f90fbd650373145eee4b24fd081 Mon Sep 17 00:00:00 2001 From: vhu-axelor <146069039+vhu-axelor@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:22:16 +0100 Subject: [PATCH] feat: add possibility to create an event from the planning view (#837) * RM#87524 --- changelogs/unreleased/87524.json | 5 +++++ packages/apps/crm/src/features/eventSlice.js | 3 +++ .../crm/src/screens/event/EventFormScreen.js | 4 +++- .../src/screens/event/EventPlanningScreen.js | 22 +++++++++++++++++++ packages/apps/crm/src/screens/event/index.js | 1 + 5 files changed, 34 insertions(+), 1 deletion(-) 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/features/eventSlice.js b/packages/apps/crm/src/features/eventSlice.js index 4af9509876..8afec0e7ca 100644 --- a/packages/apps/crm/src/features/eventSlice.js +++ b/packages/apps/crm/src/features/eventSlice.js @@ -114,6 +114,9 @@ export const createEvent = createAsyncThunk( if (data?.event?.isLead) { dispatch(fetchLeadById({leadId: data?.event?.eventLead?.id})); } + if (data?.eventPlanningDate) { + dispatch(fetchPlannedEvent({date: new Date(data?.eventPlanningDate)})); + } return res; }); }, diff --git a/packages/apps/crm/src/screens/event/EventFormScreen.js b/packages/apps/crm/src/screens/event/EventFormScreen.js index 6616c9dd8e..cf9b79147a 100644 --- a/packages/apps/crm/src/screens/event/EventFormScreen.js +++ b/packages/apps/crm/src/screens/event/EventFormScreen.js @@ -32,6 +32,7 @@ const EventFormScreen = ({navigation, route}) => { const client = route?.params?.client; const contact = route?.params?.contact; const tourlineData = route?.params?.tourlineData; + const eventPlanningDate = route?.params?.eventPlanningDate; const {Event} = useTypes(); @@ -112,11 +113,12 @@ const EventFormScreen = ({navigation, route}) => { createEvent({ event: _event, tourlineData: tourlineData, + eventPlanningDate, }), ); navigation.pop(); }, - [navigation, tourlineData], + [eventPlanningDate, navigation, tourlineData], ); const updateEventAPI = useCallback( diff --git a/packages/apps/crm/src/screens/event/EventPlanningScreen.js b/packages/apps/crm/src/screens/event/EventPlanningScreen.js index 0c7c7c6254..8dc353f28d 100644 --- a/packages/apps/crm/src/screens/event/EventPlanningScreen.js +++ b/packages/apps/crm/src/screens/event/EventPlanningScreen.js @@ -21,8 +21,10 @@ import {StyleSheet, View} from 'react-native'; import {Screen, HeaderContainer, MultiValuePicker} from '@axelor/aos-mobile-ui'; import { filterChip, + headerActionsProvider, PlanningView, useDispatch, + usePermitted, useSelector, useTranslator, useTypes, @@ -36,6 +38,7 @@ function EventPlanningScreen({navigation}) { const I18n = useTranslator(); const {Event} = useTypes(); const {getItemColor, getSelectionItems} = useTypeHelpers(); + const {canCreate} = usePermitted({modelName: 'com.axelor.apps.crm.db.Event'}); const {eventList, loading} = useSelector(state => state.event); @@ -143,6 +146,25 @@ function EventPlanningScreen({navigation}) { setFilteredList(filterOnStatus(eventList)); }, [filterOnStatus, eventList]); + 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', { + eventPlanningDate: dateSave.toDateString(), + }), + showInHeader: true, + }, + ], + }); + }, [I18n, canCreate, dateSave, navigation]); + return (