@selfcommunity/react-ui 0.11.0-alpha.15 → 0.11.0-alpha.16
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.
|
@@ -6,6 +6,7 @@ const lab_1 = require("@mui/lab");
|
|
|
6
6
|
const material_1 = require("@mui/material");
|
|
7
7
|
const styles_1 = require("@mui/material/styles");
|
|
8
8
|
const system_1 = require("@mui/system");
|
|
9
|
+
const types_1 = require("@selfcommunity/types");
|
|
9
10
|
const classnames_1 = tslib_1.__importDefault(require("classnames"));
|
|
10
11
|
const react_1 = require("react");
|
|
11
12
|
const react_intl_1 = require("react-intl");
|
|
@@ -17,8 +18,11 @@ const api_services_1 = require("@selfcommunity/api-services");
|
|
|
17
18
|
const Errors_1 = require("../../constants/Errors");
|
|
18
19
|
const utils_1 = require("@selfcommunity/utils");
|
|
19
20
|
const deafultCover_1 = tslib_1.__importDefault(require("../../assets/deafultCover"));
|
|
21
|
+
const react_core_1 = require("@selfcommunity/react-core");
|
|
22
|
+
const constants_2 = require("../PlatformWidget/constants");
|
|
20
23
|
const classes = {
|
|
21
24
|
root: `${constants_1.PREFIX}-root`,
|
|
25
|
+
warning: `${constants_1.PREFIX}-warning`,
|
|
22
26
|
form: `${constants_1.PREFIX}-form`,
|
|
23
27
|
title: `${constants_1.PREFIX}-title`,
|
|
24
28
|
cover: `${constants_1.PREFIX}-cover`,
|
|
@@ -81,7 +85,15 @@ function LiveStreamForm(inProps) {
|
|
|
81
85
|
name: constants_1.PREFIX
|
|
82
86
|
});
|
|
83
87
|
const { className, onSuccess, onError, liveStream = null } = props, rest = tslib_1.__rest(props, ["className", "onSuccess", "onError", "liveStream"]);
|
|
84
|
-
//
|
|
88
|
+
// HOOKS
|
|
89
|
+
const scContext = (0, react_core_1.useSCContext)();
|
|
90
|
+
const scUserContext = (0, react_core_1.useSCUser)();
|
|
91
|
+
const { preferences } = (0, react_core_1.useSCPreferences)();
|
|
92
|
+
const isCommunityOwner = (0, react_1.useMemo)(() => { var _a; return ((_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.id) === 1; }, [scUserContext.user]);
|
|
93
|
+
const isFreeTrialTier = (0, react_1.useMemo)(() => preferences &&
|
|
94
|
+
react_core_1.SCPreferences.CONFIGURATIONS_SUBSCRIPTION_TIER in preferences &&
|
|
95
|
+
preferences[react_core_1.SCPreferences.CONFIGURATIONS_SUBSCRIPTION_TIER].value &&
|
|
96
|
+
preferences[react_core_1.SCPreferences.CONFIGURATIONS_SUBSCRIPTION_TIER].value === types_1.SCCommunitySubscriptionTier.FREE_TRIAL, [preferences]);
|
|
85
97
|
const intl = (0, react_intl_1.useIntl)();
|
|
86
98
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
87
99
|
// @ts-ignore
|
|
@@ -175,10 +187,24 @@ function LiveStreamForm(inProps) {
|
|
|
175
187
|
const handleChangeSettings = (0, react_1.useCallback)((data) => {
|
|
176
188
|
setField((prev) => (Object.assign(Object.assign({}, prev), { settings: data })));
|
|
177
189
|
}, [setField]);
|
|
190
|
+
const warning = (0, react_1.useMemo)(() => {
|
|
191
|
+
let _message;
|
|
192
|
+
if (isFreeTrialTier && isCommunityOwner) {
|
|
193
|
+
_message = ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.liveStreamForm.selector.warningSubscriptionRequired", defaultMessage: "ui.liveStreamForm.selector.warningSubscriptionRequired", values: {
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
195
|
+
// @ts-ignore
|
|
196
|
+
link: (...chunks) => (0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: constants_2.SELFCOMMUNITY_PRICING[scContext.settings.locale.default] }, { children: chunks }))
|
|
197
|
+
} }));
|
|
198
|
+
}
|
|
199
|
+
if (_message) {
|
|
200
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.warning }, { children: (0, jsx_runtime_1.jsx)(material_1.Alert, Object.assign({ variant: "filled", severity: "warning" }, { children: _message })) })));
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}, [isFreeTrialTier, isCommunityOwner]);
|
|
178
204
|
/**
|
|
179
205
|
* Renders root object
|
|
180
206
|
*/
|
|
181
|
-
return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest, { children: [(0, jsx_runtime_1.jsx)(material_1.Paper, Object.assign({ style: _backgroundCover, classes: { root: classes.cover } }, { children: (0, jsx_runtime_1.jsx)(UploadEventCover_1.default, { isCreationMode: true, onChange: handleChangeCover }) })), Boolean(error['coverError']) && (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ color: "error" }, { children: error['coverError'] })), (0, jsx_runtime_1.jsxs)(material_1.FormGroup, Object.assign({ className: classes.form }, { children: [(0, jsx_runtime_1.jsx)(material_1.TextField, { required: true, className: classes.title, placeholder: `${intl.formatMessage(messages.title)}`, margin: "normal", value: field.title, name: "title", onChange: handleChange, InputProps: {
|
|
207
|
+
return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest, { children: [warning, (0, jsx_runtime_1.jsx)(material_1.Paper, Object.assign({ style: _backgroundCover, classes: { root: classes.cover } }, { children: (0, jsx_runtime_1.jsx)(UploadEventCover_1.default, { isCreationMode: true, onChange: handleChangeCover }) })), Boolean(error['coverError']) && (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ color: "error" }, { children: error['coverError'] })), (0, jsx_runtime_1.jsxs)(material_1.FormGroup, Object.assign({ className: classes.form }, { children: [(0, jsx_runtime_1.jsx)(material_1.TextField, { required: true, className: classes.title, placeholder: `${intl.formatMessage(messages.title)}`, margin: "normal", value: field.title, name: "title", onChange: handleChange, InputProps: {
|
|
182
208
|
endAdornment: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: LiveStream_1.LIVE_STREAM_TITLE_MAX_LENGTH - field.title.length }))
|
|
183
209
|
}, error: Boolean(field.title.length > LiveStream_1.LIVE_STREAM_TITLE_MAX_LENGTH) || Boolean(error['titleError']), helperText: field.title.length > LiveStream_1.LIVE_STREAM_TITLE_MAX_LENGTH ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.liveStreamForm.title.error.maxLength", defaultMessage: "ui.liveStreamForm.title.error.maxLength" })) : error['titleError'] ? (error['titleError']) : null }), (0, jsx_runtime_1.jsx)(material_1.TextField, { required: true, className: classes.slug, placeholder: `${intl.formatMessage(messages.slug)}`, margin: "normal", value: field.slug, name: "slug", onChange: handleChange, InputProps: {
|
|
184
210
|
endAdornment: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: LiveStream_1.LIVE_STREAM_SLUG_MAX_LENGTH - field.slug.length }))
|
|
@@ -187,6 +213,7 @@ function LiveStreamForm(inProps) {
|
|
|
187
213
|
}, error: Boolean(((_b = field.description) === null || _b === void 0 ? void 0 : _b.length) > LiveStream_1.LIVE_STREAM_DESCRIPTION_MAX_LENGTH), helperText: ((_c = field.description) === null || _c === void 0 ? void 0 : _c.length) > LiveStream_1.LIVE_STREAM_DESCRIPTION_MAX_LENGTH ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.liveStreamForm.description.error.maxLength", defaultMessage: "ui.liveStreamForm.description.error.maxLength" })) : null }), (0, jsx_runtime_1.jsx)(LiveStreamFormSettings_1.default, { settings: field.settings, onChange: handleChangeSettings }), genericError && ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.genericError }, { children: (0, jsx_runtime_1.jsx)(material_1.Alert, Object.assign({ variant: "filled", severity: "error" }, { children: genericError })) }))), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.actions }, { children: (0, jsx_runtime_1.jsx)(lab_1.LoadingButton, Object.assign({ loading: field.isSubmitting, disabled: !field.title ||
|
|
188
214
|
field.isSubmitting ||
|
|
189
215
|
field.title.length > LiveStream_1.LIVE_STREAM_TITLE_MAX_LENGTH ||
|
|
190
|
-
field.description.length > LiveStream_1.LIVE_STREAM_DESCRIPTION_MAX_LENGTH
|
|
216
|
+
field.description.length > LiveStream_1.LIVE_STREAM_DESCRIPTION_MAX_LENGTH ||
|
|
217
|
+
isFreeTrialTier, variant: "contained", onClick: handleSubmit, color: "secondary" }, { children: liveStream ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.liveStreamForm.button.edit", defaultMessage: "ui.liveStreamForm.button.edit" })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.liveStreamForm.button.create", defaultMessage: "ui.liveStreamForm.button.create" })) })) }))] }))] })));
|
|
191
218
|
}
|
|
192
219
|
exports.default = LiveStreamForm;
|
|
@@ -4,8 +4,9 @@ import { LoadingButton } from '@mui/lab';
|
|
|
4
4
|
import { Alert, Box, FormGroup, Paper, TextField, Typography } from '@mui/material';
|
|
5
5
|
import { styled } from '@mui/material/styles';
|
|
6
6
|
import { useThemeProps } from '@mui/system';
|
|
7
|
+
import { SCCommunitySubscriptionTier } from '@selfcommunity/types';
|
|
7
8
|
import classNames from 'classnames';
|
|
8
|
-
import { useCallback, useState } from 'react';
|
|
9
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
9
10
|
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
|
10
11
|
import { LIVE_STREAM_DESCRIPTION_MAX_LENGTH, LIVE_STREAM_TITLE_MAX_LENGTH, LIVE_STREAM_SLUG_MAX_LENGTH } from '../../constants/LiveStream';
|
|
11
12
|
import { LIVESTREAM_DEFAULT_SETTINGS, PREFIX } from './constants';
|
|
@@ -15,8 +16,11 @@ import { formatHttpErrorCode, LiveStreamService } from '@selfcommunity/api-servi
|
|
|
15
16
|
import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
16
17
|
import { Logger } from '@selfcommunity/utils';
|
|
17
18
|
import CoverPlaceholder from '../../assets/deafultCover';
|
|
19
|
+
import { Link, SCPreferences, useSCContext, useSCPreferences, useSCUser } from '@selfcommunity/react-core';
|
|
20
|
+
import { SELFCOMMUNITY_PRICING } from '../PlatformWidget/constants';
|
|
18
21
|
const classes = {
|
|
19
22
|
root: `${PREFIX}-root`,
|
|
23
|
+
warning: `${PREFIX}-warning`,
|
|
20
24
|
form: `${PREFIX}-form`,
|
|
21
25
|
title: `${PREFIX}-title`,
|
|
22
26
|
cover: `${PREFIX}-cover`,
|
|
@@ -79,7 +83,15 @@ export default function LiveStreamForm(inProps) {
|
|
|
79
83
|
name: PREFIX
|
|
80
84
|
});
|
|
81
85
|
const { className, onSuccess, onError, liveStream = null } = props, rest = __rest(props, ["className", "onSuccess", "onError", "liveStream"]);
|
|
82
|
-
//
|
|
86
|
+
// HOOKS
|
|
87
|
+
const scContext = useSCContext();
|
|
88
|
+
const scUserContext = useSCUser();
|
|
89
|
+
const { preferences } = useSCPreferences();
|
|
90
|
+
const isCommunityOwner = useMemo(() => { var _a; return ((_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.id) === 1; }, [scUserContext.user]);
|
|
91
|
+
const isFreeTrialTier = useMemo(() => preferences &&
|
|
92
|
+
SCPreferences.CONFIGURATIONS_SUBSCRIPTION_TIER in preferences &&
|
|
93
|
+
preferences[SCPreferences.CONFIGURATIONS_SUBSCRIPTION_TIER].value &&
|
|
94
|
+
preferences[SCPreferences.CONFIGURATIONS_SUBSCRIPTION_TIER].value === SCCommunitySubscriptionTier.FREE_TRIAL, [preferences]);
|
|
83
95
|
const intl = useIntl();
|
|
84
96
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
85
97
|
// @ts-ignore
|
|
@@ -173,10 +185,24 @@ export default function LiveStreamForm(inProps) {
|
|
|
173
185
|
const handleChangeSettings = useCallback((data) => {
|
|
174
186
|
setField((prev) => (Object.assign(Object.assign({}, prev), { settings: data })));
|
|
175
187
|
}, [setField]);
|
|
188
|
+
const warning = useMemo(() => {
|
|
189
|
+
let _message;
|
|
190
|
+
if (isFreeTrialTier && isCommunityOwner) {
|
|
191
|
+
_message = (_jsx(FormattedMessage, { id: "ui.liveStreamForm.selector.warningSubscriptionRequired", defaultMessage: "ui.liveStreamForm.selector.warningSubscriptionRequired", values: {
|
|
192
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
link: (...chunks) => _jsx(Link, Object.assign({ to: SELFCOMMUNITY_PRICING[scContext.settings.locale.default] }, { children: chunks }))
|
|
195
|
+
} }));
|
|
196
|
+
}
|
|
197
|
+
if (_message) {
|
|
198
|
+
return (_jsx(Box, Object.assign({ className: classes.warning }, { children: _jsx(Alert, Object.assign({ variant: "filled", severity: "warning" }, { children: _message })) })));
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
}, [isFreeTrialTier, isCommunityOwner]);
|
|
176
202
|
/**
|
|
177
203
|
* Renders root object
|
|
178
204
|
*/
|
|
179
|
-
return (_jsxs(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { children: [_jsx(Paper, Object.assign({ style: _backgroundCover, classes: { root: classes.cover } }, { children: _jsx(UploadEventCover, { isCreationMode: true, onChange: handleChangeCover }) })), Boolean(error['coverError']) && _jsx(Typography, Object.assign({ color: "error" }, { children: error['coverError'] })), _jsxs(FormGroup, Object.assign({ className: classes.form }, { children: [_jsx(TextField, { required: true, className: classes.title, placeholder: `${intl.formatMessage(messages.title)}`, margin: "normal", value: field.title, name: "title", onChange: handleChange, InputProps: {
|
|
205
|
+
return (_jsxs(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { children: [warning, _jsx(Paper, Object.assign({ style: _backgroundCover, classes: { root: classes.cover } }, { children: _jsx(UploadEventCover, { isCreationMode: true, onChange: handleChangeCover }) })), Boolean(error['coverError']) && _jsx(Typography, Object.assign({ color: "error" }, { children: error['coverError'] })), _jsxs(FormGroup, Object.assign({ className: classes.form }, { children: [_jsx(TextField, { required: true, className: classes.title, placeholder: `${intl.formatMessage(messages.title)}`, margin: "normal", value: field.title, name: "title", onChange: handleChange, InputProps: {
|
|
180
206
|
endAdornment: _jsx(Typography, Object.assign({ variant: "body2" }, { children: LIVE_STREAM_TITLE_MAX_LENGTH - field.title.length }))
|
|
181
207
|
}, error: Boolean(field.title.length > LIVE_STREAM_TITLE_MAX_LENGTH) || Boolean(error['titleError']), helperText: field.title.length > LIVE_STREAM_TITLE_MAX_LENGTH ? (_jsx(FormattedMessage, { id: "ui.liveStreamForm.title.error.maxLength", defaultMessage: "ui.liveStreamForm.title.error.maxLength" })) : error['titleError'] ? (error['titleError']) : null }), _jsx(TextField, { required: true, className: classes.slug, placeholder: `${intl.formatMessage(messages.slug)}`, margin: "normal", value: field.slug, name: "slug", onChange: handleChange, InputProps: {
|
|
182
208
|
endAdornment: _jsx(Typography, Object.assign({ variant: "body2" }, { children: LIVE_STREAM_SLUG_MAX_LENGTH - field.slug.length }))
|
|
@@ -185,5 +211,6 @@ export default function LiveStreamForm(inProps) {
|
|
|
185
211
|
}, error: Boolean(((_b = field.description) === null || _b === void 0 ? void 0 : _b.length) > LIVE_STREAM_DESCRIPTION_MAX_LENGTH), helperText: ((_c = field.description) === null || _c === void 0 ? void 0 : _c.length) > LIVE_STREAM_DESCRIPTION_MAX_LENGTH ? (_jsx(FormattedMessage, { id: "ui.liveStreamForm.description.error.maxLength", defaultMessage: "ui.liveStreamForm.description.error.maxLength" })) : null }), _jsx(LiveStreamSettingsForm, { settings: field.settings, onChange: handleChangeSettings }), genericError && (_jsx(Box, Object.assign({ className: classes.genericError }, { children: _jsx(Alert, Object.assign({ variant: "filled", severity: "error" }, { children: genericError })) }))), _jsx(Box, Object.assign({ className: classes.actions }, { children: _jsx(LoadingButton, Object.assign({ loading: field.isSubmitting, disabled: !field.title ||
|
|
186
212
|
field.isSubmitting ||
|
|
187
213
|
field.title.length > LIVE_STREAM_TITLE_MAX_LENGTH ||
|
|
188
|
-
field.description.length > LIVE_STREAM_DESCRIPTION_MAX_LENGTH
|
|
214
|
+
field.description.length > LIVE_STREAM_DESCRIPTION_MAX_LENGTH ||
|
|
215
|
+
isFreeTrialTier, variant: "contained", onClick: handleSubmit, color: "secondary" }, { children: liveStream ? (_jsx(FormattedMessage, { id: "ui.liveStreamForm.button.edit", defaultMessage: "ui.liveStreamForm.button.edit" })) : (_jsx(FormattedMessage, { id: "ui.liveStreamForm.button.create", defaultMessage: "ui.liveStreamForm.button.create" })) })) }))] }))] })));
|
|
189
216
|
}
|