- {cover && (
-

- )}
- {!cover && editable && (
+

+ {!watch_cover && !cover && editable && (
)}
diff --git a/src/widgets/itemInfo/itemDetails.tsx b/src/widgets/itemInfo/itemDetails.tsx
index 6706e40..f98f995 100644
--- a/src/widgets/itemInfo/itemDetails.tsx
+++ b/src/widgets/itemInfo/itemDetails.tsx
@@ -1,5 +1,9 @@
import { ItemCreateType, ItemType } from "@/entities/item";
-import { UseFormRegister, UseFormSetValue } from "react-hook-form";
+import {
+ useFormContext,
+ UseFormRegister,
+ UseFormSetValue,
+} from "react-hook-form";
import clsx from "clsx";
import { SpinnerIcon } from "@/shared/assets/icons";
@@ -8,23 +12,22 @@ export const ItemDetails = ({
description,
editable,
state,
- registerFormField: register,
- setFormValue: setValue,
}: {
- title: {
- title: string;
- default_title: string;
- error: string | undefined;
- };
- description: {
- description: string | null | undefined;
- default_description: string | null | undefined;
- };
+ title: string;
+ description: string | null | undefined;
editable: boolean;
state: "saved" | "editing" | "error";
- registerFormField: UseFormRegister
;
- setFormValue: UseFormSetValue;
}) => {
+ const {
+ register,
+ setValue,
+ watch,
+ formState: { errors },
+ } = useFormContext();
+
+ const watched_title = watch("title");
+ const watched_description = watch("description");
+
return (
@@ -32,7 +35,7 @@ export const ItemDetails = ({
@@ -46,7 +49,7 @@ export const ItemDetails = ({
)}
suppressContentEditableWarning={true}
contentEditable={editable}
- {...register("title", { value: title.default_title })}
+ {...register("title", { value: title })}
onInput={(e) => {
setValue("title", e.currentTarget.innerText, {
shouldValidate: true,
@@ -54,7 +57,7 @@ export const ItemDetails = ({
});
}}
>
- {title.default_title}
+ {title}
{editable && (
@@ -73,14 +76,14 @@ export const ItemDetails = ({
)}
- {title.error}
- {(description.default_description || editable) && (
+ {errors.title?.message}
+ {(description || editable) && (
{editable && (
{
setValue("description", e.currentTarget.innerText, {
@@ -106,7 +109,7 @@ export const ItemDetails = ({
});
}}
>
- {description.default_description}
+ {description}
)}
diff --git a/src/widgets/itemInfo/itemFragment.tsx b/src/widgets/itemInfo/itemFragment.tsx
index e8f49f0..81e8dd8 100644
--- a/src/widgets/itemInfo/itemFragment.tsx
+++ b/src/widgets/itemInfo/itemFragment.tsx
@@ -1,21 +1,25 @@
import { FilesService } from "@/entities/files";
-import { ItemCreateType, ItemType } from "@/entities/item";
-import { useCallback } from "react";
+import { ItemCreateType } from "@/entities/item";
+import { useCallback, useEffect } from "react";
import { useDropzone } from "react-dropzone";
-import { UseFormRegister, UseFormSetValue } from "react-hook-form";
+import { useFormContext } from "react-hook-form";
import clsx from "clsx";
export const ItemFragment = ({
fragment,
editable,
- setFormValue: setValue,
- registerFormField: register,
}: {
fragment: string | undefined | null;
editable: boolean;
- setFormValue: UseFormSetValue