Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add possibility to create an event from the planning view #837

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading