import { ChangeEvent, FC, useEffect, useRef, useState } from "react"; import toast from "react-hot-toast"; import { useTranslation } from "react-i18next"; import { useUpdateInfoMutation } from "@/app/services/user"; import Modal from "@/components/Modal"; import Button from "@/components/styled/Button"; import Input from "@/components/styled/Input"; import StyledModal from "@/components/styled/Modal"; interface Props { label?: string; valueKey?: "name" | "email"; type?: string; value?: string; title?: string; intro?: string; closeModal: () => void; } const ProfileBasicEditModal: FC = ({ label = "Username", valueKey = "name", value = "", type = "text", title = "Change your username", intro = "Enter a new username and your existing password.", closeModal }) => { const formRef = useRef(null); const { t } = useTranslation(); const [input, setInput] = useState(value); const [update, { isLoading, isSuccess }] = useUpdateInfoMutation(); const handleChange = (evt: ChangeEvent) => { setInput(evt.target.value); }; const handleUpdate = () => { if (!formRef || !formRef.current) return; const formEle = formRef.current as HTMLFormElement; if (!formEle.checkValidity()) { formEle.reportValidity(); return; } update({ [valueKey]: input }); }; useEffect(() => { if (isSuccess) { // todo toast.success(t("tip.update")); closeModal(); } }, [isSuccess]); return ( } >
); }; export default ProfileBasicEditModal;