/* eslint-disable eslint-comments/disable-enable-pair */ /* eslint-disable @typescript-eslint/no-unnecessary-condition */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import clsx from 'clsx' import { FormControl } from 'components/FormControl' import { FormGroup } from 'components/FormGroup' import { useInputState } from 'components/forms/FormInput.hooks' import type { ChangeEvent } from 'react' import { useEffect, useState } from 'react' import { toast } from 'react-hot-toast' import { TextInput } from '../../forms/FormInput' import type { UploadMethod } from './UploadDetails' interface CollectionDetailsProps { onChange: (data: CollectionDetailsDataProps) => void uploadMethod: UploadMethod coverImageUrl: string } export interface CollectionDetailsDataProps { name: string description: string imageFile: File[] externalLink?: string } export const CollectionDetails = ({ onChange, uploadMethod, coverImageUrl }: CollectionDetailsProps) => { const [coverImage, setCoverImage] = useState(null) const nameState = useInputState({ id: 'name', name: 'name', title: 'Name', placeholder: 'My Awesome Collection', }) const descriptionState = useInputState({ id: 'description', name: 'description', title: 'Description', placeholder: 'My Awesome Collection Description', }) const externalLinkState = useInputState({ id: 'external-link', name: 'externalLink', title: 'External Link', placeholder: 'https://my-collection...', }) useEffect(() => { try { const data: CollectionDetailsDataProps = { name: nameState.value, description: descriptionState.value, imageFile: coverImage ? [coverImage] : [], externalLink: externalLinkState.value, } onChange(data) // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { toast.error(error.message) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [nameState.value, descriptionState.value, coverImage, externalLinkState.value]) const selectCoverImage = (event: ChangeEvent) => { if (event.target.files === null) return toast.error('Error selecting cover image') if (event.target.files.length === 0) { setCoverImage(null) return toast.error('No files selected.') } const reader = new FileReader() reader.onload = (e) => { if (!e.target?.result) return toast.error('Error parsing file.') if (!event.target.files) return toast.error('No files selected.') const imageFile = new File([e.target.result], event.target.files[0].name, { type: 'image/jpg' }) setCoverImage(imageFile) } reader.readAsArrayBuffer(event.target.files[0]) } return (
{uploadMethod === 'new' && ( )} {coverImage !== null && uploadMethod === 'new' && (
no-preview-available
)} {uploadMethod === 'existing' && coverImageUrl?.includes('ipfs://') && (
no-preview-available
)} {uploadMethod === 'existing' && coverImageUrl && !coverImageUrl?.includes('ipfs://') && (
no-preview-available
)} {uploadMethod === 'existing' && !coverImageUrl && ( Waiting for cover image URL to be specified. )}
) }