import React from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import Toggle from 'react-toggle'; import { changeCreateEventApprovalRequired, changeCreateEventDescription, changeCreateEventEndTime, changeCreateEventHasEndTime, changeCreateEventName, changeCreateEventStartTime, changeCreateEventLocation, uploadEventBanner, undoUploadEventBanner, submitEvent, } from 'soapbox/actions/events'; import { ADDRESS_ICONS } from 'soapbox/components/autosuggest-location'; import LocationSearch from 'soapbox/components/location-search'; import { Form, FormGroup, HStack, Icon, IconButton, Input, Modal, Stack, Text, Textarea } from 'soapbox/components/ui'; import { isCurrentOrFutureDate } from 'soapbox/features/compose/components/schedule_form'; import BundleContainer from 'soapbox/features/ui/containers/bundle_container'; import { DatePicker } from 'soapbox/features/ui/util/async-components'; import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; import UploadButton from './upload-button'; const messages = defineMessages({ eventNamePlaceholder: { id: 'create_event.fields.name_placeholder', defaultMessage: 'Name' }, eventDescriptionPlaceholder: { id: 'create_event.fields.description_placeholder', defaultMessage: 'Description' }, eventStartTimePlaceholder: { id: 'create_event.fields.start_time_placeholder', defaultMessage: 'Event begins on…' }, eventEndTimePlaceholder: { id: 'create_event.fields.end_time_placeholder', defaultMessage: 'Event ends on…' }, resetLocation: { id: 'create_event.reset_location', defaultMessage: 'Reset location' }, }); interface ICreateEventModal { onClose: (type?: string) => void, } const CreateEventModal: React.FC = ({ onClose }) => { const intl = useIntl(); const dispatch = useAppDispatch(); const banner = useAppSelector((state) => state.create_event.banner); const isUploading = useAppSelector((state) => state.create_event.is_uploading); const name = useAppSelector((state) => state.create_event.name); const description = useAppSelector((state) => state.create_event.status); const startTime = useAppSelector((state) => state.create_event.start_time); const endTime = useAppSelector((state) => state.create_event.end_time); const approvalRequired = useAppSelector((state) => state.create_event.approval_required); const location = useAppSelector((state) => state.create_event.location); const isSubmitting = useAppSelector((state) => state.create_event.is_submitting); const onChangeName: React.ChangeEventHandler = ({ target }) => { dispatch(changeCreateEventName(target.value)); }; const onChangeDescription: React.ChangeEventHandler = ({ target }) => { dispatch(changeCreateEventDescription(target.value)); }; const onChangeStartTime = (date: Date) => { dispatch(changeCreateEventStartTime(date)); }; const onChangeEndTime = (date: Date) => { dispatch(changeCreateEventEndTime(date)); }; const onChangeHasEndTime: React.ChangeEventHandler = ({ target }) => { dispatch(changeCreateEventHasEndTime(target.checked)); }; const onChangeApprovalRequired: React.ChangeEventHandler = ({ target }) => { dispatch(changeCreateEventApprovalRequired(target.checked)); }; const onChangeLocation = (value: string | null) => { dispatch(changeCreateEventLocation(value)); }; const onClickClose = () => { onClose('CREATE_EVENT'); }; const handleFiles = (files: FileList) => { dispatch(uploadEventBanner(files[0], intl)); }; const handleClearBanner = () => { dispatch(undoUploadEventBanner()); }; const handleSubmit = () => { dispatch(submitEvent()); }; const renderLocation = () => location && ( {location.description} {[location.street, location.locality, location.country].filter(val => val.trim()).join(' · ')} onChangeLocation(null)} /> ); return ( } confirmationAction={handleSubmit} confirmationText={} confirmationDisabled={isSubmitting} onClose={onClickClose} >
} >
{banner ? ( <> ) : ( )}
} > } hintText={} >