'use client'; import { useMutation } from '@tanstack/react-query'; import { FormEvent, useState } from 'react'; import { uploadProjectAudio } from '../lib/api'; interface AudioUploadProps { projectId: string; onSuccess?: () => void; } export function AudioUpload({ projectId, onSuccess }: AudioUploadProps) { const [file, setFile] = useState(null); const mutation = useMutation({ mutationFn: async () => { if (!file) { throw new Error('Please select an audio file to upload.'); } await uploadProjectAudio(projectId, file); }, onSuccess }); const handleSubmit = (event: FormEvent) => { event.preventDefault(); mutation.mutate(); }; return (

Upload Audio

Attach a new audio track to this project.

setFile(event.target.files?.[0] ?? null)} className="block w-full rounded-md border border-slate-300 px-3 py-2 text-sm" /> {mutation.isError && (

{(mutation.error as Error).message}

)} {mutation.isSuccess &&

Audio uploaded successfully!

}
); }