@selfcommunity/react-ui 0.7.50-events.38 → 0.7.50-events.40
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/BottomNavigation/BottomNavigation.js +14 -5
- package/lib/cjs/components/CreateEventButton/CreateEventButton.js +6 -7
- package/lib/cjs/components/EditEventButton/EditEventButton.d.ts +43 -0
- package/lib/cjs/components/EditEventButton/EditEventButton.js +61 -0
- package/lib/cjs/components/EditEventButton/index.d.ts +3 -0
- package/lib/cjs/components/EditEventButton/index.js +5 -0
- package/lib/cjs/components/EventForm/EventAddress.d.ts +2 -1
- package/lib/cjs/components/EventForm/EventAddress.js +4 -4
- package/lib/cjs/components/EventForm/EventForm.d.ts +6 -0
- package/lib/cjs/components/EventForm/EventForm.js +51 -25
- package/lib/cjs/components/EventForm/UploadEventCover.d.ts +10 -0
- package/lib/cjs/components/EventForm/UploadEventCover.js +34 -7
- package/lib/cjs/components/EventHeader/EventHeader.d.ts +67 -0
- package/lib/cjs/components/EventHeader/EventHeader.js +175 -0
- package/lib/cjs/components/EventHeader/Skeleton.d.ts +25 -0
- package/lib/cjs/components/EventHeader/Skeleton.js +56 -0
- package/lib/cjs/components/EventHeader/constants.d.ts +1 -0
- package/lib/cjs/components/EventHeader/constants.js +4 -0
- package/lib/cjs/components/EventHeader/index.d.ts +4 -0
- package/lib/cjs/components/EventHeader/index.js +8 -0
- package/lib/cjs/components/EventInfoWidget/EventInfoWidget.d.ts +24 -0
- package/lib/cjs/components/EventInfoWidget/EventInfoWidget.js +74 -0
- package/lib/cjs/components/EventInfoWidget/constants.d.ts +1 -0
- package/lib/cjs/components/EventInfoWidget/constants.js +4 -0
- package/lib/cjs/components/EventInfoWidget/index.d.ts +3 -0
- package/lib/cjs/components/EventInfoWidget/index.js +6 -0
- package/lib/cjs/components/EventInviteButton/EventInviteButton.js +11 -11
- package/lib/cjs/components/EventLocationWidget/EventLocationWidget.js +1 -0
- package/lib/cjs/components/EventSubscribeButton/EventSubscribeButton.d.ts +56 -0
- package/lib/cjs/components/EventSubscribeButton/EventSubscribeButton.js +193 -0
- package/lib/cjs/components/EventSubscribeButton/index.d.ts +3 -0
- package/lib/cjs/components/EventSubscribeButton/index.js +5 -0
- package/lib/cjs/components/Events/Events.js +12 -11
- package/lib/cjs/components/FeedObject/FeedObject.js +1 -1
- package/lib/cjs/components/NavigationToolbar/NavigationToolbar.d.ts +2 -0
- package/lib/cjs/components/NavigationToolbar/NavigationToolbar.js +9 -1
- package/lib/cjs/components/NavigationToolbarMobile/NavigationToolbarMobile.js +12 -2
- package/lib/cjs/components/User/User.d.ts +2 -1
- package/lib/cjs/components/User/User.js +9 -9
- package/lib/cjs/constants/PubSub.d.ts +5 -1
- package/lib/cjs/index.d.ts +104 -100
- package/lib/cjs/index.js +270 -260
- package/lib/cjs/shared/Bullet/index.js +1 -2
- package/lib/cjs/shared/Calendar/index.d.ts +1 -2
- package/lib/cjs/shared/Calendar/index.js +3 -5
- package/lib/cjs/shared/EventInfoDetails/index.d.ts +6 -0
- package/lib/cjs/shared/EventInfoDetails/index.js +67 -0
- package/lib/esm/components/BottomNavigation/BottomNavigation.js +14 -5
- package/lib/esm/components/CreateEventButton/CreateEventButton.js +6 -7
- package/lib/esm/components/EditEventButton/EditEventButton.d.ts +43 -0
- package/lib/esm/components/EditEventButton/EditEventButton.js +58 -0
- package/lib/esm/components/EditEventButton/index.d.ts +3 -0
- package/lib/esm/components/EditEventButton/index.js +2 -0
- package/lib/esm/components/EventForm/EventAddress.d.ts +2 -1
- package/lib/esm/components/EventForm/EventAddress.js +4 -4
- package/lib/esm/components/EventForm/EventForm.d.ts +6 -0
- package/lib/esm/components/EventForm/EventForm.js +51 -25
- package/lib/esm/components/EventForm/UploadEventCover.d.ts +10 -0
- package/lib/esm/components/EventForm/UploadEventCover.js +34 -7
- package/lib/esm/components/EventHeader/EventHeader.d.ts +67 -0
- package/lib/esm/components/EventHeader/EventHeader.js +172 -0
- package/lib/esm/components/EventHeader/Skeleton.d.ts +25 -0
- package/lib/esm/components/EventHeader/Skeleton.js +53 -0
- package/lib/esm/components/EventHeader/constants.d.ts +1 -0
- package/lib/esm/components/EventHeader/constants.js +1 -0
- package/lib/esm/components/EventHeader/index.d.ts +4 -0
- package/lib/esm/components/EventHeader/index.js +4 -0
- package/lib/esm/components/EventInfoWidget/EventInfoWidget.d.ts +24 -0
- package/lib/esm/components/EventInfoWidget/EventInfoWidget.js +71 -0
- package/lib/esm/components/EventInfoWidget/constants.d.ts +1 -0
- package/lib/esm/components/EventInfoWidget/constants.js +1 -0
- package/lib/esm/components/EventInfoWidget/index.d.ts +3 -0
- package/lib/esm/components/EventInfoWidget/index.js +3 -0
- package/lib/esm/components/EventInviteButton/EventInviteButton.js +11 -11
- package/lib/esm/components/EventLocationWidget/EventLocationWidget.js +1 -0
- package/lib/esm/components/EventSubscribeButton/EventSubscribeButton.d.ts +56 -0
- package/lib/esm/components/EventSubscribeButton/EventSubscribeButton.js +190 -0
- package/lib/esm/components/EventSubscribeButton/index.d.ts +3 -0
- package/lib/esm/components/EventSubscribeButton/index.js +2 -0
- package/lib/esm/components/Events/Events.js +12 -11
- package/lib/esm/components/FeedObject/FeedObject.js +1 -1
- package/lib/esm/components/NavigationToolbar/NavigationToolbar.d.ts +2 -0
- package/lib/esm/components/NavigationToolbar/NavigationToolbar.js +9 -1
- package/lib/esm/components/NavigationToolbarMobile/NavigationToolbarMobile.js +13 -3
- package/lib/esm/components/User/User.d.ts +2 -1
- package/lib/esm/components/User/User.js +9 -9
- package/lib/esm/constants/PubSub.d.ts +5 -1
- package/lib/esm/index.d.ts +104 -100
- package/lib/esm/index.js +109 -105
- package/lib/esm/shared/Bullet/index.js +0 -1
- package/lib/esm/shared/Calendar/index.d.ts +1 -2
- package/lib/esm/shared/Calendar/index.js +0 -1
- package/lib/esm/shared/EventInfoDetails/index.d.ts +6 -0
- package/lib/esm/shared/EventInfoDetails/index.js +64 -0
- package/lib/umd/84.js +2 -0
- package/lib/umd/react-ui.js +1 -1
- package/package.json +8 -7
- package/lib/umd/204.js +0 -2
- /package/lib/umd/{204.js.LICENSE.txt → 84.js.LICENSE.txt} +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
4
|
const styles_1 = require("@mui/material/styles");
|
|
6
5
|
const system_1 = require("@mui/system");
|
|
7
6
|
const classnames_1 = tslib_1.__importDefault(require("classnames"));
|
|
@@ -20,6 +19,6 @@ function Bullet(inProps) {
|
|
|
20
19
|
props: inProps,
|
|
21
20
|
name: PREFIX
|
|
22
21
|
}), { className } = _a, props = tslib_1.__rest(_a, ["className"]);
|
|
23
|
-
return (
|
|
22
|
+
return (React.createElement(Root, Object.assign({ className: (0, classnames_1.default)(className, classes.root) }, props), "\u2022"));
|
|
24
23
|
}
|
|
25
24
|
exports.default = Bullet;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
3
|
const material_1 = require("@mui/material");
|
|
6
4
|
const PREFIX = 'SCCalendar';
|
|
7
5
|
const Root = (0, material_1.styled)(material_1.Stack, {
|
|
@@ -11,8 +9,8 @@ const Root = (0, material_1.styled)(material_1.Stack, {
|
|
|
11
9
|
})();
|
|
12
10
|
function Calendar(props) {
|
|
13
11
|
const day = props.day;
|
|
14
|
-
return (
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
return (React.createElement(Root, { gap: "7px", position: "absolute", bottom: "-36px", left: "24px", width: "60px", height: "60px", borderRadius: "5px", boxShadow: "0px 3px 8px #00000040", bgcolor: "#fff", overflow: "hidden" },
|
|
13
|
+
React.createElement(material_1.Box, { width: "100%", height: "16px", bgcolor: "#b20404" }),
|
|
14
|
+
React.createElement(material_1.Typography, { variant: "h2", textAlign: "center" }, day)));
|
|
17
15
|
}
|
|
18
16
|
exports.default = Calendar;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const material_1 = require("@mui/material");
|
|
4
|
+
const react_core_1 = require("@selfcommunity/react-core");
|
|
5
|
+
const date_fns_1 = require("date-fns");
|
|
6
|
+
const locale_1 = require("date-fns/locale");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const react_intl_1 = require("react-intl");
|
|
9
|
+
const LOCALE_MAP = {
|
|
10
|
+
en: locale_1.enUS,
|
|
11
|
+
it: locale_1.it
|
|
12
|
+
};
|
|
13
|
+
const PREFIX = 'SCEventInfoDetails';
|
|
14
|
+
const classes = {
|
|
15
|
+
root: `${PREFIX}-root`,
|
|
16
|
+
iconTextWrapper: `${PREFIX}-icon-text-wrapper`,
|
|
17
|
+
link: `${PREFIX}-link`,
|
|
18
|
+
url: `${PREFIX}-url`,
|
|
19
|
+
creationWrapper: `${PREFIX}-creation-wrapper`
|
|
20
|
+
};
|
|
21
|
+
const Root = (0, material_1.styled)(material_1.Stack, {
|
|
22
|
+
name: PREFIX,
|
|
23
|
+
slot: 'Root',
|
|
24
|
+
overridesResolver: (_props, styles) => styles.root
|
|
25
|
+
})();
|
|
26
|
+
function EventInfoDetails(inProps) {
|
|
27
|
+
// PROPS
|
|
28
|
+
const props = (0, material_1.useThemeProps)({
|
|
29
|
+
props: inProps,
|
|
30
|
+
name: PREFIX
|
|
31
|
+
});
|
|
32
|
+
const { event, hasCreatedInfo } = props;
|
|
33
|
+
// HOOKS
|
|
34
|
+
const intl = (0, react_intl_1.useIntl)();
|
|
35
|
+
const privacy = event.privacy === 'public' ? 'ui.eventInfoDetails.privacy.public' : 'ui.eventInfoDetails.privacy.private';
|
|
36
|
+
const location = event.location === 'virtual' ? 'ui.eventInfoDetails.location.virtual' : 'ui.eventInfoDetails.location.inPerson';
|
|
37
|
+
const LocationComponent = event.location === 'virtual' ? react_core_1.Link : react_1.Fragment;
|
|
38
|
+
const formatDateEventDate = (date) => {
|
|
39
|
+
return (0, date_fns_1.format)(new Date(date), "EEEE d MMMM' - Ore 'H:mm", {
|
|
40
|
+
locale: LOCALE_MAP[intl.locale]
|
|
41
|
+
}).replace(/([a-z/ì]+) (\d{2}) ([a-z]+) - Ore (\d{2}):(\d{2})/, (_, weekDay, day, month, hour, minute) => `${weekDay.charAt(0).toUpperCase() + weekDay.slice(1)} ${day} ${month.charAt(0).toUpperCase() + month.slice(1)} - Ore ${hour}:${minute}`);
|
|
42
|
+
};
|
|
43
|
+
const formatDateCreateDate = (date) => {
|
|
44
|
+
return (0, date_fns_1.format)(new Date(date), "'Creato il 'd MMMM y", {
|
|
45
|
+
locale: LOCALE_MAP[intl.locale]
|
|
46
|
+
}).replace(/Creato il (\d{1})+ ([a-z]+) (\d{4})/, (_, day, month, year) => `Creato il ${day} ${month.charAt(0).toUpperCase() + month.slice(1)} ${year}`);
|
|
47
|
+
};
|
|
48
|
+
return (React.createElement(Root, { className: classes.root },
|
|
49
|
+
React.createElement(material_1.Stack, { className: classes.iconTextWrapper },
|
|
50
|
+
React.createElement(material_1.Icon, { fontSize: "small" }, "CalendarIcon"),
|
|
51
|
+
React.createElement(material_1.Typography, { variant: "body1" }, formatDateEventDate(event.start_date))),
|
|
52
|
+
React.createElement(material_1.Stack, { className: classes.iconTextWrapper },
|
|
53
|
+
React.createElement(material_1.Icon, { fontSize: "small" }, event.privacy === 'public' ? 'public' : 'private'),
|
|
54
|
+
React.createElement(material_1.Typography, { variant: "body1" },
|
|
55
|
+
React.createElement(react_intl_1.FormattedMessage, { id: privacy, defaultMessage: privacy })),
|
|
56
|
+
"-",
|
|
57
|
+
React.createElement(material_1.Typography, { variant: "body1" },
|
|
58
|
+
React.createElement(react_intl_1.FormattedMessage, { id: location, defaultMessage: location }))),
|
|
59
|
+
React.createElement(material_1.Stack, { className: classes.iconTextWrapper },
|
|
60
|
+
React.createElement(material_1.Icon, { fontSize: "small" }, event.location === 'virtual' ? 'play_circle_outline' : 'add_location_alt'),
|
|
61
|
+
React.createElement(LocationComponent, { to: event.link, target: "_blank", className: classes.link },
|
|
62
|
+
React.createElement(material_1.Typography, { variant: "body1", className: classes.url }, event.location === 'virtual' ? event.link : event.geolocation))),
|
|
63
|
+
hasCreatedInfo && (React.createElement(material_1.Stack, { className: classes.creationWrapper },
|
|
64
|
+
React.createElement(material_1.Icon, { fontSize: "small" }, "create"),
|
|
65
|
+
React.createElement(material_1.Typography, { variant: "body1" }, formatDateCreateDate(event.created_at))))));
|
|
66
|
+
}
|
|
67
|
+
exports.default = EventInfoDetails;
|
|
@@ -61,18 +61,27 @@ export default function BottomNavigation(inProps) {
|
|
|
61
61
|
// MEMO
|
|
62
62
|
const privateMessagingEnabled = useMemo(() => features.includes(SCFeatureName.PRIVATE_MESSAGING), [features]);
|
|
63
63
|
const groupsEnabled = useMemo(() => features.includes(SCFeatureName.GROUPING) && features.includes(SCFeatureName.TAGGING), [features]);
|
|
64
|
+
const eventsEnabled = useMemo(() => features && features.includes(SCFeatureName.EVENT) && features.includes(SCFeatureName.TAGGING), [features]);
|
|
65
|
+
const exploreStreamEnabled = preferences[SCPreferences.CONFIGURATIONS_EXPLORE_STREAM_ENABLED].value;
|
|
66
|
+
const postOnlyStaffEnabled = preferences[SCPreferences.CONFIGURATIONS_POST_ONLY_STAFF_ENABLED].value;
|
|
67
|
+
const contentAvailable = preferences[SCPreferences.CONFIGURATIONS_CONTENT_AVAILABILITY].value;
|
|
64
68
|
const isIOS = useMemo(() => iOS(), []);
|
|
65
69
|
// RENDER
|
|
66
70
|
return (React.createElement(Root, Object.assign({ className: classNames(className, classes.root, { [classes.ios]: isIOS }) }, rest), children
|
|
67
71
|
? children
|
|
68
72
|
: [
|
|
69
73
|
React.createElement(BottomNavigationAction, { key: "home", className: classes.action, component: Link, to: scUserContext.user ? scRoutingContext.url(SCRoutes.HOME_ROUTE_NAME, {}) : '/', value: scUserContext.user ? scRoutingContext.url(SCRoutes.HOME_ROUTE_NAME, {}) : '/', icon: React.createElement(Icon, null, "home") }),
|
|
70
|
-
(scUserContext.user ||
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
(scUserContext.user || contentAvailable) && exploreStreamEnabled ? (React.createElement(BottomNavigationAction, { key: "explore", className: classes.action, component: Link, to: scRoutingContext.url(SCRoutes.EXPLORE_ROUTE_NAME, {}), value: scRoutingContext.url(SCRoutes.EXPLORE_ROUTE_NAME, {}), icon: React.createElement(Icon, null, "explore") })) : null,
|
|
75
|
+
(!postOnlyStaffEnabled || (UserUtils.isStaff(scUserContext.user) && postOnlyStaffEnabled)) &&
|
|
76
|
+
((groupsEnabled && !eventsEnabled) || (!groupsEnabled && eventsEnabled)) &&
|
|
77
|
+
!exploreStreamEnabled ? (React.createElement(BottomNavigationAction, { key: "composer", className: classNames(classes.composer, classes.action), component: ComposerIconButton, disableRipple: true })) : null,
|
|
74
78
|
groupsEnabled && scUserContext.user ? (React.createElement(BottomNavigationAction, { key: "groups", className: classes.action, component: Link, to: scRoutingContext.url(SCRoutes.GROUPS_SUBSCRIBED_ROUTE_NAME, {}), value: scRoutingContext.url(SCRoutes.GROUPS_SUBSCRIBED_ROUTE_NAME, {}), icon: React.createElement(Icon, null, "groups") })) : null,
|
|
75
|
-
|
|
79
|
+
(!postOnlyStaffEnabled || (UserUtils.isStaff(scUserContext.user) && postOnlyStaffEnabled)) &&
|
|
80
|
+
groupsEnabled &&
|
|
81
|
+
eventsEnabled &&
|
|
82
|
+
!exploreStreamEnabled ? (React.createElement(BottomNavigationAction, { key: "composer", className: classNames(classes.composer, classes.action), component: ComposerIconButton, disableRipple: true })) : null,
|
|
83
|
+
eventsEnabled && scUserContext.user ? (React.createElement(BottomNavigationAction, { key: "events", className: classes.action, component: Link, to: scRoutingContext.url(SCRoutes.EVENT_ROUTE_NAME, {}), value: scRoutingContext.url(SCRoutes.EVENTS_ROUTE_NAME, {}), icon: React.createElement(Icon, null, "CalendarIcon") })) : null,
|
|
84
|
+
scUserContext.user && !groupsEnabled && !eventsEnabled ? (React.createElement(BottomNavigationAction, { key: "notifications", className: classes.action, component: Link, to: scRoutingContext.url(SCRoutes.USER_NOTIFICATIONS_ROUTE_NAME, {}), value: scRoutingContext.url(SCRoutes.USER_NOTIFICATIONS_ROUTE_NAME, {}), icon: React.createElement(Badge, { badgeContent: scUserContext.user.unseen_notification_banners_counter + scUserContext.user.unseen_interactions_counter, color: "secondary" },
|
|
76
85
|
React.createElement(Icon, null, "notifications_active")) })) : null,
|
|
77
86
|
privateMessagingEnabled && scUserContext.user ? (React.createElement(BottomNavigationAction, { key: "messages", className: classes.action, component: Link, to: scRoutingContext.url(SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, {}), value: scRoutingContext.url(SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, {}), icon: React.createElement(Badge, { badgeContent: 0, color: "secondary" },
|
|
78
87
|
React.createElement(Icon, null, "email")) })) : null
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
|
-
import React, { useContext, useMemo } from 'react';
|
|
3
|
-
import { useThemeProps } from '@mui/system';
|
|
4
|
-
import { styled } from '@mui/material/styles';
|
|
5
2
|
import { Button, Icon } from '@mui/material';
|
|
6
|
-
import {
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
import { useThemeProps } from '@mui/system';
|
|
7
5
|
import { SCPreferences, SCUserContext, useSCPreferences } from '@selfcommunity/react-core';
|
|
8
6
|
import classNames from 'classnames';
|
|
7
|
+
import React, { useContext, useMemo } from 'react';
|
|
8
|
+
import { FormattedMessage } from 'react-intl';
|
|
9
9
|
import EventForm from '../EventForm';
|
|
10
|
-
import HiddenPlaceholder from '../../shared/HiddenPlaceholder';
|
|
11
10
|
const PREFIX = 'SCCreateEventButton';
|
|
12
11
|
const classes = {
|
|
13
12
|
root: `${PREFIX}-root`
|
|
@@ -65,12 +64,12 @@ export default function CreateEventButton(inProps) {
|
|
|
65
64
|
* If there's no authUserId, component is hidden.
|
|
66
65
|
*/
|
|
67
66
|
if ((!canCreateEvent && onlyStaffEnabled) || !authUserId) {
|
|
68
|
-
return
|
|
67
|
+
return null;
|
|
69
68
|
}
|
|
70
69
|
/**
|
|
71
70
|
* Renders root object
|
|
72
71
|
*/
|
|
73
72
|
return (React.createElement(React.Fragment, null,
|
|
74
|
-
React.createElement(Root, Object.assign({ className: classNames(classes.root, className), onClick: handleClick, variant: "contained", color: "secondary", startIcon: React.createElement(Icon, { fontSize: "small" }, "add") }, rest), children !== null && children !== void 0 ? children : React.createElement(FormattedMessage, { id: "ui.createEventButton", defaultMessage: "ui.createEventButton" })),
|
|
73
|
+
React.createElement(Root, Object.assign({ className: classNames(classes.root, className), onClick: handleClick, variant: "contained", color: "secondary", startIcon: !EventFormProps.event && React.createElement(Icon, { fontSize: "small" }, "add") }, rest), children !== null && children !== void 0 ? children : React.createElement(FormattedMessage, { id: "ui.createEventButton", defaultMessage: "ui.createEventButton" })),
|
|
75
74
|
open && React.createElement(EventForm, Object.assign({}, EventFormProps, { open: true, onClose: handleClick }))));
|
|
76
75
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CreateEventButtonProps } from '../CreateEventButton';
|
|
2
|
+
import { SCEventType } from '@selfcommunity/types';
|
|
3
|
+
export interface EditEventButtonProps extends CreateEventButtonProps {
|
|
4
|
+
/**
|
|
5
|
+
* Event Object
|
|
6
|
+
* @default null
|
|
7
|
+
*/
|
|
8
|
+
event?: SCEventType;
|
|
9
|
+
/**
|
|
10
|
+
* Id of the event
|
|
11
|
+
* @default null
|
|
12
|
+
*/
|
|
13
|
+
eventId?: number | string;
|
|
14
|
+
/**
|
|
15
|
+
* On edit success callback function
|
|
16
|
+
* @default null
|
|
17
|
+
*/
|
|
18
|
+
onEditSuccess?: (data: SCEventType) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Any other properties
|
|
21
|
+
*/
|
|
22
|
+
[p: string]: any;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
*> API documentation for the Community-JS Create Event Button component. Learn about the available props and the CSS API.
|
|
26
|
+
*
|
|
27
|
+
#### Import
|
|
28
|
+
```jsx
|
|
29
|
+
import {CreateEventButton} from '@selfcommunity/react-ui';
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### Component Name
|
|
33
|
+
The name `SCEditEventButton` can be used when providing style overrides in the theme.
|
|
34
|
+
|
|
35
|
+
#### CSS
|
|
36
|
+
|
|
37
|
+
|Rule Name|Global class|Description|
|
|
38
|
+
|---|---|---|
|
|
39
|
+
|root|.SCEditEventButton-root|Styles applied to the root element.|
|
|
40
|
+
|
|
41
|
+
* @param inProps
|
|
42
|
+
*/
|
|
43
|
+
export default function EditEventButton(inProps: EditEventButtonProps): JSX.Element;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useThemeProps } from '@mui/system';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
|
+
import { FormattedMessage } from 'react-intl';
|
|
6
|
+
import { useSCFetchEvent, useSCUser } from '@selfcommunity/react-core';
|
|
7
|
+
import classNames from 'classnames';
|
|
8
|
+
import CreateEventButton from '../CreateEventButton';
|
|
9
|
+
const PREFIX = 'SCEditEventButton';
|
|
10
|
+
const classes = {
|
|
11
|
+
root: `${PREFIX}-root`
|
|
12
|
+
};
|
|
13
|
+
const Root = styled(CreateEventButton, {
|
|
14
|
+
name: PREFIX,
|
|
15
|
+
slot: 'Root',
|
|
16
|
+
overridesResolver: (props, styles) => styles.root
|
|
17
|
+
})(({ theme }) => ({}));
|
|
18
|
+
/**
|
|
19
|
+
*> API documentation for the Community-JS Create Event Button component. Learn about the available props and the CSS API.
|
|
20
|
+
*
|
|
21
|
+
#### Import
|
|
22
|
+
```jsx
|
|
23
|
+
import {CreateEventButton} from '@selfcommunity/react-ui';
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
#### Component Name
|
|
27
|
+
The name `SCEditEventButton` can be used when providing style overrides in the theme.
|
|
28
|
+
|
|
29
|
+
#### CSS
|
|
30
|
+
|
|
31
|
+
|Rule Name|Global class|Description|
|
|
32
|
+
|---|---|---|
|
|
33
|
+
|root|.SCEditEventButton-root|Styles applied to the root element.|
|
|
34
|
+
|
|
35
|
+
* @param inProps
|
|
36
|
+
*/
|
|
37
|
+
export default function EditEventButton(inProps) {
|
|
38
|
+
//PROPS
|
|
39
|
+
const props = useThemeProps({
|
|
40
|
+
props: inProps,
|
|
41
|
+
name: PREFIX
|
|
42
|
+
});
|
|
43
|
+
const { className, eventId, event, onEditSuccess } = props, rest = __rest(props, ["className", "eventId", "event", "onEditSuccess"]);
|
|
44
|
+
const { scEvent, setSCEvent } = useSCFetchEvent({ id: eventId, event });
|
|
45
|
+
const scUserContext = useSCUser();
|
|
46
|
+
const handleSuccess = (data) => {
|
|
47
|
+
setSCEvent(data);
|
|
48
|
+
onEditSuccess && onEditSuccess(data);
|
|
49
|
+
};
|
|
50
|
+
if (!scUserContext.user) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Renders root object
|
|
55
|
+
*/
|
|
56
|
+
return (React.createElement(Root, Object.assign({ variant: "outlined", className: classNames(classes.root, className), EventFormProps: { event: scEvent, onSuccess: handleSuccess } }, rest),
|
|
57
|
+
React.createElement(FormattedMessage, { id: "ui.editEventButton", defaultMessage: "ui.editEventButton" })));
|
|
58
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { SCEventLocationType } from '@selfcommunity/types';
|
|
1
|
+
import { SCEventLocationType, SCEventType } from '@selfcommunity/types';
|
|
2
2
|
export interface EventAddressProps {
|
|
3
|
+
event?: SCEventType;
|
|
3
4
|
forwardGeolocationData: (data: {
|
|
4
5
|
location: SCEventLocationType;
|
|
5
6
|
geolocation?: string;
|
|
@@ -38,10 +38,10 @@ export default function EventAddress(inProps) {
|
|
|
38
38
|
// INTL
|
|
39
39
|
const intl = useIntl();
|
|
40
40
|
// PROPS
|
|
41
|
-
const { className, forwardGeolocationData } = props;
|
|
41
|
+
const { className, forwardGeolocationData, event } = props;
|
|
42
42
|
// STATE
|
|
43
|
-
const [location, setLocation] = useState(SCEventLocationType.PERSON);
|
|
44
|
-
const [geolocation, setGeoLocation] = useState(null);
|
|
43
|
+
const [location, setLocation] = useState(event ? event.location : SCEventLocationType.PERSON);
|
|
44
|
+
const [geolocation, setGeoLocation] = useState(event ? event.geolocation : null);
|
|
45
45
|
const [inputValue, setInputValue] = useState('');
|
|
46
46
|
const [suggestions, setSuggestions] = useState([]);
|
|
47
47
|
const [timeoutId, setTimeoutId] = useState(null);
|
|
@@ -116,7 +116,7 @@ export default function EventAddress(inProps) {
|
|
|
116
116
|
React.createElement(Tab, { value: SCEventLocationType.PERSON, classes: { root: classes.tab }, icon: React.createElement(Icon, null, "add_location_alt"), iconPosition: "start", label: React.createElement(FormattedMessage, { id: "ui.eventForm.address.live.label", defaultMessage: "ui.eventForm.address.live.label" }) }),
|
|
117
117
|
React.createElement(Tab, { value: SCEventLocationType.ONLINE, classes: { root: classes.tab }, icon: React.createElement(Icon, null, "play_circle_outline"), iconPosition: "start", label: React.createElement(FormattedMessage, { id: "ui.eventForm.address.online.label", defaultMessage: "ui.eventForm.address.online.label" }) })),
|
|
118
118
|
React.createElement(Box, { className: classes.tabContent },
|
|
119
|
-
location === SCEventLocationType.PERSON && (React.createElement(Autocomplete, { freeSolo: true, size: "small", value: geolocation, onChange: handleSelection, inputValue: inputValue, onInputChange: handleLocationChange, options: suggestions, getOptionLabel: (option) => option.description, noOptionsText: React.createElement(FormattedMessage, { id: "ui.eventForm.address.live.noResults", defaultMessage: "ui.eventForm.address.live.noResults" }), renderInput: (params) => (React.createElement(TextField, Object.assign({}, params, { label: React.createElement(FormattedMessage, { id: "ui.eventForm.address.live.placeholder", defaultMessage: "ui.eventForm.address.live.placeholder" }), variant: "outlined", fullWidth: true, InputProps: Object.assign(Object.assign({}, params.InputProps), { endAdornment: (React.createElement(React.Fragment, null,
|
|
119
|
+
location === SCEventLocationType.PERSON && (React.createElement(Autocomplete, { freeSolo: true, size: "small", value: geolocation, onChange: handleSelection, inputValue: inputValue, onInputChange: handleLocationChange, options: suggestions, getOptionLabel: (option) => option.description || geolocation, noOptionsText: React.createElement(FormattedMessage, { id: "ui.eventForm.address.live.noResults", defaultMessage: "ui.eventForm.address.live.noResults" }), renderInput: (params) => (React.createElement(TextField, Object.assign({}, params, { label: React.createElement(FormattedMessage, { id: "ui.eventForm.address.live.placeholder", defaultMessage: "ui.eventForm.address.live.placeholder" }), variant: "outlined", fullWidth: true, InputProps: Object.assign(Object.assign({}, params.InputProps), { endAdornment: (React.createElement(React.Fragment, null,
|
|
120
120
|
React.createElement(InputAdornment, { position: "start" },
|
|
121
121
|
React.createElement(Icon, null, "add_location_alt")),
|
|
122
122
|
params.InputProps.endAdornment)) }) }))) })),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseDialogProps } from '../../shared/BaseDialog';
|
|
2
|
+
import { SCEventType } from '@selfcommunity/types';
|
|
2
3
|
export interface EventFormProps extends BaseDialogProps {
|
|
3
4
|
/**
|
|
4
5
|
* Overrides or extends the styles applied to the component.
|
|
@@ -15,6 +16,11 @@ export interface EventFormProps extends BaseDialogProps {
|
|
|
15
16
|
* @default null
|
|
16
17
|
*/
|
|
17
18
|
onClose?: () => void;
|
|
19
|
+
/**
|
|
20
|
+
* Event Object
|
|
21
|
+
* @default null
|
|
22
|
+
*/
|
|
23
|
+
event?: SCEventType;
|
|
18
24
|
/**
|
|
19
25
|
* On success callback function
|
|
20
26
|
* @default null
|
|
@@ -20,6 +20,8 @@ import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
|
|
|
20
20
|
import EventAddress from './EventAddress';
|
|
21
21
|
import itLocale from 'date-fns/locale/it';
|
|
22
22
|
import enLocale from 'date-fns/locale/en-US';
|
|
23
|
+
import { SCGroupEventType, SCTopicType } from '../../constants/PubSub';
|
|
24
|
+
import PubSub from 'pubsub-js';
|
|
23
25
|
const messages = defineMessages({
|
|
24
26
|
name: {
|
|
25
27
|
id: 'ui.eventForm.name.placeholder',
|
|
@@ -108,35 +110,35 @@ const Root = styled(BaseDialog, {
|
|
|
108
110
|
* @param inProps
|
|
109
111
|
*/
|
|
110
112
|
export default function EventForm(inProps) {
|
|
111
|
-
var _a, _b, _c, _d, _e;
|
|
113
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
112
114
|
//PROPS
|
|
113
115
|
const props = useThemeProps({
|
|
114
116
|
props: inProps,
|
|
115
117
|
name: PREFIX
|
|
116
118
|
});
|
|
117
|
-
const { className, open = true, onClose, onSuccess } = props, rest = __rest(props, ["className", "open", "onClose", "onSuccess"]);
|
|
119
|
+
const { className, open = true, onClose, onSuccess, event = null } = props, rest = __rest(props, ["className", "open", "onClose", "onSuccess", "event"]);
|
|
118
120
|
// CONTEXT
|
|
119
121
|
const scContext = useSCContext();
|
|
120
122
|
// INTL
|
|
121
123
|
const intl = useIntl();
|
|
122
124
|
const initialFieldState = {
|
|
123
|
-
imageOriginal: '',
|
|
125
|
+
imageOriginal: event ? event.image_bigger : '',
|
|
124
126
|
imageOriginalFile: '',
|
|
125
|
-
startDate: null,
|
|
126
|
-
startTime: null,
|
|
127
|
-
endDate: null,
|
|
128
|
-
endTime: null,
|
|
129
|
-
location: SCEventLocationType.PERSON,
|
|
130
|
-
geolocation: '',
|
|
131
|
-
lat: null,
|
|
132
|
-
lng: null,
|
|
133
|
-
link: '',
|
|
134
|
-
recurring: SCEventRecurrenceType.NEVER,
|
|
135
|
-
name: '',
|
|
136
|
-
description: '',
|
|
137
|
-
isPublic: true,
|
|
127
|
+
startDate: event ? new Date(event.start_date) : null,
|
|
128
|
+
startTime: event ? new Date(event.start_date) : null,
|
|
129
|
+
endDate: event && event.end_date ? new Date(event.end_date) : null,
|
|
130
|
+
endTime: event && event.end_date ? new Date(event.end_date) : null,
|
|
131
|
+
location: event ? event.location : SCEventLocationType.PERSON,
|
|
132
|
+
geolocation: event ? event.geolocation : '',
|
|
133
|
+
lat: event ? event.geolocation_lat : null,
|
|
134
|
+
lng: event ? event.geolocation_lng : null,
|
|
135
|
+
link: event ? event.link : '',
|
|
136
|
+
recurring: event ? event.recurring : SCEventRecurrenceType.NEVER,
|
|
137
|
+
name: event ? event.name : '',
|
|
138
|
+
description: event ? event.description : '',
|
|
139
|
+
isPublic: (_a = (event && event.privacy === SCEventPrivacyType.PUBLIC)) !== null && _a !== void 0 ? _a : true,
|
|
138
140
|
isSubmitting: false,
|
|
139
|
-
showEndDateTime: false
|
|
141
|
+
showEndDateTime: (_b = (event && event.end_date)) !== null && _b !== void 0 ? _b : false
|
|
140
142
|
};
|
|
141
143
|
// STATE
|
|
142
144
|
const [field, setField] = useState(initialFieldState);
|
|
@@ -171,6 +173,22 @@ export default function EventForm(inProps) {
|
|
|
171
173
|
setError(error);
|
|
172
174
|
}
|
|
173
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Notify when a group info changed
|
|
178
|
+
* @param data
|
|
179
|
+
*/
|
|
180
|
+
function notifyChanges(data) {
|
|
181
|
+
if (data) {
|
|
182
|
+
if (event) {
|
|
183
|
+
// Edit group
|
|
184
|
+
PubSub.publish(`${SCTopicType.EVENT}.${SCGroupEventType.EDIT}`, data);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
// Create group
|
|
188
|
+
PubSub.publish(`${SCTopicType.EVENT}.${SCGroupEventType.CREATE}`, data);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
174
192
|
const handleGeoData = (data) => {
|
|
175
193
|
setField((prev) => (Object.assign(Object.assign({}, prev), data)));
|
|
176
194
|
};
|
|
@@ -202,9 +220,17 @@ export default function EventForm(inProps) {
|
|
|
202
220
|
formData.append('visible', true);
|
|
203
221
|
}
|
|
204
222
|
formData.append('description', field.description);
|
|
205
|
-
|
|
223
|
+
let eventService;
|
|
224
|
+
if (event) {
|
|
225
|
+
eventService = EventService.updateEvent(event.id, formData, { headers: { 'Content-Type': 'multipart/form-data' } });
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
eventService = EventService.createEvent(formData, { headers: { 'Content-Type': 'multipart/form-data' } });
|
|
229
|
+
}
|
|
230
|
+
eventService
|
|
206
231
|
.then((data) => {
|
|
207
232
|
onSuccess && onSuccess(data);
|
|
233
|
+
notifyChanges(data);
|
|
208
234
|
onClose && onClose();
|
|
209
235
|
setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: false })));
|
|
210
236
|
})
|
|
@@ -240,21 +266,21 @@ export default function EventForm(inProps) {
|
|
|
240
266
|
/**
|
|
241
267
|
* Renders root object
|
|
242
268
|
*/
|
|
243
|
-
return (React.createElement(Root, Object.assign({ DialogContentProps: { dividers: false }, title: React.createElement(FormattedMessage, { id: "ui.eventForm.title", defaultMessage: "ui.eventForm.title" }), open: open, onClose: onClose, className: classNames(classes.root, className), actions: React.createElement(LoadingButton, { loading: field.isSubmitting, disabled: !field.name ||
|
|
269
|
+
return (React.createElement(Root, Object.assign({ DialogContentProps: { dividers: false }, title: event ? (React.createElement(FormattedMessage, { id: "ui.eventForm.title.edit", defaultMessage: "ui.eventForm.title.edit" })) : (React.createElement(FormattedMessage, { id: "ui.eventForm.title", defaultMessage: "ui.eventForm.title" })), open: open, onClose: onClose, className: classNames(classes.root, className), actions: React.createElement(LoadingButton, { loading: field.isSubmitting, disabled: !field.name ||
|
|
244
270
|
(!field.startDate && !field.startTime) ||
|
|
245
271
|
(field.location === SCEventLocationType.ONLINE && !field.link) ||
|
|
246
272
|
(field.location === SCEventLocationType.PERSON && !field.geolocation) ||
|
|
247
273
|
(field.recurring !== SCEventRecurrenceType.NEVER && !field.endDate && !field.endTime) ||
|
|
248
274
|
Object.keys(error).length !== 0 ||
|
|
249
275
|
field.name.length > EVENT_TITLE_MAX_LENGTH ||
|
|
250
|
-
field.description.length > EVENT_DESCRIPTION_MAX_LENGTH, variant: "contained", onClick: handleSubmit, color: "secondary" }, React.createElement(FormattedMessage, { id: "ui.eventForm.button.create", defaultMessage: "ui.eventForm.button.create" })) }, rest),
|
|
276
|
+
field.description.length > EVENT_DESCRIPTION_MAX_LENGTH, variant: "contained", onClick: handleSubmit, color: "secondary" }, event ? (React.createElement(FormattedMessage, { id: "ui.eventForm.button.edit", defaultMessage: "ui.eventForm.button.edit" })) : (React.createElement(FormattedMessage, { id: "ui.eventForm.button.create", defaultMessage: "ui.eventForm.button.create" }))) }, rest),
|
|
251
277
|
React.createElement(React.Fragment, null,
|
|
252
278
|
React.createElement(Paper, { style: _backgroundCover, classes: { root: classes.cover } },
|
|
253
|
-
React.createElement(UploadEventCover, { onChange: handleChangeCover })),
|
|
279
|
+
React.createElement(UploadEventCover, { isCreationMode: true, onChange: handleChangeCover })),
|
|
254
280
|
React.createElement(FormGroup, { className: classes.form },
|
|
255
281
|
React.createElement(TextField, { required: true, className: classes.name, placeholder: `${intl.formatMessage(messages.name)}`, margin: "normal", value: field.name, name: "name", onChange: handleChange, InputProps: {
|
|
256
282
|
endAdornment: React.createElement(Typography, { variant: "body2" }, EVENT_TITLE_MAX_LENGTH - field.name.length)
|
|
257
|
-
}, error: Boolean(((
|
|
283
|
+
}, error: Boolean(((_c = field === null || field === void 0 ? void 0 : field.name) === null || _c === void 0 ? void 0 : _c.length) > EVENT_TITLE_MAX_LENGTH) || Boolean(error[`nameError`]), helperText: ((_d = field === null || field === void 0 ? void 0 : field.name) === null || _d === void 0 ? void 0 : _d.length) > EVENT_TITLE_MAX_LENGTH ? (React.createElement(FormattedMessage, { id: "ui.eventForm.name.error.maxLength", defaultMessage: "ui.eventForm.name.error.maxLength" })) : error[`nameError`] ? (error[`nameError`]) : null }),
|
|
258
284
|
React.createElement(Box, { className: classes.dateTime },
|
|
259
285
|
React.createElement(LocalizationProvider, { dateAdapter: AdapterDateFns, adapterLocale: scContext.settings.locale.default === 'it' ? itLocale : enLocale },
|
|
260
286
|
React.createElement(MobileDatePicker, { className: classes.picker, disablePast: true, label: field.startDate && React.createElement(FormattedMessage, { id: "ui.eventForm.date.placeholder", defaultMessage: "ui.eventForm.date.placeholder" }), value: field.startDate, slots: {
|
|
@@ -304,7 +330,7 @@ export default function EventForm(inProps) {
|
|
|
304
330
|
}, onChange: (value) => handleChangeDateTime(value, 'endTime') })))),
|
|
305
331
|
React.createElement(Button, { variant: "text", color: "secondary", onClick: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['showEndDateTime']: !field.showEndDateTime }))), disabled: field.showEndDateTime && field.recurring !== SCEventRecurrenceType.NEVER },
|
|
306
332
|
React.createElement(FormattedMessage, { id: "ui.eventForm.dateTime.placeholder", defaultMessage: "ui.eventForm.dateTime.placeholder", values: { symbol: field.showEndDateTime ? '-' : '+' } })),
|
|
307
|
-
React.createElement(EventAddress, { forwardGeolocationData: handleGeoData }),
|
|
333
|
+
React.createElement(EventAddress, { forwardGeolocationData: handleGeoData, event: event !== null && event !== void 0 ? event : null }),
|
|
308
334
|
privateEnabled && (React.createElement(Box, { className: classes.privacySection },
|
|
309
335
|
React.createElement(Stack, { direction: "row", spacing: 1, alignItems: "center", justifyContent: "center" },
|
|
310
336
|
React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: !field.isPublic }) },
|
|
@@ -328,6 +354,6 @@ export default function EventForm(inProps) {
|
|
|
328
354
|
b: (chunks) => React.createElement("strong", null, chunks)
|
|
329
355
|
} }))))))),
|
|
330
356
|
React.createElement(TextField, { multiline: true, className: classes.description, placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: {
|
|
331
|
-
endAdornment: (React.createElement(Typography, { variant: "body2" }, ((
|
|
332
|
-
}, error: Boolean(((
|
|
357
|
+
endAdornment: (React.createElement(Typography, { variant: "body2" }, ((_e = field.description) === null || _e === void 0 ? void 0 : _e.length) ? EVENT_DESCRIPTION_MAX_LENGTH - field.description.length : EVENT_DESCRIPTION_MAX_LENGTH))
|
|
358
|
+
}, 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 ? (React.createElement(FormattedMessage, { id: "ui.eventForm.description.error.maxLength", defaultMessage: "ui.eventForm.description.error.maxLength" })) : null })))));
|
|
333
359
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export interface UploadEventCoverProps {
|
|
2
|
+
/**
|
|
3
|
+
* Id of the event. It is optional only for event creation modal.
|
|
4
|
+
* @default null
|
|
5
|
+
*/
|
|
6
|
+
eventId?: number;
|
|
2
7
|
/**
|
|
3
8
|
* On change function.
|
|
4
9
|
* @default null
|
|
@@ -9,6 +14,11 @@ export interface UploadEventCoverProps {
|
|
|
9
14
|
* @default null
|
|
10
15
|
*/
|
|
11
16
|
className?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Prop to handle cover loading in the create event modal.
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
isCreationMode?: boolean;
|
|
12
22
|
/**
|
|
13
23
|
* Any other properties
|
|
14
24
|
*/
|
|
@@ -8,6 +8,16 @@ import classNames from 'classnames';
|
|
|
8
8
|
import { useThemeProps } from '@mui/system';
|
|
9
9
|
import { PREFIX } from './constants';
|
|
10
10
|
import { LoadingButton } from '@mui/lab';
|
|
11
|
+
import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
12
|
+
import { EventService } from '@selfcommunity/api-services';
|
|
13
|
+
import { Logger } from '@selfcommunity/utils';
|
|
14
|
+
import { defineMessages, useIntl } from 'react-intl';
|
|
15
|
+
const messages = defineMessages({
|
|
16
|
+
errorLoadImage: {
|
|
17
|
+
id: 'ui.changeGroupCover.button.change.alertErrorImage',
|
|
18
|
+
defaultMessage: 'ui.changeGroupCover.button.change.alertErrorImage'
|
|
19
|
+
}
|
|
20
|
+
});
|
|
11
21
|
const classes = {
|
|
12
22
|
root: `${PREFIX}-upload-event-cover-root`
|
|
13
23
|
};
|
|
@@ -44,13 +54,15 @@ export default function UploadEventCover(inProps) {
|
|
|
44
54
|
props: inProps,
|
|
45
55
|
name: PREFIX
|
|
46
56
|
});
|
|
47
|
-
const { onChange, className = false } = props, rest = __rest(props, ["onChange", "className"]);
|
|
57
|
+
const { eventId, onChange, className = false, isCreationMode = false } = props, rest = __rest(props, ["eventId", "onChange", "className", "isCreationMode"]);
|
|
48
58
|
//CONTEXT
|
|
49
59
|
const scUserContext = useContext(SCUserContext);
|
|
50
60
|
//STATE
|
|
51
61
|
let fileInput = useRef(null);
|
|
52
62
|
const [loading, setLoading] = useState(false);
|
|
53
63
|
const [alert, setAlert] = useState(null);
|
|
64
|
+
// INTL
|
|
65
|
+
const intl = useIntl();
|
|
54
66
|
// Anonymous
|
|
55
67
|
if (!scUserContext.user) {
|
|
56
68
|
return null;
|
|
@@ -66,12 +78,7 @@ export default function UploadEventCover(inProps) {
|
|
|
66
78
|
reader.onload = (e) => {
|
|
67
79
|
const img = new Image();
|
|
68
80
|
img.onload = () => {
|
|
69
|
-
onChange && onChange(fileInput);
|
|
70
|
-
// if (img.width < 1920) {
|
|
71
|
-
// setAlert(intl.formatMessage(messages.errorImageSize));
|
|
72
|
-
// } else {
|
|
73
|
-
// isCreationMode ? onChange && onChange(fileInput) : handleSave();
|
|
74
|
-
// }
|
|
81
|
+
isCreationMode ? onChange && onChange(fileInput) : handleSave();
|
|
75
82
|
};
|
|
76
83
|
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
77
84
|
// @ts-ignore
|
|
@@ -82,6 +89,26 @@ export default function UploadEventCover(inProps) {
|
|
|
82
89
|
reader.readAsDataURL(fileInput);
|
|
83
90
|
}
|
|
84
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* Handles cover saving after upload action
|
|
94
|
+
*/
|
|
95
|
+
function handleSave() {
|
|
96
|
+
setLoading(true);
|
|
97
|
+
const formData = new FormData();
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
formData.append('image_original', fileInput);
|
|
101
|
+
EventService.changeEventCover(eventId, formData, { headers: { 'Content-Type': 'multipart/form-data' } })
|
|
102
|
+
.then((data) => {
|
|
103
|
+
onChange && onChange(data.image_medium);
|
|
104
|
+
setLoading(false);
|
|
105
|
+
})
|
|
106
|
+
.catch((error) => {
|
|
107
|
+
Logger.error(SCOPE_SC_UI, error);
|
|
108
|
+
setLoading(false);
|
|
109
|
+
setAlert(intl.formatMessage(messages.errorLoadImage));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
85
112
|
/**
|
|
86
113
|
* If there is an error
|
|
87
114
|
*/
|