import { useMutation } from '@tanstack/react-query'; import { useState } from 'react'; import { useErrorText } from '../../shared/lib/errors'; import { useUploadsApi } from './queries'; import { useTranslation } from 'react-i18next'; import { Button, Dialog, Field, FormError } from '../../shared/ui/ui'; import s from '../../pages/page.module.css'; export function BatchEditDialog({ batchId, onClose, onSaved }: { batchId: string; onClose: () => void; onSaved: () => void }) { const { t } = useTranslation(['admin', 'common']); const api = useUploadsApi(); const errorText = useErrorText(); const [artist, setArtist] = useState(''); const [album, setAlbum] = useState(''); const [year, setYear] = useState(''); const [cover, setCover] = useState(undefined); const save = useMutation({ mutationFn: () => api.updateBatch(batchId, { ...(artist.trim() ? { artist: artist.trim() } : {}), ...(album.trim() ? { album: album.trim() } : {}), ...(year.trim() ? { year: Number.parseInt(year, 10) } : {}), ...(cover !== undefined ? { cover_base64: cover } : {}), }), onSuccess: onSaved, }); const pickCover = (file: File | undefined) => { if (!file) { setCover(undefined); return; } const reader = new FileReader(); reader.onload = () => { const data = String(reader.result ?? ''); const comma = data.indexOf(','); setCover(comma >= 0 ? data.slice(comma + 1) : data); }; reader.readAsDataURL(file); }; return ( } >

{t('uploads.batch_edit_hint')}

{save.error ? errorText(save.error) : null}
); }