import clsx from 'clsx'; import React, { useEffect, useState } from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { changeGroupEditorTitle, changeGroupEditorDescription, changeGroupEditorMedia, } from 'soapbox/actions/groups'; import { Avatar, Form, FormGroup, HStack, Icon, Input, Text, Textarea } from 'soapbox/components/ui'; import { useAppDispatch, useAppSelector, useDebounce, useInstance } from 'soapbox/hooks'; import { useGroupValidation } from 'soapbox/hooks/api'; import { isDefaultAvatar, isDefaultHeader } from 'soapbox/utils/accounts'; import resizeImage from 'soapbox/utils/resize-image'; import type { List as ImmutableList } from 'immutable'; interface IMediaInput { src: string | null accept: string onChange: React.ChangeEventHandler disabled: boolean } const messages = defineMessages({ groupNamePlaceholder: { id: 'manage_group.fields.name_placeholder', defaultMessage: 'Group Name' }, groupDescriptionPlaceholder: { id: 'manage_group.fields.description_placeholder', defaultMessage: 'Description' }, }); const HeaderPicker: React.FC = ({ src, onChange, accept, disabled }) => { return ( ); }; const AvatarPicker: React.FC = ({ src, onChange, accept, disabled }) => { return ( ); }; const DetailsStep = () => { const intl = useIntl(); const debounce = useDebounce; const dispatch = useAppDispatch(); const instance = useInstance(); const groupId = useAppSelector((state) => state.group_editor.groupId); 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 debouncedName = debounce(name, 300); const { data: { isValid, message: errorMessage } } = useGroupValidation(debouncedName); 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/')).toArray().join(','); 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); } }; useEffect(() => { if (!groupId) return; dispatch((_, getState) => { const group = getState().groups.items.get(groupId); if (!group) return; if (group.avatar && !isDefaultAvatar(group.avatar)) setAvatarSrc(group.avatar); if (group.header && !isDefaultHeader(group.header)) setHeaderSrc(group.header); }); }, [groupId]); return (
} hintText={} errors={isValid ? [] : [errorMessage as string]} > } >