import { useFormState } from "react-use-form-state"; import { Flex } from "rebass/styled-components"; import React, { FC, useState } from "react"; import axios from "axios"; import { getAxiosConfig } from "../../utils"; import { useMessage } from "../../hooks"; import { TextInput } from "../Input"; import { APIv2 } from "../../consts"; import { Button } from "../Button"; import Text, { H2 } from "../Text"; import { Col } from "../Layout"; import Icon from "../Icon"; const SettingsPassword: FC = () => { const [loading, setLoading] = useState(false); const [message, setMessage] = useMessage(2000); const [formState, { password, label }] = useFormState<{ password: string }>( null, { withIds: true } ); const onSubmit = async (e) => { e.preventDefault(); if (loading) return; if (!formState.validity.password) { return setMessage(formState.errors.password); } setLoading(true); setMessage(); try { const res = await axios.post( APIv2.AuthChangePassword, formState.values, getAxiosConfig() ); formState.clear(); setMessage(res.data.message, "green"); } catch (err) { setMessage(err?.response?.data?.error || "Couldn't update the password."); } setLoading(false); }; return (