mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Support basePath in all queries.
This commit is contained in:
parent
2508198a51
commit
5068ab12a9
11 changed files with 57 additions and 29 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import React, { useState } from 'react';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { Formik, Form, Field } from 'formik';
|
||||
import { useRouter } from 'next/router';
|
||||
import { post } from 'lib/web';
|
||||
import Button from 'components/common/Button';
|
||||
import FormLayout, {
|
||||
|
|
@ -29,10 +30,11 @@ const validate = ({ user_id, username, password }) => {
|
|||
};
|
||||
|
||||
export default function AccountEditForm({ values, onSave, onClose }) {
|
||||
const { basePath } = useRouter();
|
||||
const [message, setMessage] = useState();
|
||||
|
||||
const handleSubmit = async values => {
|
||||
const { ok, data } = await post(`/api/account`, values);
|
||||
const { ok, data } = await post(`${basePath}/api/account`, values);
|
||||
|
||||
if (ok) {
|
||||
onSave();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import React, { useState } from 'react';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { useRouter } from 'next/router';
|
||||
import { Formik, Form, Field } from 'formik';
|
||||
import { post } from 'lib/web';
|
||||
import Button from 'components/common/Button';
|
||||
|
|
@ -37,10 +38,11 @@ const validate = ({ current_password, new_password, confirm_password }) => {
|
|||
};
|
||||
|
||||
export default function ChangePasswordForm({ values, onSave, onClose }) {
|
||||
const { basePath } = useRouter();
|
||||
const [message, setMessage] = useState();
|
||||
|
||||
const handleSubmit = async values => {
|
||||
const { ok, data } = await post(`/api/account/password`, values);
|
||||
const { ok, data } = await post(`${basePath}/api/account/password`, values);
|
||||
|
||||
if (ok) {
|
||||
onSave();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
import React, { useState } from 'react';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { useRouter } from 'next/router';
|
||||
import { Formik, Form, Field } from 'formik';
|
||||
import { del } from 'lib/web';
|
||||
import Button from 'components/common/Button';
|
||||
|
|
@ -8,7 +10,6 @@ import FormLayout, {
|
|||
FormMessage,
|
||||
FormRow,
|
||||
} from 'components/layout/FormLayout';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
|
||||
const CONFIRMATION_WORD = 'DELETE';
|
||||
|
||||
|
|
@ -27,15 +28,18 @@ const validate = ({ confirmation }) => {
|
|||
};
|
||||
|
||||
export default function DeleteForm({ values, onSave, onClose }) {
|
||||
const { basePath } = useRouter();
|
||||
const [message, setMessage] = useState();
|
||||
|
||||
const handleSubmit = async ({ type, id }) => {
|
||||
const response = await del(`/api/${type}/${id}`);
|
||||
const { ok, data } = await del(`${basePath}/api/${type}/${id}`);
|
||||
|
||||
if (typeof response !== 'string') {
|
||||
if (ok) {
|
||||
onSave();
|
||||
} else {
|
||||
setMessage(<FormattedMessage id="message.failure" defaultMessage="Something went wrong." />);
|
||||
setMessage(
|
||||
data || <FormattedMessage id="message.failure" defaultMessage="Something went wrong." />,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React, { useState } from 'react';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { Formik, Form, Field } from 'formik';
|
||||
import Router from 'next/router';
|
||||
import { useRouter } from 'next/router';
|
||||
import { post } from 'lib/web';
|
||||
import Button from 'components/common/Button';
|
||||
import FormLayout, {
|
||||
|
|
@ -28,13 +28,17 @@ const validate = ({ username, password }) => {
|
|||
};
|
||||
|
||||
export default function LoginForm() {
|
||||
const router = useRouter();
|
||||
const [message, setMessage] = useState();
|
||||
|
||||
const handleSubmit = async ({ username, password }) => {
|
||||
const { ok, status, data } = await post('/api/auth/login', { username, password });
|
||||
const { ok, status, data } = await post(`${router.basePath}/api/auth/login`, {
|
||||
username,
|
||||
password,
|
||||
});
|
||||
|
||||
if (ok) {
|
||||
await Router.push('/');
|
||||
return router.push('/');
|
||||
} else {
|
||||
setMessage(
|
||||
status === 401 ? (
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import FormLayout, {
|
|||
} from 'components/layout/FormLayout';
|
||||
import Checkbox from 'components/common/Checkbox';
|
||||
import { DOMAIN_REGEX } from 'lib/constants';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
const initialValues = {
|
||||
name: '',
|
||||
|
|
@ -34,10 +35,11 @@ const validate = ({ name, domain }) => {
|
|||
};
|
||||
|
||||
export default function WebsiteEditForm({ values, onSave, onClose }) {
|
||||
const { basePath } = useRouter();
|
||||
const [message, setMessage] = useState();
|
||||
|
||||
const handleSubmit = async values => {
|
||||
const { ok, data } = await post(`/api/website`, values);
|
||||
const { ok, data } = await post(`${basePath}/api/website`, values);
|
||||
|
||||
if (ok) {
|
||||
onSave();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue