Skip to content

Commit

Permalink
feat: add possibility to create an event from the planning view (#837)
Browse files Browse the repository at this point in the history
* RM#87524
  • Loading branch information
vhu-axelor authored Dec 17, 2024
1 parent c069c5a commit 502a653
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelogs/unreleased/87524.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "Planning view: add possibility to create an event",
"type": "feat",
"packages": "crm"
}
3 changes: 3 additions & 0 deletions packages/apps/crm/src/features/eventSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
},
Expand Down
4 changes: 3 additions & 1 deletion packages/apps/crm/src/screens/event/EventFormScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -112,11 +113,12 @@ const EventFormScreen = ({navigation, route}) => {
createEvent({
event: _event,
tourlineData: tourlineData,
eventPlanningDate,
}),
);
navigation.pop();
},
[navigation, tourlineData],
[eventPlanningDate, navigation, tourlineData],
);

const updateEventAPI = useCallback(
Expand Down
22 changes: 22 additions & 0 deletions packages/apps/crm/src/screens/event/EventPlanningScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -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 (
<Screen removeSpaceOnTop={true}>
<HeaderContainer
Expand Down
1 change: 1 addition & 0 deletions packages/apps/crm/src/screens/event/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default {
EventPlanningScreen: {
title: 'Crm_Events',
component: EventPlanningScreen,
actionID: 'crm_event_planning',
options: {
shadedHeader: false,
},
Expand Down

0 comments on commit 502a653

Please sign in to comment.