@selfcommunity/react-ui 0.8.0-alpha.1 → 0.8.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/EventForm/EventAddress.d.ts +3 -8
- package/lib/cjs/components/EventForm/EventAddress.js +20 -20
- package/lib/cjs/components/EventForm/EventForm.js +23 -27
- package/lib/cjs/components/EventForm/types.d.ts +28 -0
- package/lib/cjs/components/EventForm/types.js +2 -0
- package/lib/cjs/components/EventHeader/EventHeader.js +1 -1
- package/lib/cjs/components/Events/Events.js +6 -1
- package/lib/cjs/components/MyEventsWidget/MyEventsWidget.js +28 -0
- package/lib/cjs/components/SuggestedEventsWidget/SuggestedEventsWidget.js +26 -0
- package/lib/cjs/shared/EventActionsMenu/index.d.ts +4 -0
- package/lib/cjs/shared/EventActionsMenu/index.js +13 -3
- package/lib/esm/components/EventForm/EventAddress.d.ts +3 -8
- package/lib/esm/components/EventForm/EventAddress.js +20 -20
- package/lib/esm/components/EventForm/EventForm.js +23 -27
- package/lib/esm/components/EventForm/types.d.ts +28 -0
- package/lib/esm/components/EventForm/types.js +1 -0
- package/lib/esm/components/EventHeader/EventHeader.js +1 -1
- package/lib/esm/components/Events/Events.js +6 -1
- package/lib/esm/components/MyEventsWidget/MyEventsWidget.js +29 -1
- package/lib/esm/components/SuggestedEventsWidget/SuggestedEventsWidget.js +27 -1
- package/lib/esm/shared/EventActionsMenu/index.d.ts +4 -0
- package/lib/esm/shared/EventActionsMenu/index.js +13 -3
- package/lib/umd/react-ui.js +1 -1
- package/package.json +4 -4
|
@@ -123,23 +123,23 @@ export default function EventForm(inProps) {
|
|
|
123
123
|
// INTL
|
|
124
124
|
const intl = useIntl();
|
|
125
125
|
const initialFieldState = {
|
|
126
|
-
imageOriginal: event ? event.image_bigger
|
|
127
|
-
imageOriginalFile:
|
|
126
|
+
imageOriginal: (event === null || event === void 0 ? void 0 : event.image_bigger) || '',
|
|
127
|
+
imageOriginalFile: new Blob(),
|
|
128
128
|
startDate: event ? new Date(event.start_date) : null,
|
|
129
129
|
startTime: event ? new Date(event.start_date) : null,
|
|
130
|
-
endDate: event
|
|
131
|
-
endTime: event
|
|
132
|
-
location: event ? event.location
|
|
133
|
-
geolocation: event ? event.geolocation
|
|
134
|
-
lat: event ? event.geolocation_lat
|
|
135
|
-
lng: event ? event.geolocation_lng
|
|
136
|
-
link: event ? event.link
|
|
137
|
-
recurring: event ? event.recurring
|
|
138
|
-
name: event ? event.name
|
|
130
|
+
endDate: (event === null || event === void 0 ? void 0 : event.end_date) ? new Date(event.end_date) : null,
|
|
131
|
+
endTime: (event === null || event === void 0 ? void 0 : event.end_date) ? new Date(event.end_date) : null,
|
|
132
|
+
location: (event === null || event === void 0 ? void 0 : event.location) || SCEventLocationType.PERSON,
|
|
133
|
+
geolocation: (event === null || event === void 0 ? void 0 : event.geolocation) || '',
|
|
134
|
+
lat: (event === null || event === void 0 ? void 0 : event.geolocation_lat) || null,
|
|
135
|
+
lng: (event === null || event === void 0 ? void 0 : event.geolocation_lng) || null,
|
|
136
|
+
link: (event === null || event === void 0 ? void 0 : event.link) || '',
|
|
137
|
+
recurring: (event === null || event === void 0 ? void 0 : event.recurring) || SCEventRecurrenceType.NEVER,
|
|
138
|
+
name: (event === null || event === void 0 ? void 0 : event.name) || '',
|
|
139
139
|
description: event ? event.description : '',
|
|
140
|
-
isPublic: (_a = (event
|
|
140
|
+
isPublic: (_a = (event === null || event === void 0 ? void 0 : event.privacy) === SCEventPrivacyType.PUBLIC) !== null && _a !== void 0 ? _a : true,
|
|
141
141
|
isSubmitting: false,
|
|
142
|
-
showEndDateTime: (_b = (event
|
|
142
|
+
showEndDateTime: (_b = !!(event === null || event === void 0 ? void 0 : event.end_date)) !== null && _b !== void 0 ? _b : false
|
|
143
143
|
};
|
|
144
144
|
// STATE
|
|
145
145
|
const [field, setField] = useState(initialFieldState);
|
|
@@ -213,14 +213,14 @@ export default function EventForm(inProps) {
|
|
|
213
213
|
}
|
|
214
214
|
if (field.location === SCEventLocationType.PERSON) {
|
|
215
215
|
formData.append('geolocation', field.geolocation);
|
|
216
|
-
formData.append('geolocation_lat', field.lat);
|
|
217
|
-
formData.append('geolocation_lng', field.lng);
|
|
216
|
+
formData.append('geolocation_lat', field.lat.toString());
|
|
217
|
+
formData.append('geolocation_lng', field.lng.toString());
|
|
218
218
|
}
|
|
219
219
|
if (privateEnabled) {
|
|
220
220
|
formData.append('privacy', field.isPublic ? SCEventPrivacyType.PUBLIC : SCEventPrivacyType.PRIVATE);
|
|
221
221
|
}
|
|
222
222
|
if (visibilityEnabled) {
|
|
223
|
-
formData.append('visible', true);
|
|
223
|
+
formData.append('visible', 'true');
|
|
224
224
|
}
|
|
225
225
|
formData.append('description', field.description);
|
|
226
226
|
let eventService;
|
|
@@ -232,9 +232,9 @@ export default function EventForm(inProps) {
|
|
|
232
232
|
}
|
|
233
233
|
eventService
|
|
234
234
|
.then((data) => {
|
|
235
|
-
onSuccess
|
|
235
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
236
236
|
notifyChanges(data);
|
|
237
|
-
onClose
|
|
237
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
238
238
|
setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: false })));
|
|
239
239
|
})
|
|
240
240
|
.catch((e) => {
|
|
@@ -308,15 +308,11 @@ export default function EventForm(inProps) {
|
|
|
308
308
|
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
309
309
|
// @ts-ignore
|
|
310
310
|
b: (chunks) => _jsx("strong", { children: chunks })
|
|
311
|
-
} })) : (_jsx(
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
317
|
-
// @ts-ignore
|
|
318
|
-
b: (chunks) => _jsx("strong", { children: chunks })
|
|
319
|
-
} })) })) }))] }))), _jsx(TextField, { multiline: true, className: classes.description, placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: {
|
|
311
|
+
} })) : (_jsx(FormattedMessage, { id: "ui.eventForm.privacy.private.info", defaultMessage: "ui.eventForm.private.public.info", values: {
|
|
312
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
313
|
+
// @ts-ignore
|
|
314
|
+
b: (chunks) => _jsx("strong", { children: chunks })
|
|
315
|
+
} })) }))] }))), _jsx(TextField, { multiline: true, className: classes.description, placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: {
|
|
320
316
|
endAdornment: (_jsx(Typography, Object.assign({ variant: "body2" }, { children: ((_e = field.description) === null || _e === void 0 ? void 0 : _e.length) ? EVENT_DESCRIPTION_MAX_LENGTH - field.description.length : EVENT_DESCRIPTION_MAX_LENGTH })))
|
|
321
317
|
}, error: Boolean(((_f = field.description) === null || _f === void 0 ? void 0 : _f.length) > EVENT_DESCRIPTION_MAX_LENGTH), helperText: ((_g = field.description) === null || _g === void 0 ? void 0 : _g.length) > EVENT_DESCRIPTION_MAX_LENGTH ? (_jsx(FormattedMessage, { id: "ui.eventForm.description.error.maxLength", defaultMessage: "ui.eventForm.description.error.maxLength" })) : null })] }))] }) })));
|
|
322
318
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SCEventLocationType, SCEventRecurrenceType } from '@selfcommunity/types';
|
|
2
|
+
export declare type Place = {
|
|
3
|
+
description: string;
|
|
4
|
+
id?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare type Geolocation = {
|
|
7
|
+
location: SCEventLocationType;
|
|
8
|
+
geolocation?: string;
|
|
9
|
+
lat?: number;
|
|
10
|
+
lng?: number;
|
|
11
|
+
link?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare type InitialFieldState = Geolocation & {
|
|
14
|
+
imageOriginal: string | ArrayBuffer;
|
|
15
|
+
imageOriginalFile: Blob;
|
|
16
|
+
startDate: Date | null;
|
|
17
|
+
startTime: Date | null;
|
|
18
|
+
endDate: Date | null;
|
|
19
|
+
endTime: Date | null;
|
|
20
|
+
recurring: SCEventRecurrenceType;
|
|
21
|
+
name: string;
|
|
22
|
+
description: string;
|
|
23
|
+
isPublic: boolean;
|
|
24
|
+
isSubmitting: boolean;
|
|
25
|
+
showEndDateTime: boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare type FieldStateKeys = keyof InitialFieldState;
|
|
28
|
+
export declare type FieldStateValues = InitialFieldState[FieldStateKeys];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -174,5 +174,5 @@ export default function EventHeader(inProps) {
|
|
|
174
174
|
month: 'long'
|
|
175
175
|
}),
|
|
176
176
|
hour: intl.formatDate(scEvent.start_date, { hour: 'numeric', minute: 'numeric' })
|
|
177
|
-
} })) })), _jsx(Typography, Object.assign({ variant: "h5", className: classes.name }, { children: scEvent.name })), _jsxs(Box, Object.assign({ className: classes.visibility }, { children: [_jsx(_Fragment, { children: scEvent.privacy === SCEventPrivacyType.PUBLIC ? (_jsxs(Typography, Object.assign({ className: classes.visibilityItem }, { children: [_jsx(Icon, { children: "public" }), _jsx(FormattedMessage, { id: "ui.eventHeader.visibility.public", defaultMessage: "ui.eventHeader.visibility.public" })] }))) : (_jsxs(Typography, Object.assign({ className: classes.visibilityItem }, { children: [_jsx(Icon, { children: "private" }), _jsx(FormattedMessage, { id: "ui.eventHeader.visibility.private", defaultMessage: "ui.eventHeader.visibility.private" })] }))) }), _jsx(Bullet, {}), _jsx(Typography, Object.assign({ className: classes.visibilityItem }, { children: scEvent.location === SCEventLocationType.PERSON ? (_jsx(FormattedMessage, { id: "ui.eventHeader.location.live", defaultMessage: "ui.eventHeader.location.live" })) : (_jsx(FormattedMessage, { id: "ui.eventHeader.location.online", defaultMessage: "ui.eventHeader.location.online" })) }))] })), _jsx(User, { className: classes.planner, userId: scEvent.managed_by.id, secondary: _jsx(FormattedMessage, { id: "ui.eventHeader.user.manager", defaultMessage: "ui.eventHeader.user.manager" }), elevation: 0, actions: _jsx(_Fragment, { children: isEventAdmin ? (_jsxs(Box, Object.assign({ className: classes.multiActions }, { children: [_jsx(EventInviteButton, { size: isMobile ? 'small' : 'medium', event: scEvent, eventId: scEvent.id, disabled: isEventFinished }), _jsxs(Box, { children: [_jsx(EditEventButton, { size: isMobile ? 'small' : 'medium', event: scEvent, eventId: scEvent.id, onEditSuccess: (data) => setSCEvent(data), disabled: isEventFinished }), _jsx(EventActionsMenu, Object.assign({ event: scEvent }, EventActionsProps))] })] }))) : (_jsxs(_Fragment, { children: [_jsx(EventSubscribeButton, Object.assign({ event: scEvent, onSubscribe: handleSubscribe }, EventSubscribeButtonProps, { disabled: isEventFinished })), _jsx(EventActionsMenu, Object.assign({ event: scEvent }, EventActionsProps))] })) }) })] }))] })));
|
|
177
|
+
} })) })), _jsx(Typography, Object.assign({ variant: "h5", className: classes.name }, { children: scEvent.name })), _jsxs(Box, Object.assign({ className: classes.visibility }, { children: [_jsx(_Fragment, { children: scEvent.privacy === SCEventPrivacyType.PUBLIC ? (_jsxs(Typography, Object.assign({ className: classes.visibilityItem }, { children: [_jsx(Icon, { children: "public" }), _jsx(FormattedMessage, { id: "ui.eventHeader.visibility.public", defaultMessage: "ui.eventHeader.visibility.public" })] }))) : (_jsxs(Typography, Object.assign({ className: classes.visibilityItem }, { children: [_jsx(Icon, { children: "private" }), _jsx(FormattedMessage, { id: "ui.eventHeader.visibility.private", defaultMessage: "ui.eventHeader.visibility.private" })] }))) }), _jsx(Bullet, {}), _jsx(Typography, Object.assign({ className: classes.visibilityItem }, { children: scEvent.location === SCEventLocationType.PERSON ? (_jsx(FormattedMessage, { id: "ui.eventHeader.location.live", defaultMessage: "ui.eventHeader.location.live" })) : (_jsx(FormattedMessage, { id: "ui.eventHeader.location.online", defaultMessage: "ui.eventHeader.location.online" })) }))] })), _jsx(User, { className: classes.planner, userId: scEvent.managed_by.id, secondary: _jsx(FormattedMessage, { id: "ui.eventHeader.user.manager", defaultMessage: "ui.eventHeader.user.manager" }), elevation: 0, actions: _jsx(_Fragment, { children: isEventAdmin ? (_jsxs(Box, Object.assign({ className: classes.multiActions }, { children: [_jsx(EventInviteButton, { size: isMobile ? 'small' : 'medium', event: scEvent, eventId: scEvent.id, disabled: isEventFinished }), _jsxs(Box, { children: [!isMobile && (_jsx(EditEventButton, { size: isMobile ? 'small' : 'medium', event: scEvent, eventId: scEvent.id, onEditSuccess: (data) => setSCEvent(data), disabled: isEventFinished })), _jsx(EventActionsMenu, Object.assign({ event: scEvent, onEditSuccess: (data) => setSCEvent(data) }, EventActionsProps))] })] }))) : (_jsxs(_Fragment, { children: [_jsx(EventSubscribeButton, Object.assign({ event: scEvent, onSubscribe: handleSubscribe }, EventSubscribeButtonProps, { disabled: isEventFinished })), _jsx(EventActionsMenu, Object.assign({ event: scEvent, onEditSuccess: (data) => setSCEvent(data) }, EventActionsProps))] })) }) })] }))] })));
|
|
178
178
|
}
|
|
@@ -151,7 +151,12 @@ export default function Events(inProps) {
|
|
|
151
151
|
* Subscriber for pubsub callback
|
|
152
152
|
*/
|
|
153
153
|
const onDeleteEventHandler = useCallback((_msg, deleted) => {
|
|
154
|
-
setEvents((prev) =>
|
|
154
|
+
setEvents((prev) => {
|
|
155
|
+
if (prev.some((e) => e.id === deleted)) {
|
|
156
|
+
return prev.filter((e) => e.id !== deleted);
|
|
157
|
+
}
|
|
158
|
+
return prev;
|
|
159
|
+
});
|
|
155
160
|
}, [events]);
|
|
156
161
|
/**
|
|
157
162
|
* On mount, subscribe to receive event updates (only delete)
|
|
@@ -7,7 +7,7 @@ import { Endpoints, EventService, http } from '@selfcommunity/api-services';
|
|
|
7
7
|
import { SCCache, SCRoutes, useSCPreferences, useSCRouting, useSCUser } from '@selfcommunity/react-core';
|
|
8
8
|
import { SCEventSubscriptionStatusType, SCFeatureName } from '@selfcommunity/types';
|
|
9
9
|
import { Logger } from '@selfcommunity/utils';
|
|
10
|
-
import { useCallback, useEffect, useMemo, useReducer, useState } from 'react';
|
|
10
|
+
import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react';
|
|
11
11
|
import { FormattedMessage } from 'react-intl';
|
|
12
12
|
import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
13
13
|
import { DEFAULT_PAGINATION_LIMIT, DEFAULT_PAGINATION_OFFSET } from '../../constants/Pagination';
|
|
@@ -18,6 +18,8 @@ import Event from '../Event';
|
|
|
18
18
|
import Widget from '../Widget';
|
|
19
19
|
import { PREFIX } from './constants';
|
|
20
20
|
import Skeleton from './Skeleton';
|
|
21
|
+
import PubSub from 'pubsub-js';
|
|
22
|
+
import { SCGroupEventType, SCTopicType } from '../../constants/PubSub';
|
|
21
23
|
const classes = {
|
|
22
24
|
root: `${PREFIX}-root`,
|
|
23
25
|
titleWrapper: `${PREFIX}-title-wrapper`,
|
|
@@ -64,6 +66,8 @@ export default function MyEventsWidget(inProps) {
|
|
|
64
66
|
const scRoutingContext = useSCRouting();
|
|
65
67
|
const { features } = useSCPreferences();
|
|
66
68
|
const eventsEnabled = useMemo(() => features && features.includes(SCFeatureName.EVENT) && features.includes(SCFeatureName.TAGGING), [features]);
|
|
69
|
+
// REFS
|
|
70
|
+
const updatesSubscription = useRef(null);
|
|
67
71
|
/**
|
|
68
72
|
* Initialize component
|
|
69
73
|
* Fetch data only if the component is not initialized and it is not loading data
|
|
@@ -118,6 +122,30 @@ export default function MyEventsWidget(inProps) {
|
|
|
118
122
|
_fetchNext();
|
|
119
123
|
}
|
|
120
124
|
}, [eventIndex, state.results]);
|
|
125
|
+
/**
|
|
126
|
+
* Subscriber for pubsub callback
|
|
127
|
+
*/
|
|
128
|
+
const onDeleteEventHandler = useCallback((_msg, deleted) => {
|
|
129
|
+
const _events = [...state.results];
|
|
130
|
+
if (_events.some((e) => e.id === deleted)) {
|
|
131
|
+
const updatedEvents = _events.filter((e) => e.id !== deleted);
|
|
132
|
+
dispatch({
|
|
133
|
+
type: actionWidgetTypes.SET_RESULTS,
|
|
134
|
+
payload: { results: updatedEvents }
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}, [state.results]);
|
|
138
|
+
/**
|
|
139
|
+
* On mount, subscribe to receive event updates (only delete)
|
|
140
|
+
*/
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (state.results) {
|
|
143
|
+
updatesSubscription.current = PubSub.subscribe(`${SCTopicType.EVENT}.${SCGroupEventType.DELETE}`, onDeleteEventHandler);
|
|
144
|
+
}
|
|
145
|
+
return () => {
|
|
146
|
+
updatesSubscription.current && PubSub.unsubscribe(updatesSubscription.current);
|
|
147
|
+
};
|
|
148
|
+
}, [state.results]);
|
|
121
149
|
// RENDER
|
|
122
150
|
if (!eventsEnabled || (state.initialized && state.count === 0)) {
|
|
123
151
|
return _jsx(HiddenPlaceholder, {});
|
|
@@ -6,7 +6,7 @@ import { Endpoints, http, SuggestionService } from '@selfcommunity/api-services'
|
|
|
6
6
|
import { Link, SCRoutes, useSCRouting } from '@selfcommunity/react-core';
|
|
7
7
|
import { Logger } from '@selfcommunity/utils';
|
|
8
8
|
import classNames from 'classnames';
|
|
9
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
9
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
10
10
|
import { FormattedMessage } from 'react-intl';
|
|
11
11
|
import { Swiper, SwiperSlide } from 'swiper/react';
|
|
12
12
|
import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
@@ -18,6 +18,8 @@ import Widget from '../Widget';
|
|
|
18
18
|
import Arrow from './Arrow';
|
|
19
19
|
import { PREFIX } from './constants';
|
|
20
20
|
import Skeleton from './Skeleton';
|
|
21
|
+
import PubSub from 'pubsub-js';
|
|
22
|
+
import { SCGroupEventType, SCTopicType } from '../../constants/PubSub';
|
|
21
23
|
const classes = {
|
|
22
24
|
root: `${PREFIX}-root`,
|
|
23
25
|
content: `${PREFIX}-content`,
|
|
@@ -56,6 +58,8 @@ export default function SuggestedEventsWidget(inProps) {
|
|
|
56
58
|
const scRoutingContext = useSCRouting();
|
|
57
59
|
//HOOKS
|
|
58
60
|
const theme = useTheme();
|
|
61
|
+
// REFS
|
|
62
|
+
const updatesSubscription = useRef(null);
|
|
59
63
|
useEffect(() => {
|
|
60
64
|
SuggestionService.getEventSuggestion(Object.assign({}, endpointQueryParams))
|
|
61
65
|
.then((payload) => {
|
|
@@ -104,6 +108,28 @@ export default function SuggestedEventsWidget(inProps) {
|
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
110
|
}, [count, hideMarginLeft, hideMarginRight]);
|
|
111
|
+
/**
|
|
112
|
+
* Subscriber for pubsub callback
|
|
113
|
+
*/
|
|
114
|
+
const onDeleteEventHandler = useCallback((_msg, deleted) => {
|
|
115
|
+
setEvents((prev) => {
|
|
116
|
+
if (prev.some((e) => e.id === deleted)) {
|
|
117
|
+
return prev.filter((e) => e.id !== deleted);
|
|
118
|
+
}
|
|
119
|
+
return prev;
|
|
120
|
+
});
|
|
121
|
+
}, [events]);
|
|
122
|
+
/**
|
|
123
|
+
* On mount, subscribe to receive event updates (only delete)
|
|
124
|
+
*/
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (events) {
|
|
127
|
+
updatesSubscription.current = PubSub.subscribe(`${SCTopicType.EVENT}.${SCGroupEventType.DELETE}`, onDeleteEventHandler);
|
|
128
|
+
}
|
|
129
|
+
return () => {
|
|
130
|
+
updatesSubscription.current && PubSub.unsubscribe(updatesSubscription.current);
|
|
131
|
+
};
|
|
132
|
+
}, [events]);
|
|
107
133
|
// RENDER
|
|
108
134
|
if (!events && loading) {
|
|
109
135
|
return _jsx(Skeleton, {});
|
|
@@ -18,6 +18,10 @@ export interface EventActionsMenuProps extends IconButtonProps {
|
|
|
18
18
|
* Handles callback on delete confirm
|
|
19
19
|
*/
|
|
20
20
|
onDeleteConfirm?: () => void;
|
|
21
|
+
/**
|
|
22
|
+
* Handles on edit success
|
|
23
|
+
*/
|
|
24
|
+
onEditSuccess?: (data: SCEventType) => any;
|
|
21
25
|
/**
|
|
22
26
|
* Any other properties
|
|
23
27
|
*/
|
|
@@ -15,6 +15,7 @@ import { copyTextToClipboard } from '@selfcommunity/utils';
|
|
|
15
15
|
import { enqueueSnackbar } from 'notistack';
|
|
16
16
|
import PubSub from 'pubsub-js';
|
|
17
17
|
import { SCGroupEventType, SCTopicType } from '../../constants/PubSub';
|
|
18
|
+
import EventForm from '../../components/EventForm';
|
|
18
19
|
const PREFIX = 'SCEventActionsMenu';
|
|
19
20
|
const classes = {
|
|
20
21
|
root: `${PREFIX}-root`,
|
|
@@ -69,16 +70,17 @@ export default function EventActionsMenu(inProps) {
|
|
|
69
70
|
props: inProps,
|
|
70
71
|
name: PREFIX
|
|
71
72
|
});
|
|
72
|
-
const { className, event, eventId, onDeleteConfirm } = props, rest = __rest(props, ["className", "event", "eventId", "onDeleteConfirm"]);
|
|
73
|
+
const { className, event, eventId, onDeleteConfirm, onEditSuccess } = props, rest = __rest(props, ["className", "event", "eventId", "onDeleteConfirm", "onEditSuccess"]);
|
|
73
74
|
// STATE
|
|
74
75
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
75
76
|
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
|
|
77
|
+
const [openEdit, setOpenEdit] = useState(false);
|
|
76
78
|
// HOOKS
|
|
77
79
|
const theme = useTheme();
|
|
78
80
|
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
|
|
79
81
|
const scRoutingContext = useSCRouting();
|
|
80
82
|
const scUserContext = useSCUser();
|
|
81
|
-
const { scEvent } = useSCFetchEvent({ id: eventId, event });
|
|
83
|
+
const { scEvent, setSCEvent } = useSCFetchEvent({ id: eventId, event });
|
|
82
84
|
const isEventAdmin = useMemo(() => { var _a; return scUserContext.user && ((_a = scEvent === null || scEvent === void 0 ? void 0 : scEvent.managed_by) === null || _a === void 0 ? void 0 : _a.id) === scUserContext.user.id; }, [scUserContext.user, (_a = scEvent === null || scEvent === void 0 ? void 0 : scEvent.managed_by) === null || _a === void 0 ? void 0 : _a.id]);
|
|
83
85
|
const isEventFinished = useMemo(() => {
|
|
84
86
|
if (scEvent && !scEvent.running) {
|
|
@@ -93,10 +95,17 @@ export default function EventActionsMenu(inProps) {
|
|
|
93
95
|
const handleClose = () => {
|
|
94
96
|
setAnchorEl(null);
|
|
95
97
|
};
|
|
98
|
+
const handleEditClick = () => {
|
|
99
|
+
setOpenEdit((o) => !o);
|
|
100
|
+
};
|
|
96
101
|
const handleCloseDialog = () => {
|
|
97
102
|
setOpenConfirmDialog(false);
|
|
98
103
|
setAnchorEl(null);
|
|
99
104
|
};
|
|
105
|
+
const handleEditSuccess = (data) => {
|
|
106
|
+
setSCEvent(data);
|
|
107
|
+
onEditSuccess && onEditSuccess(data);
|
|
108
|
+
};
|
|
100
109
|
/**
|
|
101
110
|
* Handles thread deletion
|
|
102
111
|
*/
|
|
@@ -148,6 +157,7 @@ export default function EventActionsMenu(inProps) {
|
|
|
148
157
|
isEventAdmin &&
|
|
149
158
|
!isEventFinished && [
|
|
150
159
|
_jsx(Divider, {}, "divider"),
|
|
160
|
+
isMobile && (_jsxs(MenuItem, Object.assign({ className: classes.item, onClick: handleEditClick }, { children: [_jsx(ListItemIcon, { children: _jsx(Icon, { children: "edit" }) }), _jsx(FormattedMessage, { id: "ui.shared.eventActionsMenu.item.edit", defaultMessage: "ui.shared.eventActionsMenu.item.edit" })] }), "edit")),
|
|
151
161
|
_jsxs(MenuItem, Object.assign({ className: classes.item, onClick: () => handleAction(CANCEL_EVENT) }, { children: [_jsx(ListItemIcon, { children: _jsx(Icon, { children: "close" }) }), _jsx(FormattedMessage, { id: "ui.shared.eventActionsMenu.item.cancel", defaultMessage: "ui.shared.eventActionsMenu.item.cancel" })] }), "cancel")
|
|
152
162
|
]
|
|
153
163
|
];
|
|
@@ -155,5 +165,5 @@ export default function EventActionsMenu(inProps) {
|
|
|
155
165
|
if (!scEvent) {
|
|
156
166
|
return null;
|
|
157
167
|
}
|
|
158
|
-
return (_jsxs(_Fragment, { children: [_jsx(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { onClick: handleOpen }, { children: _jsx(Icon, { children: "more_vert" }) })), isMobile ? (_jsx(SwipeableDrawerRoot, Object.assign({ className: classes.drawerRoot, anchor: "bottom", open: Boolean(anchorEl), onClose: handleClose, onOpen: handleOpen, PaperProps: { className: classes.paper }, disableSwipeToOpen: true }, { children: _jsx(List, { children: renderList() }) }))) : (_jsx(MenuRoot, Object.assign({ className: classes.menuRoot, anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handleClose, PaperProps: { className: classes.paper } }, { children: renderList() }))), openConfirmDialog && (_jsx(ConfirmDialog, { open: openConfirmDialog, title: _jsx(FormattedMessage, { id: "ui.shared.eventActionsMenu.dialog.msg", defaultMessage: "ui.shared.eventActionsMenu.dialog.msg" }), btnConfirm: _jsx(FormattedMessage, { id: "ui.shared.eventActionsMenu.dialog.confirm", defaultMessage: "ui.shared.eventActionsMenu.dialog.confirm" }), onConfirm: handleDeleteThread, onClose: handleCloseDialog }))] }));
|
|
168
|
+
return (_jsxs(_Fragment, { children: [_jsx(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { onClick: handleOpen }, { children: _jsx(Icon, { children: "more_vert" }) })), isMobile ? (_jsx(SwipeableDrawerRoot, Object.assign({ className: classes.drawerRoot, anchor: "bottom", open: Boolean(anchorEl), onClose: handleClose, onOpen: handleOpen, PaperProps: { className: classes.paper }, disableSwipeToOpen: true }, { children: _jsx(List, { children: renderList() }) }))) : (_jsx(MenuRoot, Object.assign({ className: classes.menuRoot, anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handleClose, PaperProps: { className: classes.paper } }, { children: renderList() }))), openConfirmDialog && (_jsx(ConfirmDialog, { open: openConfirmDialog, title: _jsx(FormattedMessage, { id: "ui.shared.eventActionsMenu.dialog.msg", defaultMessage: "ui.shared.eventActionsMenu.dialog.msg" }), btnConfirm: _jsx(FormattedMessage, { id: "ui.shared.eventActionsMenu.dialog.confirm", defaultMessage: "ui.shared.eventActionsMenu.dialog.confirm" }), onConfirm: handleDeleteThread, onClose: handleCloseDialog })), openEdit && _jsx(EventForm, { onClose: handleEditClick, event: scEvent, onSuccess: handleEditSuccess })] }));
|
|
159
169
|
}
|