mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 09:45:04 +01:00
Merge branch 'dev' of https://github.com/umami-software/umami into dev
# Conflicts: # components/forms/UserPasswordForm.js # components/pages/Dashboard.js
This commit is contained in:
commit
db6a6d6055
@ -1,16 +1,15 @@
|
|||||||
import { useRef } from 'react';
|
import { useRef } from 'react';
|
||||||
import { Form, FormInput, FormButtons, PasswordField, Button } from 'react-basics';
|
import { Form, FormInput, FormButtons, PasswordField, Button } from 'react-basics';
|
||||||
import useApi from 'hooks/useApi';
|
import useApi from 'hooks/useApi';
|
||||||
import { useMutation } from '@tanstack/react-query';
|
|
||||||
import styles from './UserPasswordForm.module.css';
|
import styles from './UserPasswordForm.module.css';
|
||||||
import useUser from 'hooks/useUser';
|
import useUser from 'hooks/useUser';
|
||||||
|
|
||||||
export default function UserPasswordForm({ onSave, userId }) {
|
export default function UserPasswordForm({ onSave, onClose, userId }) {
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
|
|
||||||
const isCurrentUser = !userId || user?.id === userId;
|
const isCurrentUser = !userId || user?.id === userId;
|
||||||
const url = isCurrentUser ? `/users/${user?.id}/password` : `/users/${user?.id}`;
|
const url = isCurrentUser ? `/users/${user?.id}/password` : `/users/${user?.id}`;
|
||||||
const { post } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error, isLoading } = useMutation(data => post(url, data));
|
const { mutate, error, isLoading } = useMutation(data => post(url, data));
|
||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
|
|
||||||
@ -65,9 +64,10 @@ export default function UserPasswordForm({ onSave, userId }) {
|
|||||||
<PasswordField autoComplete="off" />
|
<PasswordField autoComplete="off" />
|
||||||
</FormInput>
|
</FormInput>
|
||||||
<FormButtons flex>
|
<FormButtons flex>
|
||||||
<Button type="submit" disabled={isLoading}>
|
<Button type="submit" variant="primary" disabled={isLoading}>
|
||||||
Save
|
Save
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button onClick={onClose}>Close</Button>
|
||||||
</FormButtons>
|
</FormButtons>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
import { Button, Loading } from 'react-basics';
|
||||||
import { defineMessages, useIntl } from 'react-intl';
|
import { defineMessages, useIntl } from 'react-intl';
|
||||||
import Page from 'components/layout/Page';
|
import Page from 'components/layout/Page';
|
||||||
import PageHeader from 'components/layout/PageHeader';
|
import PageHeader from 'components/layout/PageHeader';
|
||||||
import WebsiteList from 'components/pages/WebsiteList';
|
import WebsiteChartList from 'components/pages/WebsiteChartList';
|
||||||
import { Button, Loading } from 'react-basics';
|
|
||||||
import DashboardSettingsButton from 'components/settings/DashboardSettingsButton';
|
import DashboardSettingsButton from 'components/settings/DashboardSettingsButton';
|
||||||
import useApi from 'hooks/useApi';
|
import useApi from 'hooks/useApi';
|
||||||
import useDashboard from 'store/dashboard';
|
import useDashboard from 'store/dashboard';
|
||||||
@ -42,7 +42,7 @@ export default function Dashboard({ userId }) {
|
|||||||
{!editing && <DashboardSettingsButton />}
|
{!editing && <DashboardSettingsButton />}
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
{editing && <DashboardEdit websites={data} />}
|
{editing && <DashboardEdit websites={data} />}
|
||||||
{!editing && <WebsiteList websites={data} showCharts={showCharts} limit={max} />}
|
{!editing && <WebsiteChartList websites={data} showCharts={showCharts} limit={max} />}
|
||||||
{max < data.length && (
|
{max < data.length && (
|
||||||
<Button className={styles.button} onClick={handleMore}>
|
<Button className={styles.button} onClick={handleMore}>
|
||||||
{formatMessage(messages.more)}
|
{formatMessage(messages.more)}
|
||||||
|
@ -2,15 +2,26 @@ import Page from 'components/layout/Page';
|
|||||||
import PageHeader from 'components/layout/PageHeader';
|
import PageHeader from 'components/layout/PageHeader';
|
||||||
import ProfileDetails from 'components/settings/ProfileDetails';
|
import ProfileDetails from 'components/settings/ProfileDetails';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Breadcrumbs, Item, Tabs, useToast } from 'react-basics';
|
import { Breadcrumbs, Icon, Item, Tabs, useToast, Modal, Button } from 'react-basics';
|
||||||
import UserPasswordForm from 'components/forms/UserPasswordForm';
|
import UserPasswordForm from 'components/forms/UserPasswordForm';
|
||||||
|
import Pen from 'assets/pen.svg';
|
||||||
|
|
||||||
export default function ProfileSettings() {
|
export default function ProfileSettings() {
|
||||||
|
const [edit, setEdit] = useState(false);
|
||||||
const [tab, setTab] = useState('general');
|
const [tab, setTab] = useState('general');
|
||||||
const { toast, showToast } = useToast();
|
const { toast, showToast } = useToast();
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
showToast({ message: 'Saved successfully.', variant: 'success' });
|
showToast({ message: 'Saved successfully.', variant: 'success' });
|
||||||
|
setEdit(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAdd = () => {
|
||||||
|
setEdit(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
setEdit(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -20,13 +31,22 @@ export default function ProfileSettings() {
|
|||||||
<Breadcrumbs>
|
<Breadcrumbs>
|
||||||
<Item>Profile</Item>
|
<Item>Profile</Item>
|
||||||
</Breadcrumbs>
|
</Breadcrumbs>
|
||||||
|
<Button onClick={handleAdd}>
|
||||||
|
<Icon>
|
||||||
|
<Pen />
|
||||||
|
</Icon>
|
||||||
|
Change Password
|
||||||
|
</Button>
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
<Tabs selectedKey={tab} onSelect={setTab} style={{ marginBottom: 30, fontSize: 14 }}>
|
<Tabs selectedKey={tab} onSelect={setTab} style={{ marginBottom: 30, fontSize: 14 }}>
|
||||||
<Item key="general">General</Item>
|
<Item key="general">General</Item>
|
||||||
<Item key="password">Password</Item>
|
|
||||||
</Tabs>
|
</Tabs>
|
||||||
{tab === 'general' && <ProfileDetails />}
|
{tab === 'general' && <ProfileDetails />}
|
||||||
{tab === 'password' && <UserPasswordForm onSave={handleSave} />}
|
{edit && (
|
||||||
|
<Modal title="Add website" onClose={handleClose}>
|
||||||
|
{close => <UserPasswordForm onSave={handleSave} onClose={close} />}
|
||||||
|
</Modal>
|
||||||
|
)}
|
||||||
</Page>
|
</Page>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,11 @@ import useApi from 'hooks/useApi';
|
|||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Breadcrumbs, Item, Tabs, useToast } from 'react-basics';
|
import { Breadcrumbs, Item, Icon, Tabs, useToast, Modal, Button } from 'react-basics';
|
||||||
|
import Pen from 'assets/pen.svg';
|
||||||
|
|
||||||
export default function UserSettings({ userId }) {
|
export default function UserSettings({ userId }) {
|
||||||
|
const [edit, setEdit] = useState(false);
|
||||||
const [values, setValues] = useState(null);
|
const [values, setValues] = useState(null);
|
||||||
const [tab, setTab] = useState('general');
|
const [tab, setTab] = useState('general');
|
||||||
const { get } = useApi();
|
const { get } = useApi();
|
||||||
@ -31,6 +33,18 @@ export default function UserSettings({ userId }) {
|
|||||||
if (data) {
|
if (data) {
|
||||||
setValues(state => ({ ...state, ...data }));
|
setValues(state => ({ ...state, ...data }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (edit) {
|
||||||
|
setEdit(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAdd = () => {
|
||||||
|
setEdit(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
setEdit(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete = async () => {
|
const handleDelete = async () => {
|
||||||
@ -54,15 +68,26 @@ export default function UserSettings({ userId }) {
|
|||||||
</Item>
|
</Item>
|
||||||
<Item>{values?.username}</Item>
|
<Item>{values?.username}</Item>
|
||||||
</Breadcrumbs>
|
</Breadcrumbs>
|
||||||
|
<Button onClick={handleAdd}>
|
||||||
|
<Icon>
|
||||||
|
<Pen />
|
||||||
|
</Icon>
|
||||||
|
Change Password
|
||||||
|
</Button>
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
<Tabs selectedKey={tab} onSelect={setTab} style={{ marginBottom: 30, fontSize: 14 }}>
|
<Tabs selectedKey={tab} onSelect={setTab} style={{ marginBottom: 30, fontSize: 14 }}>
|
||||||
<Item key="general">General</Item>
|
<Item key="general">General</Item>
|
||||||
<Item key="password">Password</Item>
|
|
||||||
<Item key="delete">Danger Zone</Item>
|
<Item key="delete">Danger Zone</Item>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
{tab === 'general' && <UserEditForm userId={userId} data={values} onSave={handleSave} />}
|
{tab === 'general' && <UserEditForm userId={userId} data={values} onSave={handleSave} />}
|
||||||
{tab === 'password' && <UserPasswordForm userId={userId} data={values} onSave={handleSave} />}
|
|
||||||
{tab === 'delete' && <UserDelete userId={userId} onSave={handleDelete} />}
|
{tab === 'delete' && <UserDelete userId={userId} onSave={handleDelete} />}
|
||||||
|
{edit && (
|
||||||
|
<Modal title="Add website" onClose={handleClose}>
|
||||||
|
{close => (
|
||||||
|
<UserPasswordForm userId={userId} data={values} onSave={handleSave} onClose={close} />
|
||||||
|
)}
|
||||||
|
</Modal>
|
||||||
|
)}
|
||||||
</Page>
|
</Page>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import useUser from 'hooks/useUser';
|
|||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
import DateRangeSetting from './DateRangeSetting';
|
import DateRangeSetting from './DateRangeSetting';
|
||||||
import LanguageSetting from './LanguageSetting';
|
import LanguageSetting from './LanguageSetting';
|
||||||
import styles from './ProfileSettings.module.css';
|
import styles from './ProfileDetails.module.css';
|
||||||
import ThemeSetting from './ThemeSetting';
|
import ThemeSetting from './ThemeSetting';
|
||||||
|
|
||||||
export default function ProfileDetails() {
|
export default function ProfileDetails() {
|
||||||
|
Loading…
Reference in New Issue
Block a user