UNPKG

@selfcommunity/react-ui

Version:

React UI Components to integrate a Community created with SelfCommunity Platform.

419 lines (414 loc) • 31.9 kB
import { __rest } from "tslib"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { LoadingButton } from '@mui/lab'; import { Alert, Box, FormControl, FormGroup, Icon, IconButton, InputAdornment, InputLabel, MenuItem, Paper, Select, Stack, Switch, TextField, Typography } from '@mui/material'; import { styled } from '@mui/material/styles'; import { useThemeProps } from '@mui/system'; import { LocalizationProvider, MobileDatePicker, MobileTimePicker } from '@mui/x-date-pickers'; import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns'; import { EventService, formatHttpErrorCode } from '@selfcommunity/api-services'; import { SCPreferences, useSCContext, useSCPreferences, useSCUser } from '@selfcommunity/react-core'; import { SCEventLocationType, SCEventPrivacyType, SCEventRecurrenceType, SCFeatureName } from '@selfcommunity/types'; import { Logger } from '@selfcommunity/utils'; import classNames from 'classnames'; import enLocale from 'date-fns/locale/en-US'; import itLocale from 'date-fns/locale/it'; import PubSub from 'pubsub-js'; import { useCallback, useMemo, useState } from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { SCOPE_SC_UI } from '../../constants/Errors'; import { EVENT_DESCRIPTION_MAX_LENGTH, EVENT_TITLE_MAX_LENGTH } from '../../constants/Event'; import { SCGroupEventType, SCTopicType } from '../../constants/PubSub'; import { DAILY_LATER_DAYS, MONTHLY_LATER_DAYS, NEVER_LATER_DAYS, PREFIX, WEEKLY_LATER_DAYS } from './constants'; import EventAddress from './EventAddress'; import UploadEventCover from './UploadEventCover'; import { combineDateAndTime, getLaterDaysDate, getLaterHoursDate, getNewDate } from './utils'; import { LIVESTREAM_DEFAULT_SETTINGS } from '../LiveStreamForm/constants'; import CoverPlaceholder from '../../assets/deafultCover'; const messages = defineMessages({ name: { id: 'ui.eventForm.name.placeholder', defaultMessage: 'ui.eventForm.name.placeholder' }, description: { id: 'ui.eventForm.description.placeholder', defaultMessage: 'ui.eventForm.description.placeholder' }, startDate: { id: 'ui.eventForm.date.placeholder', defaultMessage: 'ui.eventForm.date.placeholder' }, startTime: { id: 'ui.eventForm.time.placeholder', defaultMessage: 'ui.eventForm.time.placeholder' }, frequency: { id: 'ui.eventForm.frequency.label', defaultMessage: 'ui.eventForm.frequency.label' }, frequencyPlaceholder: { id: 'ui.eventForm.frequency.none.placeholder', defaultMessage: 'ui.eventForm.frequency.none.placeholder' }, endDate: { id: 'ui.eventForm.date.end.placeholder', defaultMessage: 'ui.eventForm.date.end.placeholder' }, endTime: { id: 'ui.eventForm.time.end.placeholder', defaultMessage: 'ui.eventForm.time.end.placeholder' }, pickerCancelAction: { id: 'ui.eventForm.time.picker.cancel.placeholder', defaultMessage: 'ui.eventForm.time.picker.cancel.placeholder' } }); const classes = { root: `${PREFIX}-root`, active: `${PREFIX}-active`, title: `${PREFIX}-title`, cover: `${PREFIX}-cover`, picker: `${PREFIX}-picker`, dateTime: `${PREFIX}-date-time`, frequency: `${PREFIX}-frequency`, form: `${PREFIX}-form`, switch: `${PREFIX}-switch`, switchLabel: `${PREFIX}-switch-label`, name: `${PREFIX}-name`, description: `${PREFIX}-description`, content: `${PREFIX}-content`, actions: `${PREFIX}-actions`, privacySection: `${PREFIX}-privacy-section`, privacySectionInfo: `${PREFIX}-privacy-section-info`, error: `${PREFIX}-error`, genericError: `${PREFIX}-generic-error` }; const Root = styled(Box, { name: PREFIX, slot: 'Root' })(() => ({})); /** *> API documentation for the Community-JS Event Form component. Learn about the available props and the CSS API. * #### Import ```jsx import {EventForm} from '@selfcommunity/react-ui'; ``` #### Component Name The name `SCEventForm` can be used when providing style overrides in the theme. #### CSS |Rule Name|Global class|Description| |---|---|---| |root|.SCEventForm-root|Styles applied to the root element.| |active|.SCEventForm-active|Styles applied to the active element.| |title|.SCEventForm-title|Styles applied to the title element.| |cover|.SCEventForm-cover|Styles applied to the cover field.| |form|.SCEventForm-form|Styles applied to the form element.| |switch|.SCEventForm-switch|Styles applied to the switch element.| |switchLabel|.SCEventForm-switch-label|Styles applied to the switchLabel element.| |name|.SCEventForm-name|Styles applied to the name field.| |description|.SCEventForm-description|Styles applied to the description field.| |content|.SCEventForm-content|Styles applied to the element.| |privacySection|.SCEventForm-privacy-section|Styles applied to the privacy section.| |privacySectionInfo|.SCEventForm-privacy-section-info|Styles applied to the privacy info section.| |error|.SCEventForm-error|Styles applied to the error elements.| * @param inProps */ export default function EventForm(inProps) { var _a, _b, _c, _d, _e, _f; //PROPS const props = useThemeProps({ props: inProps, name: PREFIX }); const { className, onSuccess, onError, event, presetLocation, EventAddressComponentProps = {} } = props, rest = __rest(props, ["className", "onSuccess", "onError", "event", "presetLocation", "EventAddressComponentProps"]); // CONTEXT const scContext = useSCContext(); const scUserContext = useSCUser(); // INTL const intl = useIntl(); const startDateTime = useMemo(() => getNewDate(event === null || event === void 0 ? void 0 : event.start_date), [event]); const endDateTime = useMemo(() => getNewDate(event === null || event === void 0 ? void 0 : event.end_date), [event]); const initialFieldState = { name: (event === null || event === void 0 ? void 0 : event.name) || '', description: event ? event.description : '', imageOriginal: (event === null || event === void 0 ? void 0 : event.image_bigger) || '', imageOriginalFile: '', startDate: event ? startDateTime : getNewDate(), startTime: event ? startDateTime : getLaterHoursDate(1), endDate: (event === null || event === void 0 ? void 0 : event.end_date) ? endDateTime : getNewDate(), endTime: (event === null || event === void 0 ? void 0 : event.end_date) ? endDateTime : getLaterHoursDate(3), location: (event === null || event === void 0 ? void 0 : event.location) ? event.location === SCEventLocationType.PERSON ? SCEventLocationType.PERSON : event.location === SCEventLocationType.ONLINE && event.live_stream ? SCEventLocationType.LIVESTREAM : SCEventLocationType.ONLINE : ((_a = EventAddressComponentProps.locations) === null || _a === void 0 ? void 0 : _a.length) ? presetLocation in EventAddressComponentProps.locations ? presetLocation : EventAddressComponentProps.locations[0] : SCEventLocationType.PERSON, geolocation: (event === null || event === void 0 ? void 0 : event.geolocation) || '', lat: (event === null || event === void 0 ? void 0 : event.geolocation_lat) || null, lng: (event === null || event === void 0 ? void 0 : event.geolocation_lng) || null, link: (event === null || event === void 0 ? void 0 : event.link) || '', liveStreamSettings: (event === null || event === void 0 ? void 0 : event.live_stream) ? event === null || event === void 0 ? void 0 : event.live_stream.settings : null, recurring: (event === null || event === void 0 ? void 0 : event.recurring) || SCEventRecurrenceType.NEVER, isPublic: (event === null || event === void 0 ? void 0 : event.privacy) === SCEventPrivacyType.PUBLIC || true, isSubmitting: false }; // STATE const [field, setField] = useState(initialFieldState); const [error, setError] = useState({}); const [genericError, setGenericError] = useState(null); // PREFERENCES const scPreferences = useSCPreferences(); const liveStreamEnabled = useMemo(() => scPreferences.preferences && scPreferences.features && scPreferences.features.includes(SCFeatureName.LIVE_STREAM) && SCPreferences.CONFIGURATIONS_LIVE_STREAM_ENABLED in scPreferences.preferences && scPreferences.preferences[SCPreferences.CONFIGURATIONS_LIVE_STREAM_ENABLED].value, [scPreferences.preferences, scPreferences.features]); const canCreateLiveStream = useMemo(() => { var _a, _b; return (_b = (_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.create_live_stream; }, [(_b = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _b === void 0 ? void 0 : _b.permission]); const privateEnabled = useMemo(() => scPreferences.preferences[SCPreferences.CONFIGURATIONS_EVENTS_PRIVATE_ENABLED].value, [scPreferences.preferences]); const visibilityEnabled = useMemo(() => scPreferences.preferences[SCPreferences.CONFIGURATIONS_EVENTS_VISIBILITY_ENABLED].value, [scPreferences.preferences]); const disablePastStartTime = useMemo(() => field.startDate.getDate() === getNewDate().getDate(), [field]); const disablePastEndTime = useMemo(() => field.endDate.getDate() === getNewDate().getDate(), [field]); const _backgroundCover = Object.assign({}, (field.imageOriginal ? { background: `url('${field.imageOriginal}') center / cover` } : { background: `url('${CoverPlaceholder}') no-repeat 0 0 / 100% 100%` })); const handleChangeCover = useCallback((cover) => { setField((prev) => (Object.assign(Object.assign({}, prev), { ['imageOriginalFile']: cover }))); const reader = new FileReader(); reader.onloadend = () => { setField((prev) => (Object.assign(Object.assign({}, prev), { ['imageOriginal']: reader.result }))); }; reader.readAsDataURL(cover); if (error.imageOriginalError) { delete error.imageOriginalError; setError(error); } setGenericError(null); }, [error]); /** * Notify when a group info changed * @param data */ const notifyChanges = useCallback((data) => { if (event) { // Edit group PubSub.publish(`${SCTopicType.EVENT}.${SCGroupEventType.EDIT}`, data); } else { // Create group PubSub.publish(`${SCTopicType.EVENT}.${SCGroupEventType.CREATE}`, data); } }, [event]); const handleGeoData = useCallback((data) => { setField((prev) => (Object.assign(Object.assign({}, prev), data))); setGenericError(null); }, []); const handleLiveStreamSettingsData = useCallback((data) => { setField((prev) => (Object.assign(Object.assign({}, prev), { liveStreamSettings: Object.assign(Object.assign({}, prev.liveStreamSettings), data) }))); }, []); const handleSubmit = useCallback(() => { setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: true }))); setGenericError(null); const formData = new FormData(); if (field.imageOriginalFile) { formData.append('image_original', field.imageOriginalFile); } formData.append('name', field.name); formData.append('start_date', combineDateAndTime(field.startDate, field.startTime)); formData.append('recurring', field.recurring); formData.append('end_date', combineDateAndTime(field.endDate, field.endTime)); formData.append('location', field.location === SCEventLocationType.PERSON ? SCEventLocationType.PERSON : SCEventLocationType.ONLINE); if (field.location === SCEventLocationType.ONLINE) { formData.append('link', field.link); formData.append('live_stream_settings', null); } else if (field.location === SCEventLocationType.LIVESTREAM) { formData.append('link', ''); formData.append('live_stream_settings', JSON.stringify(Object.assign(Object.assign({}, LIVESTREAM_DEFAULT_SETTINGS), field.liveStreamSettings))); } else if (field.location === SCEventLocationType.PERSON) { formData.append('geolocation', field.geolocation); formData.append('geolocation_lat', field.lat.toString()); formData.append('geolocation_lng', field.lng.toString()); formData.append('link', ''); formData.append('live_stream_settings', null); } if (field.location !== SCEventLocationType.PERSON) { formData.append('geolocation', ''); formData.append('geolocation_lat', ''); formData.append('geolocation_lng', ''); } if (privateEnabled) { formData.append('privacy', field.isPublic ? SCEventPrivacyType.PUBLIC : SCEventPrivacyType.PRIVATE); } if (visibilityEnabled) { formData.append('visible', 'true'); } formData.append('description', field.description); let eventService; if (event) { eventService = EventService.updateEvent(event.id, formData, { headers: { 'Content-Type': 'multipart/form-data' } }); } else { eventService = EventService.createEvent(formData, { headers: { 'Content-Type': 'multipart/form-data' } }); } eventService .then((data) => { notifyChanges(data); setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: false }))); onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data); }) .catch((e) => { const _error = formatHttpErrorCode(e); if (!Object.keys(_error).length) { setGenericError(intl.formatMessage({ id: 'ui.eventForm.genericError', defaultMessage: 'ui.eventForm.genericError' })); } else if ('codeError' in _error) { setGenericError(intl.formatMessage({ id: 'ui.eventForm.liveStream.error.monthlyMinuteLimitReached', defaultMessage: 'ui.eventForm.liveStream.error.monthlyMinuteLimitReached' })); } else { setGenericError(null); } let __errors = {}; if ('coverError' in _error) { __errors = Object.assign(Object.assign({}, __errors), { ['coverError']: _jsx(FormattedMessage, { id: "ui.ui.eventForm.cover.error", defaultMessage: "ui.ui.eventForm.cover.error" }) }); } if ('nameError' in _error || ('nonFieldErrorsError' in _error && _error['nonFieldErrorsError'].error === 'unique')) { __errors = Object.assign(Object.assign({}, __errors), { ['nameError']: _jsx(FormattedMessage, { id: "ui.eventForm.name.error.unique", defaultMessage: "ui.eventForm.name.error.unique" }) }); } setError(__errors); setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: false }))); Logger.error(SCOPE_SC_UI, e); onError === null || onError === void 0 ? void 0 : onError(e); }); }, [field, privateEnabled, visibilityEnabled, onSuccess, onError, notifyChanges]); const handleChange = useCallback((event) => { const { name, value } = event.target; setField((prev) => (Object.assign(Object.assign({}, prev), { [name]: value }))); if (error[`${name}Error`]) { delete error[`${name}Error`]; setError(error); } setGenericError(null); }, [error, setField, setGenericError]); const handleChangeDateTime = useCallback((value, name) => { setField((prev) => (Object.assign(Object.assign({}, prev), { [name]: value }))); if (error[`${name}Error`]) { delete error[`${name}Error`]; setError(error); } else if (error['endDateError']) { delete error['endDateError']; setError(error); } setGenericError(null); }, [error, setField, setGenericError]); const shouldDisableDate = useCallback((date) => { let disabled = false; switch (field.recurring) { case SCEventRecurrenceType.DAILY: disabled = date.getTime() > getLaterDaysDate(DAILY_LATER_DAYS, field.startDate).getTime(); break; case SCEventRecurrenceType.WEEKLY: disabled = date.getTime() > getLaterDaysDate(WEEKLY_LATER_DAYS, field.startDate).getTime(); break; case SCEventRecurrenceType.MONTHLY: disabled = date.getTime() > getLaterDaysDate(MONTHLY_LATER_DAYS, field.startDate).getTime(); break; case SCEventRecurrenceType.NEVER: default: disabled = date.getTime() > getLaterDaysDate(NEVER_LATER_DAYS, field.startDate).getTime(); } return disabled; }, [field]); const shouldDisableTime = useCallback((date) => field.startTime.getTime() > date.getTime(), [field]); /** * Renders root object */ 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.name, placeholder: `${intl.formatMessage(messages.name)}`, margin: "normal", value: field.name, name: "name", onChange: handleChange, InputProps: { endAdornment: _jsx(Typography, Object.assign({ variant: "body2" }, { children: EVENT_TITLE_MAX_LENGTH - field.name.length })) }, error: Boolean(field.name.length > EVENT_TITLE_MAX_LENGTH) || Boolean(error['nameError']), helperText: field.name.length > EVENT_TITLE_MAX_LENGTH ? (_jsx(FormattedMessage, { id: "ui.eventForm.name.error.maxLength", defaultMessage: "ui.eventForm.name.error.maxLength" })) : error['nameError'] ? (error['nameError']) : null }), _jsx(Box, Object.assign({ className: classes.dateTime }, { children: _jsxs(LocalizationProvider, Object.assign({ dateAdapter: AdapterDateFns, adapterLocale: scContext.settings.locale.default === 'it' ? itLocale : enLocale, localeText: { cancelButtonLabel: `${intl.formatMessage(messages.pickerCancelAction)}` } }, { children: [_jsx(MobileDatePicker, { className: classes.picker, disablePast: true, label: field.startDate && _jsx(FormattedMessage, { id: "ui.eventForm.date.placeholder", defaultMessage: "ui.eventForm.date.placeholder" }), value: field.startDate, slots: { textField: (params) => (_jsx(TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.startDate)}`, startAdornment: (_jsx(InputAdornment, Object.assign({ position: "start" }, { children: _jsx(IconButton, { children: _jsx(Icon, { children: "CalendarIcon" }) }) }))) }) }))) }, slotProps: { toolbar: { // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment // @ts-ignore toolbarTitle: _jsx(FormattedMessage, { id: "ui.eventForm.date.title", defaultMessage: "ui.eventForm.date.title" }) } }, onChange: (value) => handleChangeDateTime(value, 'startDate') }), _jsx(MobileTimePicker, { className: classes.picker, disablePast: disablePastStartTime, label: field.startTime && _jsx(FormattedMessage, { id: "ui.eventForm.time.placeholder", defaultMessage: "ui.eventForm.time.placeholder" }), value: field.startTime, slots: { textField: (params) => (_jsx(TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.startTime)}`, startAdornment: (_jsx(InputAdornment, Object.assign({ position: "start" }, { children: _jsx(IconButton, { children: _jsx(Icon, { children: "access_time" }) }) }))) }) }))) }, slotProps: { toolbar: { // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment // @ts-ignore toolbarTitle: _jsx(FormattedMessage, { id: "ui.eventForm.time.title", defaultMessage: "ui.eventForm.time.title" }) } }, onChange: (value) => handleChangeDateTime(value, 'startTime') })] })) })), _jsxs(FormControl, Object.assign({ className: classes.frequency }, { children: [field.recurring !== SCEventRecurrenceType.NEVER && _jsx(InputLabel, Object.assign({ id: "recurring" }, { children: `${intl.formatMessage(messages.frequency)}` })), _jsx(Select, Object.assign({ name: "recurring", label: field.recurring !== SCEventRecurrenceType.NEVER && `${intl.formatMessage(messages.frequency)}`, labelId: "recurring", value: field.recurring, onChange: handleChange, displayEmpty: true, renderValue: (selected) => { if (!selected) { return _jsx("em", { children: `${intl.formatMessage(messages.frequencyPlaceholder)}` }); } return (_jsx(FormattedMessage, { id: `ui.eventForm.frequency.${selected}.placeholder`, defaultMessage: `ui.eventForm.frequency.${selected}.placeholder` })); }, startAdornment: _jsx(InputAdornment, Object.assign({ position: "start" }, { children: _jsx(IconButton, { children: _jsx(Icon, { children: "frequency" }) }) })) }, { children: Object.values(SCEventRecurrenceType).map((f) => (_jsx(MenuItem, Object.assign({ value: f }, { children: _jsx(FormattedMessage, { id: `ui.eventForm.frequency.${f}.placeholder`, defaultMessage: `ui.eventForm.frequency.${f}.placeholder` }) }), f))) }))] })), _jsx(Box, Object.assign({ className: classes.dateTime }, { children: _jsxs(LocalizationProvider, Object.assign({ dateAdapter: AdapterDateFns, adapterLocale: scContext.settings.locale.default === 'it' ? itLocale : enLocale, localeText: { cancelButtonLabel: `${intl.formatMessage(messages.pickerCancelAction)}` } }, { children: [_jsx(MobileDatePicker, { className: classes.picker, minDate: field.startDate, label: _jsx(FormattedMessage, { id: "ui.eventForm.date.end.placeholder", defaultMessage: "ui.eventForm.date.end.placeholder" }), value: field.endDate, slots: { textField: (params) => (_jsx(TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.endDate)}`, startAdornment: (_jsx(InputAdornment, Object.assign({ position: "start" }, { children: _jsx(IconButton, { children: _jsx(Icon, { children: "calendar_off" }) }) }))) }) }))) }, slotProps: { toolbar: { // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment // @ts-ignore toolbarTitle: _jsx(FormattedMessage, { id: "ui.eventForm.date.title", defaultMessage: "ui.eventForm.date.title" }) } }, onChange: (value) => handleChangeDateTime(value, 'endDate'), shouldDisableDate: shouldDisableDate }), _jsx(MobileTimePicker, { className: classes.picker, disablePast: disablePastEndTime, label: field.endTime && _jsx(FormattedMessage, { id: "ui.eventForm.time.end.placeholder", defaultMessage: "ui.eventForm.time.end.placeholder" }), value: field.endTime, slots: { textField: (params) => { var _a; return (_jsx(TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.endTime)}`, startAdornment: (_jsx(InputAdornment, Object.assign({ position: "start" }, { children: _jsx(IconButton, { children: _jsx(Icon, { children: "access_time" }) }) }))) }), error: Boolean(error['endDateError']), helperText: ((_a = error['endDateError']) === null || _a === void 0 ? void 0 : _a.error) ? (_jsx(FormattedMessage, { id: "ui.eventForm.time.end.error.invalid", defaultMessage: "ui.eventForm.time.end.error.invalid" })) : null }))); } }, slotProps: { toolbar: { // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment // @ts-ignore toolbarTitle: _jsx(FormattedMessage, { id: "ui.eventForm.time.title", defaultMessage: "ui.eventForm.time.title" }) } }, onChange: (value) => handleChangeDateTime(value, 'endTime'), shouldDisableTime: shouldDisableTime })] })) })), _jsx(EventAddress, Object.assign({ forwardGeolocationData: handleGeoData, forwardLivestreamSettingsData: handleLiveStreamSettingsData, event: Object.assign(Object.assign({}, event), { name: field.name, start_date: field.startDate, location: field.location, geolocation: field.geolocation, live_stream: Object.assign(Object.assign({ title: field.name || `${intl.formatMessage(messages.name)}` }, (event && ((_c = event.live_stream) === null || _c === void 0 ? void 0 : _c.created_at) && { created_at: field.startDate })), { settings: field.liveStreamSettings }) }) }, EventAddressComponentProps)), privateEnabled && (_jsxs(Box, Object.assign({ className: classes.privacySection }, { children: [_jsxs(Stack, Object.assign({ direction: "row", spacing: 1, alignItems: "center", justifyContent: "center" }, { children: [_jsxs(Typography, Object.assign({ className: classNames(classes.switchLabel, { [classes.active]: !field.isPublic }) }, { children: [_jsx(Icon, { children: "private" }), _jsx(FormattedMessage, { id: "ui.eventForm.privacy.private", defaultMessage: "ui.eventForm.privacy.private" })] })), _jsx(Switch, { className: classes.switch, checked: field.isPublic, onChange: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['isPublic']: !field.isPublic }))), disabled: event && !field.isPublic }), _jsxs(Typography, Object.assign({ className: classNames(classes.switchLabel, { [classes.active]: field.isPublic }) }, { children: [_jsx(Icon, { children: "public" }), _jsx(FormattedMessage, { id: "ui.eventForm.privacy.public", defaultMessage: "ui.eventForm.privacy.public" })] }))] })), _jsx(Typography, Object.assign({ variant: "body2", textAlign: "center", className: classes.privacySectionInfo }, { children: field.isPublic ? (_jsx(FormattedMessage, { id: "ui.eventForm.privacy.public.info", defaultMessage: "ui.eventForm.privacy.public.info", values: { // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment // @ts-ignores b: (chunks) => _jsx("strong", { children: chunks }) } })) : (_jsx(FormattedMessage, { id: "ui.eventForm.privacy.private.info", defaultMessage: "ui.eventForm.private.public.info", values: { // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment // @ts-ignore b: (chunks) => _jsx("strong", { children: chunks }) } })) }))] }))), _jsx(TextField, { multiline: true, className: classes.description, placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: { endAdornment: (_jsx(Typography, Object.assign({ variant: "body2" }, { children: ((_d = field.description) === null || _d === void 0 ? void 0 : _d.length) ? EVENT_DESCRIPTION_MAX_LENGTH - field.description.length : EVENT_DESCRIPTION_MAX_LENGTH }))) }, error: Boolean(((_e = field.description) === null || _e === void 0 ? void 0 : _e.length) > EVENT_DESCRIPTION_MAX_LENGTH), helperText: ((_f = field.description) === null || _f === void 0 ? void 0 : _f.length) > EVENT_DESCRIPTION_MAX_LENGTH ? (_jsx(FormattedMessage, { id: "ui.eventForm.description.error.maxLength", defaultMessage: "ui.eventForm.description.error.maxLength" })) : null }), 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.name || !field.startDate || !field.startTime || !field.endDate || !field.endTime || Boolean(genericError) || (field.location === SCEventLocationType.ONLINE && !field.link) || (field.location === SCEventLocationType.PERSON && !field.geolocation) || (field.recurring !== SCEventRecurrenceType.NEVER && !field.endDate && !field.endTime) || field.isSubmitting || field.name.length > EVENT_TITLE_MAX_LENGTH || field.description.length > EVENT_DESCRIPTION_MAX_LENGTH || (field.location === SCEventLocationType.LIVESTREAM && (!liveStreamEnabled || !canCreateLiveStream)), variant: "contained", onClick: handleSubmit, color: "secondary" }, { children: event ? (_jsx(FormattedMessage, { id: "ui.eventForm.button.edit", defaultMessage: "ui.eventForm.button.edit" })) : (_jsx(FormattedMessage, { id: "ui.eventForm.button.create", defaultMessage: "ui.eventForm.button.create" })) })) }))] }))] }))); }