mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 06:07:17 +01:00
Updated settings components.
This commit is contained in:
parent
1d9c3133f0
commit
91af593ff5
31 changed files with 805 additions and 494 deletions
|
|
@ -1,25 +1,16 @@
|
|||
import PropTypes from 'prop-types';
|
||||
import { Icon, Flexbox } from 'react-basics';
|
||||
import { Icon, Text, Flexbox } from 'react-basics';
|
||||
import Logo from 'assets/logo.svg';
|
||||
import styles from './EmptyPlaceholder.module.css';
|
||||
|
||||
function EmptyPlaceholder({ msg, children }) {
|
||||
return (
|
||||
<div className={styles.placeholder}>
|
||||
<Icon className={styles.icon} size="xl">
|
||||
<Flexbox direction="column" alignItems="center" justifyContent="center" gap={60} height={600}>
|
||||
<Icon size="xl">
|
||||
<Logo />
|
||||
</Icon>
|
||||
<h2 className={styles.msg}>{msg}</h2>
|
||||
<Flexbox justifyContent="center" alignItems="center">
|
||||
{children}
|
||||
</Flexbox>
|
||||
</div>
|
||||
<Text size="lg">{msg}</Text>
|
||||
<div>{children}</div>
|
||||
</Flexbox>
|
||||
);
|
||||
}
|
||||
|
||||
EmptyPlaceholder.propTypes = {
|
||||
msg: PropTypes.node,
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
export default EmptyPlaceholder;
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
.placeholder {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 600px;
|
||||
}
|
||||
|
||||
.icon {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.msg {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
import Calendar from 'assets/calendar.svg';
|
||||
import Clock from 'assets/clock.svg';
|
||||
import Dashboard from 'assets/dashboard.svg';
|
||||
import Edit from 'assets/edit.svg';
|
||||
import Gear from 'assets/gear.svg';
|
||||
import Globe from 'assets/globe.svg';
|
||||
import Lock from 'assets/lock.svg';
|
||||
import Logo from 'assets/logo.svg';
|
||||
import Moon from 'assets/moon.svg';
|
||||
import Profile from 'assets/profile.svg';
|
||||
|
|
@ -10,4 +12,18 @@ import Sun from 'assets/sun.svg';
|
|||
import User from 'assets/user.svg';
|
||||
import Users from 'assets/users.svg';
|
||||
|
||||
export { Calendar, Clock, Dashboard, Gear, Globe, Logo, Moon, Profile, Sun, User, Users };
|
||||
export {
|
||||
Calendar,
|
||||
Clock,
|
||||
Dashboard,
|
||||
Edit,
|
||||
Gear,
|
||||
Globe,
|
||||
Lock,
|
||||
Logo,
|
||||
Moon,
|
||||
Profile,
|
||||
Sun,
|
||||
User,
|
||||
Users,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,19 +4,22 @@ import classNames from 'classnames';
|
|||
import { Dashboard, Logo, Profile, User, Users, Clock, Globe } from 'components/icons';
|
||||
import NavGroup from './NavGroup';
|
||||
import styles from './NavBar.module.css';
|
||||
import ThemeButton from '../buttons/ThemeButton';
|
||||
import LanguageButton from '../buttons/LanguageButton';
|
||||
|
||||
const { ChevronDown, Search } = Icons;
|
||||
|
||||
const analytics = [
|
||||
{ key: 'dashboard', label: 'Dashboard', url: '/dashboard', icon: <Dashboard /> },
|
||||
{ key: 'realtime', label: 'Realtime', url: '/realtime', icon: <Clock /> },
|
||||
{ key: 'queries', label: 'Queries', url: '/queries', icon: <Search /> },
|
||||
{ label: 'Dashboard', url: '/dashboard', icon: <Dashboard /> },
|
||||
{ label: 'Realtime', url: '/realtime', icon: <Clock /> },
|
||||
{ label: 'Queries', url: '/queries', icon: <Search /> },
|
||||
];
|
||||
|
||||
const settings = [
|
||||
{ key: 'websites', label: 'Websites', url: '/settings/websites', icon: <Globe /> },
|
||||
{ key: 'users', label: 'Users', url: '/settings/users', icon: <User /> },
|
||||
{ key: 'teams', label: 'Teams', url: '/settings/teams', icon: <Users /> },
|
||||
{ label: 'Websites', url: '/settings/websites', icon: <Globe /> },
|
||||
{ label: 'Users', url: '/settings/users', icon: <User /> },
|
||||
{ label: 'Teams', url: '/settings/teams', icon: <Users /> },
|
||||
{ label: 'Profile', url: '/settings/profile', icon: <Profile /> },
|
||||
];
|
||||
|
||||
export default function NavBar() {
|
||||
|
|
@ -38,10 +41,10 @@ export default function NavBar() {
|
|||
<NavGroup title="Analytics" items={analytics} minimized={minimized} />
|
||||
<NavGroup title="Settings" items={settings} minimized={minimized} />
|
||||
<div className={styles.footer}>
|
||||
<Icon>
|
||||
<Profile />
|
||||
</Icon>
|
||||
<Text>Profile</Text>
|
||||
<div className={styles.buttons}>
|
||||
<ThemeButton />
|
||||
<LanguageButton />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -45,3 +45,9 @@
|
|||
justify-content: flex-end;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,18 +26,23 @@ export default function NavGroup({
|
|||
[styles.minimized]: minimized,
|
||||
})}
|
||||
>
|
||||
<div className={styles.header} onClick={allowExpand ? handleExpand : undefined}>
|
||||
<Text>{title}</Text>
|
||||
<Icon size="sm" rotate={expanded ? 0 : -90}>
|
||||
<ChevronDown />
|
||||
</Icon>
|
||||
</div>
|
||||
{title && (
|
||||
<div className={styles.header} onClick={allowExpand ? handleExpand : undefined}>
|
||||
<Text>{title}</Text>
|
||||
<Icon size="sm" rotate={expanded ? 0 : -90}>
|
||||
<ChevronDown />
|
||||
</Icon>
|
||||
</div>
|
||||
)}
|
||||
<div className={styles.body}>
|
||||
{items.map(({ key, label, url, icon }) => {
|
||||
{items.map(({ label, url, icon, divider }) => {
|
||||
return (
|
||||
<Link key={key} href={url}>
|
||||
<Link key={label} href={url}>
|
||||
<a
|
||||
className={classNames(styles.item, { [styles.selected]: pathname.startsWith(url) })}
|
||||
className={classNames(styles.item, {
|
||||
[styles.divider]: divider,
|
||||
[styles.selected]: pathname.startsWith(url),
|
||||
})}
|
||||
>
|
||||
<Icon>{icon}</Icon>
|
||||
<Text className={styles.text}>{label}</Text>
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
}
|
||||
|
||||
.items {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
|
|
@ -33,6 +34,7 @@
|
|||
}
|
||||
|
||||
.item {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
|
|
@ -43,6 +45,10 @@
|
|||
width: 200px;
|
||||
}
|
||||
|
||||
a.item {
|
||||
color: var(--base700);
|
||||
}
|
||||
|
||||
.item.selected {
|
||||
color: var(--base900);
|
||||
border-right-color: var(--primary400);
|
||||
|
|
@ -58,10 +64,6 @@
|
|||
pointer-events: none;
|
||||
}
|
||||
|
||||
a.item {
|
||||
color: var(--base600);
|
||||
}
|
||||
|
||||
.minimized .text,
|
||||
.minimized .header {
|
||||
display: none;
|
||||
|
|
@ -74,3 +76,18 @@ a.item {
|
|||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.divider:before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin: auto;
|
||||
border-top: 1px solid var(--base300);
|
||||
width: 160px;
|
||||
}
|
||||
|
||||
.minimized .divider:before {
|
||||
width: 60px;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,8 +39,7 @@ export default function Dashboard({ userId }) {
|
|||
|
||||
return (
|
||||
<Page>
|
||||
<PageHeader>
|
||||
<div>{formatMessage(messages.dashboard)}</div>
|
||||
<PageHeader title={formatMessage(messages.dashboard)}>
|
||||
{!editing && <DashboardSettingsButton />}
|
||||
</PageHeader>
|
||||
{editing && <DashboardEdit websites={data} />}
|
||||
|
|
|
|||
46
components/pages/settings/profile/ChangePasswordButton.js
Normal file
46
components/pages/settings/profile/ChangePasswordButton.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { useState } from 'react';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
import { Button, Icon, Modal, useToast } from 'react-basics';
|
||||
import PasswordEditForm from 'components/pages/settings/profile/PasswordEditForm';
|
||||
import { Lock } from 'components/icons';
|
||||
|
||||
const messages = defineMessages({
|
||||
changePassword: { id: 'label.change-password', defaultMessage: 'Change password' },
|
||||
saved: { id: 'message.saved-successfully', defaultMessage: 'Saved successfully.' },
|
||||
});
|
||||
|
||||
export default function ChangePasswordButton() {
|
||||
const { formatMessage } = useIntl();
|
||||
const [edit, setEdit] = useState(false);
|
||||
const { toast, showToast } = useToast();
|
||||
|
||||
const handleSave = () => {
|
||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||
setEdit(false);
|
||||
};
|
||||
|
||||
const handleAdd = () => {
|
||||
setEdit(true);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setEdit(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{toast}
|
||||
<Button onClick={handleAdd}>
|
||||
<Icon>
|
||||
<Lock />
|
||||
</Icon>
|
||||
Change Password
|
||||
</Button>
|
||||
{edit && (
|
||||
<Modal title={formatMessage(messages.changePassword)} onClose={handleClose}>
|
||||
{() => <PasswordEditForm onSave={handleSave} onClose={handleClose} />}
|
||||
</Modal>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
76
components/pages/settings/profile/PasswordEditForm.js
Normal file
76
components/pages/settings/profile/PasswordEditForm.js
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
import { useRef } from 'react';
|
||||
import { Form, FormRow, FormInput, FormButtons, PasswordField, Button } from 'react-basics';
|
||||
import useApi from 'hooks/useApi';
|
||||
import useUser from 'hooks/useUser';
|
||||
|
||||
export default function PasswordEditForm({ userId, onSave, onClose }) {
|
||||
const user = useUser();
|
||||
const isCurrentUser = !userId || user?.id === userId;
|
||||
const url = isCurrentUser ? `/users/${user?.id}/password` : `/users/${user?.id}`;
|
||||
const { post, useMutation } = useApi();
|
||||
const { mutate, error, isLoading } = useMutation(data => post(url, data));
|
||||
const ref = useRef(null);
|
||||
|
||||
const handleSubmit = async data => {
|
||||
const payload = isCurrentUser
|
||||
? data
|
||||
: {
|
||||
password: data.newPassword,
|
||||
};
|
||||
|
||||
mutate(payload, {
|
||||
onSuccess: async () => {
|
||||
onSave();
|
||||
ref.current.reset();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const samePassword = value => {
|
||||
if (value !== ref?.current?.getValues('newPassword')) {
|
||||
return "Passwords don't match";
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
return (
|
||||
<Form ref={ref} onSubmit={handleSubmit} error={error}>
|
||||
{isCurrentUser && (
|
||||
<FormRow label="Current password">
|
||||
<FormInput name="currentPassword" rules={{ required: 'Required' }}>
|
||||
<PasswordField autoComplete="off" />
|
||||
</FormInput>
|
||||
</FormRow>
|
||||
)}
|
||||
<FormRow label="New password">
|
||||
<FormInput
|
||||
name="newPassword"
|
||||
rules={{
|
||||
required: 'Required',
|
||||
minLength: { value: 8, message: 'Minimum length 8 characters' },
|
||||
}}
|
||||
>
|
||||
<PasswordField autoComplete="off" />
|
||||
</FormInput>
|
||||
</FormRow>
|
||||
<FormRow label="Confirm password">
|
||||
<FormInput
|
||||
name="confirmPassword"
|
||||
rules={{
|
||||
required: 'Required',
|
||||
minLength: { value: 8, message: 'Minimum length 8 characters' },
|
||||
validate: samePassword,
|
||||
}}
|
||||
>
|
||||
<PasswordField autoComplete="off" />
|
||||
</FormInput>
|
||||
</FormRow>
|
||||
<FormButtons flex>
|
||||
<Button type="submit" variant="primary" disabled={isLoading}>
|
||||
Save
|
||||
</Button>
|
||||
<Button onClick={onClose}>Close</Button>
|
||||
</FormButtons>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,48 +1,26 @@
|
|||
import { Breadcrumbs, Item } from 'react-basics';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
import Page from 'components/layout/Page';
|
||||
import PageHeader from 'components/layout/PageHeader';
|
||||
import ProfileDetails from 'components/pages/settings/profile/ProfileDetails';
|
||||
import { useState } from 'react';
|
||||
import { Breadcrumbs, Icon, Item, useToast, Modal, Button } from 'react-basics';
|
||||
import UserPasswordForm from 'components/pages/settings/users/UserPasswordForm';
|
||||
import Lock from 'assets/lock.svg';
|
||||
import ProfileDetails from './ProfileDetails';
|
||||
import ChangePasswordButton from './ChangePasswordButton';
|
||||
|
||||
const messages = defineMessages({
|
||||
profile: { id: 'label.profile', defaultMessage: 'Profile' },
|
||||
});
|
||||
|
||||
export default function ProfileSettings() {
|
||||
const [edit, setEdit] = useState(false);
|
||||
const { toast, showToast } = useToast();
|
||||
|
||||
const handleSave = () => {
|
||||
showToast({ message: 'Saved successfully.', variant: 'success' });
|
||||
setEdit(false);
|
||||
};
|
||||
|
||||
const handleAdd = () => {
|
||||
setEdit(true);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setEdit(false);
|
||||
};
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
return (
|
||||
<Page>
|
||||
{toast}
|
||||
<PageHeader>
|
||||
<Breadcrumbs>
|
||||
<Item>Profile</Item>
|
||||
<Item>{formatMessage(messages.profile)}</Item>
|
||||
</Breadcrumbs>
|
||||
<Button onClick={handleAdd}>
|
||||
<Icon>
|
||||
<Lock />
|
||||
</Icon>
|
||||
Change Password
|
||||
</Button>
|
||||
<ChangePasswordButton />
|
||||
</PageHeader>
|
||||
<ProfileDetails />
|
||||
{edit && (
|
||||
<Modal title="Change password" onClose={handleClose}>
|
||||
{close => <UserPasswordForm onSave={handleSave} onClose={close} />}
|
||||
</Modal>
|
||||
)}
|
||||
</Page>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
65
components/pages/settings/users/UserAddForm.js
Normal file
65
components/pages/settings/users/UserAddForm.js
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import {
|
||||
Dropdown,
|
||||
Item,
|
||||
Form,
|
||||
FormRow,
|
||||
FormButtons,
|
||||
FormInput,
|
||||
TextField,
|
||||
PasswordField,
|
||||
SubmitButton,
|
||||
} from 'react-basics';
|
||||
import { useIntl, defineMessages } from 'react-intl';
|
||||
import useApi from 'hooks/useApi';
|
||||
import { ROLES } from 'lib/constants';
|
||||
|
||||
const messages = defineMessages({
|
||||
username: { id: 'label.username', defaultMessage: 'Username' },
|
||||
password: { id: 'label.password', defaultMessage: 'Password' },
|
||||
role: { id: 'label.role', defaultMessage: 'Role' },
|
||||
user: { id: 'label.user', defaultMessage: 'User' },
|
||||
admin: { id: 'label.admin', defaultMessage: 'Admin' },
|
||||
save: { id: 'label.save', defaultMessage: 'Save' },
|
||||
cancel: { id: 'label.cancel', defaultMessage: 'Cancel' },
|
||||
required: { id: 'label.required', defaultMessage: 'Required' },
|
||||
});
|
||||
|
||||
export default function UserAddForm({ onSave }) {
|
||||
const { post, useMutation } = useApi();
|
||||
const { mutate, error } = useMutation(data => post(`/users`, data));
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
const handleSubmit = async data => {
|
||||
mutate(data, {
|
||||
onSuccess: async () => {
|
||||
onSave(data);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Form onSubmit={handleSubmit} error={error}>
|
||||
<FormRow label={formatMessage(messages.username)}>
|
||||
<FormInput name="username" rules={{ required: formatMessage(messages.required) }}>
|
||||
<TextField />
|
||||
</FormInput>
|
||||
</FormRow>
|
||||
<FormRow label={formatMessage(messages.password)}>
|
||||
<FormInput name="password" rules={{ required: formatMessage(messages.required) }}>
|
||||
<PasswordField />
|
||||
</FormInput>
|
||||
</FormRow>
|
||||
<FormRow label={formatMessage(messages.role)}>
|
||||
<FormInput name="role" rules={{ required: formatMessage(messages.required) }}>
|
||||
<Dropdown style={{ width: 200 }}>
|
||||
<Item key={ROLES.user}>{formatMessage(messages.user)}</Item>
|
||||
<Item key={ROLES.admin}>{formatMessage(messages.admin)}</Item>
|
||||
</Dropdown>
|
||||
</FormInput>
|
||||
</FormRow>
|
||||
<FormButtons>
|
||||
<SubmitButton variant="primary">{formatMessage(messages.save)}</SubmitButton>
|
||||
</FormButtons>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
|
|
@ -9,7 +9,6 @@ import {
|
|||
SubmitButton,
|
||||
} from 'react-basics';
|
||||
import { useRef } from 'react';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import useApi from 'hooks/useApi';
|
||||
import { ROLES } from 'lib/constants';
|
||||
|
||||
|
|
@ -26,7 +25,7 @@ const items = [
|
|||
|
||||
export default function UserEditForm({ data, onSave }) {
|
||||
const { id } = data;
|
||||
const { post } = useApi();
|
||||
const { post, useMutation } = useApi();
|
||||
const { mutate, error } = useMutation(({ username }) => post(`/user/${id}`, { username }));
|
||||
const ref = useRef(null);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import useUser from 'hooks/useUser';
|
|||
|
||||
export default function UserPasswordForm({ onSave, onClose, userId }) {
|
||||
const user = useUser();
|
||||
|
||||
const isCurrentUser = !userId || user?.id === userId;
|
||||
const url = isCurrentUser ? `/users/${user?.id}/password` : `/users/${user?.id}`;
|
||||
const { post, useMutation } = useApi();
|
||||
|
|
|
|||
|
|
@ -1,21 +1,30 @@
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
import { Breadcrumbs, Item, Tabs, useToast } from 'react-basics';
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
import UserDelete from 'components/pages/settings/users/UserDelete';
|
||||
import UserEditForm from 'components/pages/settings/users/UserEditForm';
|
||||
import UserEditForm from 'components/pages/settings/users//UserEditForm';
|
||||
import UserPasswordForm from 'components/pages/settings/users/UserPasswordForm';
|
||||
import Page from 'components/layout/Page';
|
||||
import PageHeader from 'components/layout/PageHeader';
|
||||
import useApi from 'hooks/useApi';
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Breadcrumbs, Item, Icon, Tabs, useToast, Modal, Button } from 'react-basics';
|
||||
import Pen from 'assets/pen.svg';
|
||||
|
||||
const messages = defineMessages({
|
||||
users: { id: 'label.users', defaultMessage: 'Users' },
|
||||
details: { id: 'label.details', defaultMessage: 'Details' },
|
||||
changePassword: { id: 'label.change-password', defaultMessage: 'Change password' },
|
||||
actions: { id: 'label.actions', defaultMessage: 'Actions' },
|
||||
saved: { id: 'message.saved-successfully', defaultMessage: 'Saved successfully.' },
|
||||
delete: { id: 'message.delete-successfully', defaultMessage: 'Delete successfully.' },
|
||||
});
|
||||
|
||||
export default function UserSettings({ userId }) {
|
||||
const { formatMessage } = useIntl();
|
||||
const [edit, setEdit] = useState(false);
|
||||
const [values, setValues] = useState(null);
|
||||
const [tab, setTab] = useState('general');
|
||||
const { get } = useApi();
|
||||
const [tab, setTab] = useState('details');
|
||||
const { get, useQuery } = useApi();
|
||||
const { toast, showToast } = useToast();
|
||||
const router = useRouter();
|
||||
const { data, isLoading } = useQuery(
|
||||
|
|
@ -39,14 +48,6 @@ export default function UserSettings({ userId }) {
|
|||
}
|
||||
};
|
||||
|
||||
const handleAdd = () => {
|
||||
setEdit(true);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setEdit(false);
|
||||
};
|
||||
|
||||
const handleDelete = async () => {
|
||||
showToast({ message: 'Deleted successfully.', variant: 'danger' });
|
||||
await router.push('/users');
|
||||
|
|
@ -64,30 +65,19 @@ export default function UserSettings({ userId }) {
|
|||
<PageHeader>
|
||||
<Breadcrumbs>
|
||||
<Item>
|
||||
<Link href="/users">Users</Link>
|
||||
<Link href="/settings/users">{formatMessage(messages.users)}</Link>
|
||||
</Item>
|
||||
<Item>{values?.username}</Item>
|
||||
</Breadcrumbs>
|
||||
<Button onClick={handleAdd}>
|
||||
<Icon>
|
||||
<Pen />
|
||||
</Icon>
|
||||
Change Password
|
||||
</Button>
|
||||
</PageHeader>
|
||||
<Tabs selectedKey={tab} onSelect={setTab} style={{ marginBottom: 30, fontSize: 14 }}>
|
||||
<Item key="general">General</Item>
|
||||
<Item key="delete">Danger Zone</Item>
|
||||
<Item key="details">{formatMessage(messages.details)}</Item>
|
||||
<Item key="password">{formatMessage(messages.changePassword)}</Item>
|
||||
<Item key="delete">{formatMessage(messages.actions)}</Item>
|
||||
</Tabs>
|
||||
{tab === 'general' && <UserEditForm userId={userId} data={values} onSave={handleSave} />}
|
||||
{tab === 'details' && <UserEditForm userId={userId} data={values} onSave={handleSave} />}
|
||||
{tab === 'password' && <UserPasswordForm userId={userId} onSave={handleSave} />}
|
||||
{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>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,44 +1,69 @@
|
|||
import { useState } from 'react';
|
||||
import { Button, Text, Icon, useToast, Icons, Modal } from 'react-basics';
|
||||
import { useIntl, defineMessages } from 'react-intl';
|
||||
import Page from 'components/layout/Page';
|
||||
import PageHeader from 'components/layout/PageHeader';
|
||||
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
||||
import UsersTable from 'components/pages/settings/users/UsersTable';
|
||||
import { useState } from 'react';
|
||||
import { Button, Icon, useToast } from 'react-basics';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import UserEditForm from 'components/pages/settings/users/UserEditForm';
|
||||
import useApi from 'hooks/useApi';
|
||||
import useUser from 'hooks/useUser';
|
||||
|
||||
const { Plus } = Icons;
|
||||
|
||||
const messages = defineMessages({
|
||||
saved: { id: 'messages.api-key-saved', defaultMessage: 'API key saved.' },
|
||||
noUsers: {
|
||||
id: 'messages.no-useres',
|
||||
defaultMessage: "You don't have any users.",
|
||||
},
|
||||
users: { id: 'label.users', defaultMessage: 'Users' },
|
||||
createUser: { id: 'label.create-user', defaultMessage: 'Create user' },
|
||||
});
|
||||
|
||||
export default function UsersList() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState();
|
||||
const [edit, setEdit] = useState(false);
|
||||
const { formatMessage } = useIntl();
|
||||
const { toast, showToast } = useToast();
|
||||
const { post } = useApi();
|
||||
const { mutate, isLoading } = useMutation(data => post('/api-key', data));
|
||||
const { user } = useUser();
|
||||
const { get, useQuery } = useApi();
|
||||
const { data, isLoading, error, refetch } = useQuery(['user'], () => get(`/users`), {
|
||||
enabled: !!user,
|
||||
});
|
||||
const hasData = data && data.length !== 0;
|
||||
|
||||
const handleSave = () => {
|
||||
mutate(
|
||||
{},
|
||||
{
|
||||
onSuccess: async () => {
|
||||
showToast({ message: 'API key saved.', variant: 'success' });
|
||||
},
|
||||
},
|
||||
);
|
||||
const handleSave = async () => {
|
||||
await refetch();
|
||||
setEdit(false);
|
||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||
};
|
||||
|
||||
const handleAdd = () => setEdit(true);
|
||||
|
||||
const handleClose = () => setEdit(false);
|
||||
|
||||
const addButton = (
|
||||
<Button variant="primary" onClick={handleAdd}>
|
||||
<Icon>
|
||||
<Plus />
|
||||
</Icon>
|
||||
<Text>{formatMessage(messages.createUser)}</Text>
|
||||
</Button>
|
||||
);
|
||||
|
||||
return (
|
||||
<Page loading={loading || isLoading} error={error}>
|
||||
<Page loading={isLoading} error={error}>
|
||||
{toast}
|
||||
<PageHeader title="Users">
|
||||
<Button onClick={handleSave}>
|
||||
<Icon icon="plus" /> Create user
|
||||
</Button>
|
||||
</PageHeader>
|
||||
<UsersTable
|
||||
onLoading={({ isLoading, error }) => {
|
||||
setLoading(isLoading);
|
||||
setError(error);
|
||||
}}
|
||||
onAddKeyClick={handleSave}
|
||||
/>
|
||||
<PageHeader title={formatMessage(messages.users)}>{addButton}</PageHeader>
|
||||
{hasData && <UsersTable data={data} />}
|
||||
{!hasData && (
|
||||
<EmptyPlaceholder message={formatMessage(messages.noUsers)}>{addButton}</EmptyPlaceholder>
|
||||
)}
|
||||
{edit && (
|
||||
<Modal title={formatMessage(messages.createUser)} onClose={handleClose}>
|
||||
{close => <UserEditForm onSave={handleSave} onClose={close} />}
|
||||
</Modal>
|
||||
)}
|
||||
</Page>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,6 @@
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
||||
import { formatDistance } from 'date-fns';
|
||||
import useApi from 'hooks/useApi';
|
||||
import Link from 'next/link';
|
||||
import { useEffect, useState } from 'react';
|
||||
import {
|
||||
Button,
|
||||
Text,
|
||||
Icon,
|
||||
Table,
|
||||
TableBody,
|
||||
|
|
@ -14,84 +9,66 @@ import {
|
|||
TableHeader,
|
||||
TableRow,
|
||||
} from 'react-basics';
|
||||
import { formatDistance } from 'date-fns';
|
||||
import Link from 'next/link';
|
||||
import { Edit } from 'components/icons';
|
||||
import styles from './UsersTable.module.css';
|
||||
|
||||
const defaultColumns = [
|
||||
const columns = [
|
||||
{ name: 'username', label: 'Username', style: { flex: 2 } },
|
||||
{ name: 'role', label: 'Role', style: { flex: 2 } },
|
||||
{ name: 'created', label: 'Created' },
|
||||
{ name: 'action', label: ' ' },
|
||||
];
|
||||
|
||||
export default function UsersTable({ columns = defaultColumns, onLoading, onAddKeyClick }) {
|
||||
const [values, setValues] = useState(null);
|
||||
const { get } = useApi();
|
||||
const { data, isLoading, error } = useQuery(['user'], () => get(`/users`));
|
||||
const hasData = data && data.length !== 0;
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
setValues(data);
|
||||
onLoading({ data, isLoading, error });
|
||||
}
|
||||
}, [onLoading, data, isLoading, error]);
|
||||
|
||||
export default function UsersTable({ data = [] }) {
|
||||
return (
|
||||
<>
|
||||
{hasData && (
|
||||
<Table className={styles.table} columns={columns} rows={values}>
|
||||
<TableHeader>
|
||||
{(column, index) => {
|
||||
return (
|
||||
<TableColumn key={index} className={styles.header} style={{ ...column.style }}>
|
||||
{column.label}
|
||||
</TableColumn>
|
||||
);
|
||||
}}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{(row, keys, rowIndex) => {
|
||||
row.created = formatDistance(new Date(row.createdAt), new Date(), {
|
||||
addSuffix: true,
|
||||
});
|
||||
<Table className={styles.table} columns={columns} rows={data}>
|
||||
<TableHeader>
|
||||
{(column, index) => {
|
||||
return (
|
||||
<TableColumn key={index} className={styles.header} style={{ ...column.style }}>
|
||||
{column.label}
|
||||
</TableColumn>
|
||||
);
|
||||
}}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{(row, keys, rowIndex) => {
|
||||
row.created = formatDistance(new Date(row.createdAt), new Date(), {
|
||||
addSuffix: true,
|
||||
});
|
||||
|
||||
row.action = (
|
||||
<div className={styles.actions}>
|
||||
<Link href={`/settings/users/${row.id}`}>
|
||||
<Button>
|
||||
<Icon icon="arrow-right" />
|
||||
Settings
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
row.action = (
|
||||
<div className={styles.actions}>
|
||||
<Link href={`/settings/users/${row.id}`}>
|
||||
<Button>
|
||||
<Icon>
|
||||
<Edit />
|
||||
</Icon>
|
||||
<Text>Edit</Text>
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<TableRow key={rowIndex} data={row} keys={keys}>
|
||||
{(data, key, colIndex) => {
|
||||
return (
|
||||
<TableCell
|
||||
key={colIndex}
|
||||
className={styles.cell}
|
||||
style={{ ...columns[colIndex]?.style }}
|
||||
>
|
||||
{data[key]}
|
||||
</TableCell>
|
||||
);
|
||||
}}
|
||||
</TableRow>
|
||||
);
|
||||
}}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
{!hasData && (
|
||||
<EmptyPlaceholder className={styles.empty} msg="You don't have any Users.">
|
||||
<Button variant="primary" onClick={onAddKeyClick}>
|
||||
<Icon icon="plus" /> Create User
|
||||
</Button>
|
||||
</EmptyPlaceholder>
|
||||
)}
|
||||
</>
|
||||
return (
|
||||
<TableRow key={rowIndex} data={row} keys={keys}>
|
||||
{(data, key, colIndex) => {
|
||||
return (
|
||||
<TableCell
|
||||
key={colIndex}
|
||||
className={styles.cell}
|
||||
style={{ ...columns[colIndex]?.style }}
|
||||
>
|
||||
{data[key]}
|
||||
</TableCell>
|
||||
);
|
||||
}}
|
||||
</TableRow>
|
||||
);
|
||||
}}
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export default function ShareUrl({ websiteId, data, onSave }) {
|
|||
);
|
||||
const ref = useRef(null);
|
||||
const url = useMemo(
|
||||
() => `${process.env.analyticsUrl}/share/${id}/${encodeURIComponent(name)}`,
|
||||
() => `${process.env.analyticsUrl || location.origin}/share/${id}/${encodeURIComponent(name)}`,
|
||||
[id, name],
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export default function WebsiteEditForm({ websiteId, data, onSave }) {
|
|||
};
|
||||
|
||||
return (
|
||||
<Form ref={ref} onSubmit={handleSubmit} error={error} values={data}>
|
||||
<Form ref={ref} onSubmit={handleSubmit} error={error} values={data} style={{ width: 600 }}>
|
||||
<FormRow label="Website ID">
|
||||
<TextField value={websiteId} readOnly allowCopy />
|
||||
</FormRow>
|
||||
|
|
|
|||
|
|
@ -1,16 +1,29 @@
|
|||
import { useEffect, useState } from 'react';
|
||||
import { Breadcrumbs, Item, Tabs, useToast, Button, Icon } from 'react-basics';
|
||||
import useApi from 'hooks/useApi';
|
||||
import { Breadcrumbs, Item, Tabs, useToast, Button, Text, Icon, Icons } from 'react-basics';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
import Link from 'next/link';
|
||||
import Page from 'components/layout/Page';
|
||||
import PageHeader from 'components/layout/PageHeader';
|
||||
import WebsiteEditForm from 'components/pages/settings/websites/WebsiteEditForm';
|
||||
import WebsiteReset from 'components/pages/settings/websites/WebsiteReset';
|
||||
import PageHeader from 'components/layout/PageHeader';
|
||||
import TrackingCode from 'components/pages/settings/websites/TrackingCode';
|
||||
import ShareUrl from 'components/pages/settings/websites/ShareUrl';
|
||||
import ExternalLink from 'assets/external-link.svg';
|
||||
import useApi from 'hooks/useApi';
|
||||
|
||||
export default function WebsiteDetails({ websiteId }) {
|
||||
const { External } = Icons;
|
||||
|
||||
const messages = defineMessages({
|
||||
websites: { id: 'label.websites', defaultMessage: 'Websites' },
|
||||
details: { id: 'label.details', defaultMessage: 'Details' },
|
||||
trackingCode: { id: 'label.tracking-code', defaultMessage: 'Tracking code' },
|
||||
shareUrl: { id: 'label.share-url', defaultMessage: 'Share URL' },
|
||||
actions: { id: 'label.actions', defaultMessage: 'Actions' },
|
||||
view: { id: 'label.view', defaultMessage: 'View' },
|
||||
saved: { id: 'message.saved-successfully', defaultMessage: 'Save successfully.' },
|
||||
});
|
||||
|
||||
export default function WebsiteSettings({ websiteId }) {
|
||||
const { formatMessage } = useIntl();
|
||||
const [values, setValues] = useState(null);
|
||||
const [tab, setTab] = useState('details');
|
||||
const { get, useQuery } = useApi();
|
||||
|
|
@ -26,7 +39,7 @@ export default function WebsiteDetails({ websiteId }) {
|
|||
);
|
||||
|
||||
const handleSave = data => {
|
||||
showToast({ message: 'Saved successfully.', variant: 'success' });
|
||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||
setValues(state => ({ ...state, ...data }));
|
||||
};
|
||||
|
||||
|
|
@ -42,7 +55,7 @@ export default function WebsiteDetails({ websiteId }) {
|
|||
<PageHeader>
|
||||
<Breadcrumbs>
|
||||
<Item>
|
||||
<Link href="/settings/websites">Websites</Link>
|
||||
<Link href="/settings/websites">{formatMessage(messages.websites)}</Link>
|
||||
</Item>
|
||||
<Item>{values?.name}</Item>
|
||||
</Breadcrumbs>
|
||||
|
|
@ -50,18 +63,18 @@ export default function WebsiteDetails({ websiteId }) {
|
|||
<a>
|
||||
<Button variant="primary">
|
||||
<Icon>
|
||||
<ExternalLink />
|
||||
<External />
|
||||
</Icon>
|
||||
View
|
||||
<Text>{formatMessage(messages.view)}</Text>
|
||||
</Button>
|
||||
</a>
|
||||
</Link>
|
||||
</PageHeader>
|
||||
<Tabs selectedKey={tab} onSelect={setTab} style={{ marginBottom: 30 }}>
|
||||
<Item key="details">Details</Item>
|
||||
<Item key="tracking">Tracking code</Item>
|
||||
<Item key="share">Share URL</Item>
|
||||
<Item key="actions">Actions</Item>
|
||||
<Item key="details">{formatMessage(messages.details)}</Item>
|
||||
<Item key="tracking">{formatMessage(messages.trackingCode)}</Item>
|
||||
<Item key="share">{formatMessage(messages.shareUrl)}</Item>
|
||||
<Item key="actions">{formatMessage(messages.actions)}</Item>
|
||||
</Tabs>
|
||||
{tab === 'details' && (
|
||||
<WebsiteEditForm websiteId={websiteId} data={values} onSave={handleSave} />
|
||||
|
|
@ -1,72 +1,70 @@
|
|||
import { useState } from 'react';
|
||||
import { Button, Icon, Text, Modal, useToast, Icons } from 'react-basics';
|
||||
import useApi from 'hooks/useApi';
|
||||
import { useIntl, defineMessages } from 'react-intl';
|
||||
import Page from 'components/layout/Page';
|
||||
import PageHeader from 'components/layout/PageHeader';
|
||||
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
||||
import WebsiteAddForm from 'components/pages/settings/websites/WebsiteAddForm';
|
||||
import PageHeader from 'components/layout/PageHeader';
|
||||
import WebsitesTable from 'components/pages/settings/websites/WebsitesTable';
|
||||
import Page from 'components/layout/Page';
|
||||
import useApi from 'hooks/useApi';
|
||||
import useUser from 'hooks/useUser';
|
||||
|
||||
const messages = defineMessages({
|
||||
saved: { id: 'messages.website-saved', defaultMessage: 'Website saved.' },
|
||||
noWebsites: {
|
||||
id: 'messages.no-websites',
|
||||
defaultMessage: "You don't have any websites configured.",
|
||||
},
|
||||
websites: { id: 'label.websites', defaultMessage: 'Websites' },
|
||||
addWebsite: { id: 'label.add-website', defaultMessage: 'Add website' },
|
||||
});
|
||||
|
||||
const { Plus } = Icons;
|
||||
|
||||
export default function WebsitesList() {
|
||||
const [edit, setEdit] = useState(false);
|
||||
const { get, useQuery } = useApi();
|
||||
const { user } = useUser();
|
||||
const { get, useQuery } = useApi();
|
||||
const { data, isLoading, error, refetch } = useQuery(
|
||||
['websites', user?.id],
|
||||
() => get(`/users/${user?.id}/websites`),
|
||||
{ enabled: !!user },
|
||||
);
|
||||
const hasData = data && data.length !== 0;
|
||||
const { toast, showToast } = useToast();
|
||||
|
||||
const columns = [
|
||||
{ name: 'name', label: 'Name', style: { flex: 2 } },
|
||||
{ name: 'domain', label: 'Domain' },
|
||||
{ name: 'action', label: ' ' },
|
||||
];
|
||||
|
||||
const handleAdd = () => {
|
||||
setEdit(true);
|
||||
};
|
||||
const { formatMessage } = useIntl();
|
||||
const hasData = data && data.length !== 0;
|
||||
|
||||
const handleSave = async () => {
|
||||
await refetch();
|
||||
setEdit(false);
|
||||
showToast({ message: 'Website saved.', variant: 'success' });
|
||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setEdit(false);
|
||||
};
|
||||
const handleAdd = () => setEdit(true);
|
||||
|
||||
const handleClose = () => setEdit(false);
|
||||
|
||||
const addButton = (
|
||||
<Button variant="primary" onClick={handleAdd}>
|
||||
<Icon>
|
||||
<Plus />
|
||||
</Icon>
|
||||
<Text>{formatMessage(messages.addWebsite)}</Text>
|
||||
</Button>
|
||||
);
|
||||
|
||||
return (
|
||||
<Page loading={isLoading} error={error}>
|
||||
{toast}
|
||||
<PageHeader title="Websites">
|
||||
<Button variant="primary" onClick={handleAdd}>
|
||||
<Icon>
|
||||
<Plus />
|
||||
</Icon>
|
||||
<Text>Add website</Text>
|
||||
</Button>
|
||||
</PageHeader>
|
||||
|
||||
{hasData && <WebsitesTable columns={columns} rows={data} />}
|
||||
<PageHeader title={formatMessage(messages.websites)}>{addButton}</PageHeader>
|
||||
{hasData && <WebsitesTable data={data} />}
|
||||
{!hasData && (
|
||||
<EmptyPlaceholder message="You don't have any websites configured.">
|
||||
<Button variant="primary" onClick={handleAdd}>
|
||||
<Icon>
|
||||
<Plus />
|
||||
</Icon>
|
||||
<Text>Add website</Text>
|
||||
</Button>
|
||||
<EmptyPlaceholder message={formatMessage(messages.noWebsites)}>
|
||||
{addButton}
|
||||
</EmptyPlaceholder>
|
||||
)}
|
||||
{edit && (
|
||||
<Modal title="Add website" onClose={handleClose}>
|
||||
<Modal title={formatMessage(messages.addWebsite)} onClose={handleClose}>
|
||||
{close => <WebsiteAddForm onSave={handleSave} onClose={close} />}
|
||||
</Modal>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,15 @@ import styles from './WebsitesTable.module.css';
|
|||
|
||||
const { ArrowRight, External } = Icons;
|
||||
|
||||
export default function WebsitesTable({ columns = [], rows = [] }) {
|
||||
const columns = [
|
||||
{ name: 'name', label: 'Name', style: { flex: 2 } },
|
||||
{ name: 'domain', label: 'Domain' },
|
||||
{ name: 'action', label: ' ' },
|
||||
];
|
||||
|
||||
export default function WebsitesTable({ data = [] }) {
|
||||
return (
|
||||
<Table className={styles.table} columns={columns} rows={rows}>
|
||||
<Table className={styles.table} columns={columns} rows={data}>
|
||||
<TableHeader>
|
||||
{(column, index) => {
|
||||
return (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue