import { useFormState } from "react-use-form-state"; import { Flex } from "reflexbox/styled-components"; import React, { FC, useState } from "react"; import axios from "axios"; import { getAxiosConfig } from "../../utils"; import { useMessage } from "../../hooks"; import TextInput from "../TextInput"; import { API } from "../../consts"; import { Button } from "../Button"; import Icon from "../Icon"; import Text, { H2 } from "../Text"; import { Col } from "../Layout"; const SettingsPassword: FC = () => { const [loading, setLoading] = useState(false); const [message, setMessage] = useMessage(); const [formState, { password }] = useFormState<{ password: string }>(); 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( API.CHANGE_PASSWORD, 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 (

Change password

Enter a new password to change your current password. { const val = value.trim(); if (!val || val.length < 8) { return "Password must be at least 8 chars."; } } })} placeholder="New password" height={44} width={[1, 2 / 3]} pl={24} pr={24} mr={3} required /> {message.text} ); }; export default SettingsPassword;