import { useMemo } from "react"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import ReactPlayer from "react-player/lazy"; import { FormLabel } from "~/shared/ui/form-label"; import { Input } from "~/shared/ui/input"; import { FileButton } from "~/shared/ui/file-button"; import { Button } from "~/shared/ui/button"; import { CoverButton } from "~/pages/root/steps/data-step/components/cover-button"; import { HiddenFileInput } from "~/shared/ui/hidden-file-input"; import { useRootStore } from "~/shared/stores/root"; import { Checkbox } from "~/shared/ui/checkbox"; import { AudioPlayer } from "~/shared/ui/audio-player"; import { HashtagInput } from "~/shared/ui/hashtag-input"; type DataStepProps = { nextStep(): void; }; export const DataStep = ({ nextStep }: DataStepProps) => { const rootStore = useRootStore(); const formSchema = useMemo(() => { return z.object({ name: z.string().min(1, "Обязательное поле"), author: z.string().optional(), }); }, []); type FormValues = z.infer; const form = useForm({ resolver: zodResolver(formSchema), mode: "onChange", defaultValues: { name: rootStore.name, author: rootStore?.author, }, }); const handleSubmit = () => { form.handleSubmit(async (values: FormValues) => { try { rootStore.setName(values.name); if (values.author) { rootStore.setAuthor(values.author); } nextStep(); } catch (error) { console.error("Error:", error); } })(); }; return (
/Заполните информацию о контенте
1/5
{ rootStore.setFile(file); rootStore.setFileSrc(URL.createObjectURL(file)); rootStore.setFileType(file.type); // Save the file type for conditional rendering }} /> {!rootStore.fileSrc && } {rootStore.fileSrc && (
{rootStore.fileType?.startsWith("audio") ? ( ) : ( )}
)}
rootStore.setAllowCover(!rootStore.allowCover)} checked={rootStore.allowCover} /> } /> {rootStore.allowCover && ( { rootStore.setCover(cover); }} /> {rootStore.cover ? ( { rootStore.setCover(null); }} /> ) : ( )} )}
); };