import React from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { Form, FormGroup, Input, Streamfield, Textarea } from 'soapbox/components/ui'; import AvatarPicker from 'soapbox/features/group/components/group-avatar-picker'; import HeaderPicker from 'soapbox/features/group/components/group-header-picker'; import { useAppSelector, useDebounce, useInstance } from 'soapbox/hooks'; import { CreateGroupParams, useGroupValidation } from 'soapbox/hooks/api'; import { usePreview } from 'soapbox/hooks/forms'; 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' }, hashtagPlaceholder: { id: 'manage_group.fields.hashtag_placeholder', defaultMessage: 'Add a topic' }, }); interface IDetailsStep { params: CreateGroupParams onChange(params: CreateGroupParams): void } const DetailsStep: React.FC = ({ params, onChange }) => { const intl = useIntl(); const debounce = useDebounce; const instance = useInstance(); const { display_name: displayName = '', note = '', tags = [''], } = params; const debouncedName = debounce(displayName, 300); const { data: { isValid, message: errorMessage } } = useGroupValidation(debouncedName); const avatarSrc = usePreview(params.avatar); const headerSrc = usePreview(params.header); const attachmentTypes = useAppSelector( state => state.instance.configuration.getIn(['media_attachments', 'supported_mime_types']) as ImmutableList, )?.filter(type => type.startsWith('image/')).toArray().join(','); const handleTextChange = (property: keyof CreateGroupParams): React.ChangeEventHandler => { return (e) => { onChange({ ...params, [property]: e.target.value, }); }; }; const handleImageChange = (property: keyof CreateGroupParams, maxPixels?: number): React.ChangeEventHandler => { return async ({ target: { files } }) => { const file = files ? files[0] : undefined; if (file) { const resized = await resizeImage(file, maxPixels); onChange({ ...params, [property]: resized, }); } }; }; const handleTagsChange = (tags: string[]) => { onChange({ ...params, tags, }); }; const handleAddTag = () => { onChange({ ...params, tags: [...tags, ''], }); }; const handleRemoveTag = (i: number) => { const newTags = [...tags]; newTags.splice(i, 1); onChange({ ...params, tags: newTags, }); }; return (
} hintText={} errors={isValid ? [] : [errorMessage as string]} > } >