mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 09:45:04 +01:00
Merge branch 'dev' into feat/um-76-turn-off-ui
This commit is contained in:
commit
1d808f1b1f
@ -1,6 +1,5 @@
|
||||
import { useState } from 'react';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
import { useRouter } from 'next/router';
|
||||
import Page from 'components/layout/Page';
|
||||
import PageHeader from 'components/layout/PageHeader';
|
||||
import WebsiteList from 'components/pages/WebsiteList';
|
||||
@ -16,10 +15,7 @@ const messages = defineMessages({
|
||||
more: { id: 'label.more', defaultMessage: 'More' },
|
||||
});
|
||||
|
||||
export default function Dashboard() {
|
||||
const router = useRouter();
|
||||
const { id } = router.query;
|
||||
const userId = id?.[0];
|
||||
export default function Dashboard({ userId }) {
|
||||
const dashboard = useDashboard();
|
||||
const { showCharts, limit, editing } = dashboard;
|
||||
const [max, setMax] = useState(limit);
|
||||
|
@ -29,13 +29,15 @@ export default function AccountSettings() {
|
||||
|
||||
const Checkmark = ({ isAdmin }) => (isAdmin ? <Icon icon={<Check />} size="medium" /> : null);
|
||||
|
||||
const DashboardLink = row => (
|
||||
<Link href={`/dashboard/${row.userId}/${row.username}`}>
|
||||
<a>
|
||||
<Icon icon={<LinkIcon />} />
|
||||
</a>
|
||||
</Link>
|
||||
);
|
||||
const DashboardLink = row => {
|
||||
return (
|
||||
<Link href={`/dashboard/${row.accountUuid}/${row.username}`}>
|
||||
<a>
|
||||
<Icon icon={<LinkIcon />} />
|
||||
</a>
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
|
||||
const Buttons = row => (
|
||||
<ButtonLayout align="right">
|
||||
|
@ -21,9 +21,9 @@ export default async (req, res) => {
|
||||
if (req.method === 'POST') {
|
||||
const { username, password, account_uuid } = req.body;
|
||||
|
||||
const accountByUsername = await getAccount({ username });
|
||||
const account = await getAccount({ username });
|
||||
|
||||
if (accountByUsername) {
|
||||
if (account) {
|
||||
return badRequest(res, 'Account already exists');
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ export default async (req, res) => {
|
||||
if (req.method === 'GET') {
|
||||
const { userId } = req.auth;
|
||||
|
||||
const websites = await getUserWebsites(userId);
|
||||
const websites = await getUserWebsites({ userId });
|
||||
const ids = websites.map(({ websiteUuid }) => websiteUuid);
|
||||
const token = createToken({ websites: ids }, secret());
|
||||
const data = await getRealtimeData(ids, subMinutes(new Date(), 30));
|
||||
|
@ -6,15 +6,16 @@ import { uuid } from 'lib/crypto';
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { userId: currentUserId, isAdmin, accountUuid } = req.auth;
|
||||
const { user_id, include_all } = req.query;
|
||||
const { userId: currentUserId, isAdmin } = req.auth;
|
||||
const accountUuid = user_id || req.auth.accountUuid;
|
||||
let account;
|
||||
|
||||
if (accountUuid) {
|
||||
account = await getAccount({ accountUuid: accountUuid });
|
||||
account = await getAccount({ accountUuid });
|
||||
}
|
||||
|
||||
const userId = account ? account.id : +user_id;
|
||||
const userId = account ? account.id : user_id;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
if (userId && userId !== currentUserId && !isAdmin) {
|
||||
@ -24,7 +25,7 @@ export default async (req, res) => {
|
||||
const websites =
|
||||
isAdmin && include_all
|
||||
? await getAllWebsites()
|
||||
: await getUserWebsites(userId || currentUserId);
|
||||
: await getUserWebsites({ userId: account.id });
|
||||
|
||||
return ok(res, websites);
|
||||
}
|
||||
|
@ -2,17 +2,27 @@ import React from 'react';
|
||||
import Layout from 'components/layout/Layout';
|
||||
import Dashboard from 'components/pages/Dashboard';
|
||||
import useRequireLogin from 'hooks/useRequireLogin';
|
||||
import { useRouter } from 'next/router';
|
||||
import useUser from 'hooks/useUser';
|
||||
|
||||
export default function DashboardPage() {
|
||||
const {
|
||||
query: { id },
|
||||
isReady,
|
||||
asPath,
|
||||
} = useRouter();
|
||||
const { loading } = useRequireLogin();
|
||||
const user = useUser();
|
||||
|
||||
if (loading) {
|
||||
if (!user || !isReady || loading) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const userId = id?.[0];
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<Dashboard />
|
||||
<Dashboard key={asPath} userId={user.id || userId} />
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ export async function getAccounts() {
|
||||
isAdmin: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
accountUuid: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getUserWebsites(userId) {
|
||||
export async function getUserWebsites(where) {
|
||||
return prisma.client.website.findMany({
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
where,
|
||||
orderBy: {
|
||||
name: 'asc',
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user