Added useApi hook.
This commit is contained in:
@@ -8,7 +8,7 @@ import FormLayout, {
|
||||
FormMessage,
|
||||
FormRow,
|
||||
} from 'components/layout/FormLayout';
|
||||
import usePost from 'hooks/usePost';
|
||||
import useApi from 'hooks/useApi';
|
||||
|
||||
const initialValues = {
|
||||
username: '',
|
||||
@@ -29,11 +29,11 @@ const validate = ({ user_id, username, password }) => {
|
||||
};
|
||||
|
||||
export default function AccountEditForm({ values, onSave, onClose }) {
|
||||
const post = usePost();
|
||||
const { post } = useApi();
|
||||
const [message, setMessage] = useState();
|
||||
|
||||
const handleSubmit = async values => {
|
||||
const { ok, data } = await post('/api/account', values);
|
||||
const { ok, data } = await post('/account', values);
|
||||
|
||||
if (ok) {
|
||||
onSave();
|
||||
|
||||
@@ -8,7 +8,7 @@ import FormLayout, {
|
||||
FormMessage,
|
||||
FormRow,
|
||||
} from 'components/layout/FormLayout';
|
||||
import usePost from 'hooks/usePost';
|
||||
import useApi from 'hooks/useApi';
|
||||
|
||||
const initialValues = {
|
||||
current_password: '',
|
||||
@@ -37,11 +37,11 @@ const validate = ({ current_password, new_password, confirm_password }) => {
|
||||
};
|
||||
|
||||
export default function ChangePasswordForm({ values, onSave, onClose }) {
|
||||
const post = usePost();
|
||||
const { post } = useApi();
|
||||
const [message, setMessage] = useState();
|
||||
|
||||
const handleSubmit = async values => {
|
||||
const { ok, data } = await post('/api/account/password', values);
|
||||
const { ok, data } = await post('/account/password', values);
|
||||
|
||||
if (ok) {
|
||||
onSave();
|
||||
|
||||
@@ -8,7 +8,7 @@ import FormLayout, {
|
||||
FormMessage,
|
||||
FormRow,
|
||||
} from 'components/layout/FormLayout';
|
||||
import useDelete from 'hooks/useDelete';
|
||||
import useApi from 'hooks/useApi';
|
||||
|
||||
const CONFIRMATION_WORD = 'DELETE';
|
||||
|
||||
@@ -27,11 +27,11 @@ const validate = ({ confirmation }) => {
|
||||
};
|
||||
|
||||
export default function DeleteForm({ values, onSave, onClose }) {
|
||||
const del = useDelete();
|
||||
const { del } = useApi();
|
||||
const [message, setMessage] = useState();
|
||||
|
||||
const handleSubmit = async ({ type, id }) => {
|
||||
const { ok, data } = await del(`/api/${type}/${id}`);
|
||||
const { ok, data } = await del(`/${type}/${id}`);
|
||||
|
||||
if (ok) {
|
||||
onSave();
|
||||
|
||||
@@ -10,7 +10,7 @@ import FormLayout, {
|
||||
FormRow,
|
||||
} from 'components/layout/FormLayout';
|
||||
import Icon from 'components/common/Icon';
|
||||
import usePost from 'hooks/usePost';
|
||||
import useApi from 'hooks/useApi';
|
||||
import { setItem } from 'lib/web';
|
||||
import { AUTH_TOKEN } from 'lib/constants';
|
||||
import { setUser } from 'store/app';
|
||||
@@ -31,12 +31,12 @@ const validate = ({ username, password }) => {
|
||||
};
|
||||
|
||||
export default function LoginForm() {
|
||||
const post = usePost();
|
||||
const { post } = useApi();
|
||||
const router = useRouter();
|
||||
const [message, setMessage] = useState();
|
||||
|
||||
const handleSubmit = async ({ username, password }) => {
|
||||
const { ok, status, data } = await post('/api/auth/login', {
|
||||
const { ok, status, data } = await post('/auth/login', {
|
||||
username,
|
||||
password,
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ import FormLayout, {
|
||||
FormMessage,
|
||||
FormRow,
|
||||
} from 'components/layout/FormLayout';
|
||||
import usePost from 'hooks/usePost';
|
||||
import useApi from 'hooks/useApi';
|
||||
|
||||
const CONFIRMATION_WORD = 'RESET';
|
||||
|
||||
@@ -27,11 +27,11 @@ const validate = ({ confirmation }) => {
|
||||
};
|
||||
|
||||
export default function ResetForm({ values, onSave, onClose }) {
|
||||
const post = usePost();
|
||||
const { post } = useApi();
|
||||
const [message, setMessage] = useState();
|
||||
|
||||
const handleSubmit = async ({ type, id }) => {
|
||||
const { ok, data } = await post(`/api/${type}/${id}/reset`);
|
||||
const { ok, data } = await post(`/${type}/${id}/reset`);
|
||||
|
||||
if (ok) {
|
||||
onSave();
|
||||
|
||||
@@ -10,7 +10,7 @@ import FormLayout, {
|
||||
} from 'components/layout/FormLayout';
|
||||
import Checkbox from 'components/common/Checkbox';
|
||||
import { DOMAIN_REGEX } from 'lib/constants';
|
||||
import usePost from 'hooks/usePost';
|
||||
import useApi from 'hooks/useApi';
|
||||
|
||||
const initialValues = {
|
||||
name: '',
|
||||
@@ -34,11 +34,11 @@ const validate = ({ name, domain }) => {
|
||||
};
|
||||
|
||||
export default function WebsiteEditForm({ values, onSave, onClose }) {
|
||||
const post = usePost();
|
||||
const { post } = useApi();
|
||||
const [message, setMessage] = useState();
|
||||
|
||||
const handleSubmit = async values => {
|
||||
const { ok, data } = await post('/api/website', values);
|
||||
const { ok, data } = await post('/website', values);
|
||||
|
||||
if (ok) {
|
||||
onSave();
|
||||
|
||||
Reference in New Issue
Block a user