refactor tags create page

This commit is contained in:
Alex Holliday committed 2026-08-07 09:47:11 -07:00
1 parent 0eff052258
commit 012e09d30c
1 file changed
+7 -23
+7 -23
View File
@@ -6,7 +6,7 @@ import { useTheme } from "@mui/material/styles";
import { useEffect } from "react"; import { useEffect } from "react";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { Controller, useForm } from "react-hook-form"; import { useForm, FormProvider } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod"; import { zodResolver } from "@hookform/resolvers/zod";
import { mutate } from "swr"; import { mutate } from "swr";
import { useGet, usePost, usePatch } from "@/Hooks/UseApi"; import { useGet, usePost, usePatch } from "@/Hooks/UseApi";
@@ -14,6 +14,8 @@ import type { TagFormData } from "@/Validation/tag";
import type { Tag } from "@/Types/Tag"; import type { Tag } from "@/Types/Tag";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useTagsForm } from "@/Hooks/useTagsForm"; import { useTagsForm } from "@/Hooks/useTagsForm";
import { FormTextField } from "@/Components/inputs/forms/FormTextField";
import { FormColorField } from "@/Components/inputs/forms/FormColorField";
const TagsCreatePage = () => { const TagsCreatePage = () => {
const { t } = useTranslation(); const { t } = useTranslation();
@@ -51,6 +53,7 @@ const TagsCreatePage = () => {
}; };
return ( return (
<FormProvider {...form}>
<BasePage <BasePage
component="form" component="form"
onSubmit={handleSubmit(onSubmit)} onSubmit={handleSubmit(onSubmit)}
@@ -59,21 +62,10 @@ const TagsCreatePage = () => {
title={t("pages.tags.form.name.title")} title={t("pages.tags.form.name.title")}
subtitle={t("pages.tags.form.name.description")} subtitle={t("pages.tags.form.name.description")}
rightContent={ rightContent={
<Controller <FormTextField
name="name" name="name"
control={control}
defaultValue={defaults.name}
render={({ field, fieldState }) => (
<TextField
{...field}
type="text"
fieldLabel={t("pages.tags.form.name.optionName")} fieldLabel={t("pages.tags.form.name.optionName")}
placeholder={t("pages.tags.form.name.placeholder")} placeholder={t("pages.tags.form.name.placeholder")}
fullWidth
error={!!fieldState.error}
helperText={fieldState.error?.message ?? ""}
/>
)}
/> />
} }
/> />
@@ -81,19 +73,10 @@ const TagsCreatePage = () => {
title={t("pages.tags.form.color.title")} title={t("pages.tags.form.color.title")}
subtitle={t("pages.tags.form.color.description")} subtitle={t("pages.tags.form.color.description")}
rightContent={ rightContent={
<Controller <FormColorField
name="color" name="color"
control={control}
defaultValue={defaults.color}
render={({ field }) => (
<ColorInput
format="hex"
value={field.value}
onChange={field.onChange}
fieldLabel={t("pages.tags.form.color.optionName")} fieldLabel={t("pages.tags.form.color.optionName")}
/> />
)}
/>
} }
/> />
@@ -112,6 +95,7 @@ const TagsCreatePage = () => {
</Button> </Button>
</Stack> </Stack>
</BasePage> </BasePage>
</FormProvider>
); );
}; };