Skip to content

Commit

Permalink
feat: add possibility to create an event from the planning view
Browse files Browse the repository at this point in the history
  • Loading branch information
vhu-axelor committed Dec 11, 2024
1 parent 0383600 commit e477f9f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
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"
}
23 changes: 23 additions & 0 deletions packages/apps/crm/src/hooks/use-crm-header-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions packages/apps/crm/src/screens/event/EventPlanningScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
filterChip,
PlanningView,
useDispatch,
useIsFocused,
useSelector,
useTranslator,
useTypes,
Expand All @@ -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();

Expand Down Expand Up @@ -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(
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 e477f9f

Please sign in to comment.