import React, { useState } from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { changeGroupEditorTitle, changeGroupEditorDescription, changeGroupEditorMedia, } from 'soapbox/actions/groups'; import Icon from 'soapbox/components/icon'; import { Avatar, Form, FormGroup, HStack, IconButton, Input, Text, Textarea } from 'soapbox/components/ui'; import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; import resizeImage from 'soapbox/utils/resize-image'; import type { List as ImmutableList } from 'immutable'; const messages = defineMessages({ groupNamePlaceholder: { id: 'manage_group.fields.name_placeholder', defaultMessage: 'Group Name' }, groupDescriptionPlaceholder: { id: 'manage_group.fields.description_placeholder', defaultMessage: 'Description' }, }); const DetailsStep = () => { const intl = useIntl(); const dispatch = useAppDispatch(); const isUploading = useAppSelector((state) => state.group_editor.isUploading); const name = useAppSelector((state) => state.group_editor.displayName); const description = useAppSelector((state) => state.group_editor.note); const [avatarSrc, setAvatarSrc] = useState(null); const [headerSrc, setHeaderSrc] = useState(null); const attachmentTypes = useAppSelector(state => state.instance.configuration.getIn(['media_attachments', 'supported_mime_types']) as ImmutableList)?.filter(type => type.startsWith('image/')); const onChangeName: React.ChangeEventHandler = ({ target }) => { dispatch(changeGroupEditorTitle(target.value)); }; const onChangeDescription: React.ChangeEventHandler = ({ target }) => { dispatch(changeGroupEditorDescription(target.value)); }; const handleFileChange: React.ChangeEventHandler = e => { const rawFile = e.target.files?.item(0); if (!rawFile) return; if (e.target.name === 'avatar') { resizeImage(rawFile, 400 * 400).then(file => { dispatch(changeGroupEditorMedia('avatar', file)); setAvatarSrc(URL.createObjectURL(file)); }).catch(console.error); } else { resizeImage(rawFile, 1920 * 1080).then(file => { dispatch(changeGroupEditorMedia('header', file)); setHeaderSrc(URL.createObjectURL(file)); }).catch(console.error); } }; return (
{headerSrc ? ( <> {}} /> ) : ( )}
{avatarSrc ? ( ) : ( )}
} > } >