@selfcommunity/react-ui 0.9.0-alpha.17 → 0.9.0-alpha.19

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.
@@ -94,8 +94,8 @@ export default function EventHeader(inProps) {
94
94
  /**
95
95
  * Handles callback subscribe/unsubscribe event
96
96
  */
97
- const handleSubscribe = (_event, status) => {
98
- setSCEvent(Object.assign({}, scEvent, { subscription_status: status }));
97
+ const handleSubscribe = (event) => {
98
+ setSCEvent(event);
99
99
  };
100
100
  // RENDER
101
101
  if (!scEvent) {
@@ -139,5 +139,5 @@ export default function EventHeader(inProps) {
139
139
  month: 'long'
140
140
  }),
141
141
  hour: intl.formatDate(scEvent.start_date, { hour: 'numeric', minute: 'numeric' })
142
- } })) })), _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, disabled: isEventFinished }), _jsxs(Box, { children: [!isMobile && (_jsx(EditEventButton, { size: isMobile ? 'small' : 'medium', event: scEvent, 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))] })) }) })] }))] })));
142
+ } })) })), _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, disabled: isEventFinished }), _jsxs(Box, { children: [!isMobile && (_jsx(EditEventButton, { size: isMobile ? 'small' : 'medium', event: scEvent, onEditSuccess: setSCEvent, 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: setSCEvent }, EventActionsProps))] })) }) })] }))] })));
143
143
  }
@@ -1,4 +1,4 @@
1
- import { SCEventSubscriptionStatusType, SCEventType, SCUserType } from '@selfcommunity/types';
1
+ import { SCEventType, SCUserType } from '@selfcommunity/types';
2
2
  export interface EventSubscribeButtonProps {
3
3
  /**
4
4
  * Overrides or extends the styles applied to the component.
@@ -25,7 +25,7 @@ export interface EventSubscribeButtonProps {
25
25
  * @param user
26
26
  * @param joined
27
27
  */
28
- onSubscribe?: (event: SCEventType, status: SCEventSubscriptionStatusType | null) => any;
28
+ onSubscribe?: (event: SCEventType) => any;
29
29
  /**
30
30
  * Others properties
31
31
  */
@@ -4,12 +4,12 @@ import { LoadingButton } from '@mui/lab';
4
4
  import { Box, Button, Checkbox, CircularProgress, FormControlLabel, Icon, Menu, MenuItem, SwipeableDrawer, useMediaQuery, useTheme } from '@mui/material';
5
5
  import { styled } from '@mui/material/styles';
6
6
  import { useThemeProps } from '@mui/system';
7
- import { getEventStatus, useSCContext, useSCFetchEvent, useSCUser } from '@selfcommunity/react-core';
7
+ import { useSCContext, useSCFetchEvent, useSCUser } from '@selfcommunity/react-core';
8
8
  import { SCEventPrivacyType, SCEventSubscriptionStatusType } from '@selfcommunity/types';
9
9
  import { CacheStrategies, Logger } from '@selfcommunity/utils';
10
10
  import classNames from 'classnames';
11
11
  import PubSub from 'pubsub-js';
12
- import { useEffect, useMemo, useState } from 'react';
12
+ import { useCallback, useEffect, useMemo, useState } from 'react';
13
13
  import { FormattedMessage } from 'react-intl';
14
14
  import { SCOPE_SC_UI } from '../../constants/Errors';
15
15
  import { SCGroupEventType, SCTopicType } from '../../constants/PubSub';
@@ -100,12 +100,12 @@ export default function EventSubscribeButton(inProps) {
100
100
  });
101
101
  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]);
102
102
  // HANDLERS
