/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ import React from "react"; import { useHistory, useParams } from "react-router-dom"; import { useForm } from "react-hook-form"; import { useTopicArea } from "../hooks"; import BackendService from "../services/BackendService"; import TextField from "../components/TextField"; import Button from "../components/Button"; import Breadcrumbs from "../components/Breadcrumbs"; import AlertContainer from "./AlertContainer"; import { useTranslation } from "react-i18next"; interface FormValues { name: string; topicAreaId: string; description: string; } interface PathParams { topicAreaId: string; } function EditTopicArea() { const history = useHistory(); const { topicAreaId } = useParams(); const { register, errors, handleSubmit } = useForm(); const { topicarea } = useTopicArea(topicAreaId); const { t } = useTranslation(); const onSubmit = async (values: FormValues) => { try { await BackendService.renameTopicArea(topicAreaId, values.name); history.push("/admin/settings/topicarea", { alert: { type: "success", message: t("SettingsTopicAreaNameEditSuccess", { name: values.name, }), }, }); } catch (err) { history.push(`/admin/settings/topicarea/${topicAreaId}/edit`, { alert: { type: "error", message: t("SettingsTopicAreaNameEditProblem", { name: values.name, }), }, }); } }; const onCancel = () => { history.push("/admin/settings/topicarea"); }; if (!topicarea) { return null; } return ( <>

{t("SettingsTopicAreaNameEdit")}


); } export default EditTopicArea;