261 lines
7.5 KiB
TypeScript
261 lines
7.5 KiB
TypeScript
/**
|
||
* Renders the editor of the site's categories, on the "manage" tab of one's own
|
||
* profile for a user with the `category:manage` permission.
|
||
*
|
||
* @module
|
||
*/
|
||
|
||
import { useState } from "react";
|
||
import { t } from "@lingui/core/macro";
|
||
import { Trans } from "@lingui/react/macro";
|
||
|
||
import { API_URL } from "../../config/api.ts";
|
||
import { VALIDATION } from "../../../shared/validation.ts";
|
||
import type {
|
||
Category,
|
||
CreateCategoryRequest,
|
||
UpdateCategoryRequest,
|
||
} from "../../../shared/category.ts";
|
||
import type { Wire } from "../../../shared/api.ts";
|
||
import { useAuth } from "../../hooks/auth/useAuth.ts";
|
||
import { useCategories } from "../../hooks/category/useCategories.ts";
|
||
import { ConfirmModal } from "../shared/ConfirmModal.tsx";
|
||
import { expectOk } from "../../utils/shared/api.ts";
|
||
import { FormError } from "../form/FormError.tsx";
|
||
import { FormProvider } from "react-hook-form";
|
||
import { SubmitButton } from "../form/SubmitButton.tsx";
|
||
import { useApiForm } from "../../hooks/form/useApiForm.ts";
|
||
|
||
interface CategoryFields {
|
||
name: string;
|
||
slug: string;
|
||
}
|
||
|
||
/**
|
||
* The value of `editing` while a new category is being created. Its leading
|
||
* space keeps it from matching a category id.
|
||
*/
|
||
const NEW = " |