103
- const handleOpen = (event) => {
103
+ const handleOpen = useCallback((event) => {
104
104
  setAnchorEl(event.currentTarget);
105
- };
106
- const handleClose = () => {
105
+ }, [setAnchorEl]);
106
+ const handleClose = useCallback(() => {
107
107
  setAnchorEl(null);
108
- };
108
+ }, [setAnchorEl]);
109
109
  useEffect(() => {
110
110
  /**
111
111
  * Call scEventsManager.subscriptionStatus inside an effect
@@ -115,25 +115,23 @@ export default function EventSubscribeButton(inProps) {
115
115
  setStatus(scEventsManager === null || scEventsManager === void 0 ? void 0 : scEventsManager.subscriptionStatus(scEvent));
116
116
  }
117
117
  }, [authUserId, scEventsManager === null || scEventsManager === void 0 ? void 0 : scEventsManager.subscriptionStatus, scEvent]);
118
- const toggleEventAttendance = (eventStatus) => {
118
+ const toggleEventAttendance = useCallback((eventStatus) => {
119
119
  setLoading(true);
120
120
  const isGoing = eventStatus === SCEventSubscriptionStatusType.GOING ||
121
121
  !(scEvent === null || scEvent === void 0 ? void 0 : scEvent.subscription_status) ||
122
122
  (scEvent === null || scEvent === void 0 ? void 0 : scEvent.subscription_status) === SCEventSubscriptionStatusType.INVITED;
123
123
  const toggleAction = isGoing ? scEventsManager.toggleEventAttendance(scEvent) : scEventsManager.toggleEventNonattendance(scEvent);
124
124
  toggleAction
125
- .then(() => {
126
- onSubscribe
127
- ? onSubscribe(scEvent, getEventStatus(scEvent, isGoing))
128
- : setSCEvent(Object.assign({}, scEvent, { subscription_status: getEventStatus(scEvent, isGoing) }));
125
+ .then((data) => {
126
+ onSubscribe ? onSubscribe(data) : setSCEvent(data);
129
127
  setLoading(false);
130
128
  PubSub.publish(`${SCTopicType.EVENT}.${SCGroupEventType.MEMBERS}`);
131
129
  })
132
130
  .catch((e) => {
133
131
  Logger.error(SCOPE_SC_UI, e);
134
132
  });
135
- };
136
- const handleToggleAction = (event) => {
133
+ }, [scEvent, scEventsManager, onSubscribe, setLoading]);
134
+ const handleToggleAction = useCallback((event) => {
137
135
  setAnchorEl(null);
138
136
  if (!scUserContext.user) {
139
137
  scContext.settings.handleAnonymousAction();
@@ -141,7 +139,7 @@ export default function EventSubscribeButton(inProps) {
141
139
  else if (status !== undefined) {
142
140
  toggleEventAttendance(event.target.value);
143
141
  }
144
- };
142
+ }, [scUserContext.user, status, scContext.settings]);
145
143
  function renderMenuItems() {
146
144
  return (_jsx(Box, { children: options.map((option) => (_jsx(MenuItem, Object.assign({ className: classes.item, disabled: loading }, { children: _jsx(FormControlLabel, { label: option.label, control: loading ? (_jsx(CircularProgress, { color: "primary", size: 20 })) : (_jsx(Checkbox, { size: "small", checked: status === option.value, value: option.value, onChange: handleToggleAction, name: `${option.value}-option`, inputProps: { 'aria-label': `${option.label}` } })), labelPlacement: "start" }) }), option.value))) }));
147
145
  }
@@ -18,6 +18,7 @@ const classes = {
18
18
  summary: `${PREFIX}-app-summary`,
19
19
  step: `${PREFIX}-app-step`,
20
20
  image: `${PREFIX}-app-image`,
21
+ imageAndroid: `${PREFIX}-app-image-android`,
21
22
  action: `${PREFIX}-app-action`,
22
23
  button: `${PREFIX}-app-button`
23
24
  };
@@ -53,7 +54,7 @@ export default function App(inProps) {
53
54
  // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
54
55
  // @ts-ignore
55
56
  b: (...chunks) => _jsx("strong", { children: chunks })
56
- } }) })), _jsx(CardMedia, { className: classes.image, component: "img", src: AndroidPlaceholder })] })), tab === 1 && (_jsxs(_Fragment, { children: [_jsx(Typography, Object.assign({ className: classes.summary }, { children: _jsx(FormattedMessage, { id: "ui.onBoardingWidget.step.app.ios", defaultMessage: "ui.onBoardingWidget.step.app.ios" }) })), _jsx(Typography, Object.assign({ className: classes.step }, { children: _jsx(FormattedMessage, { id: "ui.onBoardingWidget.step.app.ios.a", defaultMessage: "ui.onBoardingWidget.step.app.ios.a", values: {
57
+ } }) })), _jsx(CardMedia, { className: classes.imageAndroid, component: "img", src: AndroidPlaceholder })] })), tab === 1 && (_jsxs(_Fragment, { children: [_jsx(Typography, Object.assign({ className: classes.summary }, { children: _jsx(FormattedMessage, { id: "ui.onBoardingWidget.step.app.ios", defaultMessage: "ui.onBoardingWidget.step.app.ios" }) })), _jsx(Typography, Object.assign({ className: classes.step }, { children: _jsx(FormattedMessage, { id: "ui.onBoardingWidget.step.app.ios.a", defaultMessage: "ui.onBoardingWidget.step.app.ios.a", values: {
57
58
  // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
58
59
  // @ts-ignore
59
60
  icon: (...chunks) => _jsx(Icon, Object.assign({ fontSize: "medium" }, { children: chunks })),