From 84935724240f3da772df54a131c56d22a155424d Mon Sep 17 00:00:00 2001
From: Orkhan Ashrafov <70017511+webofpies@users.noreply.github.com>
Date: Fri, 7 Feb 2025 01:33:03 +0400
Subject: [PATCH] refactor: language and new book forms
---
.../components/NewBookForm/NewBookForm.jsx | 86 ++-----------------
.../components/ImportURLInfoPopup.jsx | 28 ++++++
.../src/features/book/hooks/useNewBookForm.js | 31 +++++++
.../components/LanguageForm/LanguageForm.jsx | 75 +++-------------
.../language/hooks/useLanguageForm.js | 38 ++++++++
.../language/hooks/useSelectedLanguage.js | 36 ++++++++
frontend/src/pages/LanguagesPage.jsx | 17 ++++
frontend/src/pages/NewBookPage.jsx | 41 ++++++++-
8 files changed, 204 insertions(+), 148 deletions(-)
create mode 100644 frontend/src/features/book/components/NewBookForm/components/ImportURLInfoPopup.jsx
create mode 100644 frontend/src/features/book/hooks/useNewBookForm.js
create mode 100644 frontend/src/features/language/hooks/useLanguageForm.js
create mode 100644 frontend/src/features/language/hooks/useSelectedLanguage.js
diff --git a/frontend/src/features/book/components/NewBookForm/NewBookForm.jsx b/frontend/src/features/book/components/NewBookForm/NewBookForm.jsx
index b81361dd..35521a09 100644
--- a/frontend/src/features/book/components/NewBookForm/NewBookForm.jsx
+++ b/frontend/src/features/book/components/NewBookForm/NewBookForm.jsx
@@ -1,21 +1,15 @@
import { useNavigate, useSearchParams } from "react-router-dom";
import { useMutation, useQuery } from "@tanstack/react-query";
-import { useForm } from "@mantine/form";
import { notifications } from "@mantine/notifications";
import {
- ActionIcon,
Button,
Fieldset,
FileInput,
Group,
NumberInput,
- Paper,
- Popover,
- rem,
Select,
Stack,
TagsInput,
- Text,
Textarea,
TextInput,
} from "@mantine/core";
@@ -26,21 +20,19 @@ import {
IconHeading,
IconHeadphones,
IconLink,
- IconQuestionMark,
- IconSquareRoundedPlusFilled,
IconTags,
IconWorldWww,
} from "@tabler/icons-react";
-import LanguageCards from "@language/components/LanguageCards/LanguageCards";
import FormButtons from "@common/FormButtons/FormButtons";
import { userLanguageQuery } from "@language/api/query";
import { initialQuery } from "@settings/api/settings";
import { errorMessage } from "@resources/notifications";
import { createBook, getBookDataFromUrl } from "../../api/api";
-import { getFormDataFromObj } from "@actions/utils";
+import useNewBookForm from "@book/hooks/useNewBookForm";
+import ImportURLInfoPopup from "./components/ImportURLInfoPopup";
import classes from "./NewBookForm.module.css";
-function NewBookForm({ openDrawer }) {
+function NewBookForm() {
const navigate = useNavigate();
const [params] = useSearchParams();
const langId = params.get("langId");
@@ -49,43 +41,7 @@ function NewBookForm({ openDrawer }) {
const { data: initial } = useQuery(initialQuery);
const dir = language?.right_to_left ? "rtl" : "ltr";
- const form = useForm({
- initialValues: {
- language_id: "",
- title: "",
- text: "",
- importurl: "",
- text_file: undefined,
- audio_file: undefined,
- threshold_page_tokens: 250,
- split_by: "paragraphs",
- source_uri: "",
- book_tags: [],
- },
- transformValues: (values) => {
- const data = {
- ...values,
- language_id: Number(langId),
- };
-
- return getFormDataFromObj(data);
- },
- });
-
- const cardsRadioLabel = (
-