mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-22 09:57:00 +01:00
Merge branch 'dev' of https://github.com/umami-software/umami into dev
This commit is contained in:
commit
260f03cda4
@ -9,38 +9,21 @@ const contentSecurityPolicy = [
|
|||||||
`script-src 'self' 'unsafe-eval' 'unsafe-inline'`,
|
`script-src 'self' 'unsafe-eval' 'unsafe-inline'`,
|
||||||
`style-src 'self' 'unsafe-inline'`,
|
`style-src 'self' 'unsafe-inline'`,
|
||||||
`connect-src 'self' api.umami.is`,
|
`connect-src 'self' api.umami.is`,
|
||||||
`frame-src *`,
|
`frame-ancestors 'self' ${process.env.ALLOWED_FRAME_URLS || ''}`,
|
||||||
];
|
];
|
||||||
|
|
||||||
const cspHeader = (values = []) => ({
|
|
||||||
key: 'Content-Security-Policy',
|
|
||||||
value: values
|
|
||||||
.join(';')
|
|
||||||
.replace(/\s{2,}/g, ' ')
|
|
||||||
.trim(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const headers = [
|
const headers = [
|
||||||
{
|
{
|
||||||
key: 'X-DNS-Prefetch-Control',
|
key: 'X-DNS-Prefetch-Control',
|
||||||
value: 'on',
|
value: 'on',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'X-Frame-Options',
|
key: 'Content-Security-Policy',
|
||||||
value: 'SAMEORIGIN',
|
value: contentSecurityPolicy
|
||||||
|
.join(';')
|
||||||
|
.replace(/\s{2,}/g, ' ')
|
||||||
|
.trim(),
|
||||||
},
|
},
|
||||||
cspHeader(contentSecurityPolicy),
|
|
||||||
];
|
|
||||||
|
|
||||||
const shareHeaders = [
|
|
||||||
{
|
|
||||||
key: 'X-DNS-Prefetch-Control',
|
|
||||||
value: 'on',
|
|
||||||
},
|
|
||||||
cspHeader([
|
|
||||||
...contentSecurityPolicy,
|
|
||||||
`frame-ancestors 'self' ${process.env.ALLOWED_FRAME_URLS || ''}`,
|
|
||||||
]),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if (process.env.FORCE_SSL) {
|
if (process.env.FORCE_SSL) {
|
||||||
@ -142,10 +125,6 @@ const config = {
|
|||||||
source: '/:path*',
|
source: '/:path*',
|
||||||
headers,
|
headers,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
source: '/share/:path*',
|
|
||||||
headers: shareHeaders,
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
async rewrites() {
|
async rewrites() {
|
||||||
|
10
package.json
10
package.json
@ -66,7 +66,7 @@
|
|||||||
"@prisma/client": "5.6.0",
|
"@prisma/client": "5.6.0",
|
||||||
"@prisma/extension-read-replicas": "^0.3.0",
|
"@prisma/extension-read-replicas": "^0.3.0",
|
||||||
"@react-spring/web": "^9.7.3",
|
"@react-spring/web": "^9.7.3",
|
||||||
"@tanstack/react-query": "^4.33.0",
|
"@tanstack/react-query": "^5.12.2",
|
||||||
"@umami/prisma-client": "^0.8.0",
|
"@umami/prisma-client": "^0.8.0",
|
||||||
"@umami/redis-client": "^0.18.0",
|
"@umami/redis-client": "^0.18.0",
|
||||||
"chalk": "^4.1.1",
|
"chalk": "^4.1.1",
|
||||||
@ -94,12 +94,12 @@
|
|||||||
"maxmind": "^4.3.6",
|
"maxmind": "^4.3.6",
|
||||||
"moment-timezone": "^0.5.35",
|
"moment-timezone": "^0.5.35",
|
||||||
"next": "13.5.6",
|
"next": "13.5.6",
|
||||||
"next-basics": "^0.37.0",
|
"next-basics": "^0.39.0",
|
||||||
"node-fetch": "^3.2.8",
|
"node-fetch": "^3.2.8",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"prisma": "5.6.0",
|
"prisma": "5.6.0",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-basics": "^0.109.0",
|
"react-basics": "^0.114.0",
|
||||||
"react-beautiful-dnd": "^13.1.0",
|
"react-beautiful-dnd": "^13.1.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-error-boundary": "^4.0.4",
|
"react-error-boundary": "^4.0.4",
|
||||||
@ -127,8 +127,8 @@
|
|||||||
"@svgr/rollup": "^8.1.0",
|
"@svgr/rollup": "^8.1.0",
|
||||||
"@svgr/webpack": "^8.1.0",
|
"@svgr/webpack": "^8.1.0",
|
||||||
"@types/node": "^20.9.0",
|
"@types/node": "^20.9.0",
|
||||||
"@types/react": "^18.2.37",
|
"@types/react": "^18.2.41",
|
||||||
"@types/react-dom": "^18.2.15",
|
"@types/react-dom": "^18.2.17",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.7.3",
|
"@typescript-eslint/eslint-plugin": "^6.7.3",
|
||||||
"@typescript-eslint/parser": "^6.7.3",
|
"@typescript-eslint/parser": "^6.7.3",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
|
@ -1,30 +1,33 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
import { Button } from 'react-basics';
|
||||||
|
import Head from 'next/head';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import Script from 'next/script';
|
||||||
import WebsiteSelect from 'components/input/WebsiteSelect';
|
import WebsiteSelect from 'components/input/WebsiteSelect';
|
||||||
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 EventsChart from 'components/metrics/EventsChart';
|
import EventsChart from 'components/metrics/EventsChart';
|
||||||
import WebsiteChart from '../../(main)/websites/[id]/WebsiteChart';
|
import WebsiteChart from 'app/(main)/websites/[id]/WebsiteChart';
|
||||||
import useApi from 'components/hooks/useApi';
|
import useApi from 'components/hooks/useApi';
|
||||||
import Head from 'next/head';
|
|
||||||
import Link from 'next/link';
|
|
||||||
import useNavigation from 'components/hooks/useNavigation';
|
import useNavigation from 'components/hooks/useNavigation';
|
||||||
import Script from 'next/script';
|
|
||||||
import { Button } from 'react-basics';
|
|
||||||
import styles from './TestConsole.module.css';
|
import styles from './TestConsole.module.css';
|
||||||
|
|
||||||
export function TestConsole({ websiteId }) {
|
export function TestConsole({ websiteId }: { websiteId: string }) {
|
||||||
const { get, useQuery } = useApi();
|
const { get, useQuery } = useApi();
|
||||||
const { data, isLoading, error } = useQuery(['websites:me'], () => get('/me/websites'));
|
const { data, isLoading, error } = useQuery({
|
||||||
|
queryKey: ['websites:me'],
|
||||||
|
queryFn: () => get('/me/websites'),
|
||||||
|
});
|
||||||
const { router } = useNavigation();
|
const { router } = useNavigation();
|
||||||
|
|
||||||
function handleChange(value) {
|
function handleChange(value: string) {
|
||||||
router.push(`/console/${value}`);
|
router.push(`/console/${value}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleClick() {
|
function handleClick() {
|
||||||
window.umami.track({ url: '/page-view', referrer: 'https://www.google.com' });
|
window['umami'].track({ url: '/page-view', referrer: 'https://www.google.com' });
|
||||||
window.umami.track('track-event-no-data');
|
window['umami'].track('track-event-no-data');
|
||||||
window.umami.track('track-event-with-data', {
|
window['umami'].track('track-event-with-data', {
|
||||||
test: 'test-data',
|
test: 'test-data',
|
||||||
boolean: true,
|
boolean: true,
|
||||||
booleanError: 'true',
|
booleanError: 'true',
|
||||||
@ -44,7 +47,7 @@ export function TestConsole({ websiteId }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleIdentifyClick() {
|
function handleIdentifyClick() {
|
||||||
window.umami.identify({
|
window['umami'].identify({
|
||||||
userId: 123,
|
userId: 123,
|
||||||
name: 'brian',
|
name: 'brian',
|
||||||
number: Math.random() * 100,
|
number: Math.random() * 100,
|
||||||
@ -71,7 +74,7 @@ export function TestConsole({ websiteId }) {
|
|||||||
const website = data?.data.find(({ id }) => websiteId === id);
|
const website = data?.data.find(({ id }) => websiteId === id);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page loading={isLoading} error={error}>
|
<Page isLoading={isLoading} error={error}>
|
||||||
<Head>
|
<Head>
|
||||||
<title>{website ? `${website.name} | Umami Console` : 'Umami Console'}</title>
|
<title>{website ? `${website.name} | Umami Console` : 'Umami Console'}</title>
|
||||||
</Head>
|
</Head>
|
||||||
@ -113,7 +116,7 @@ export function TestConsole({ websiteId }) {
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div className={styles.header}>Click events</div>
|
<div className={styles.header}>Click events</div>
|
||||||
<Button id="send-event-button" data-umami-event="button-click" variant="action">
|
<Button id="send-event-button" data-umami-event="button-click" variant="primary">
|
||||||
Send event
|
Send event
|
||||||
</Button>
|
</Button>
|
||||||
<p />
|
<p />
|
||||||
@ -122,18 +125,18 @@ export function TestConsole({ websiteId }) {
|
|||||||
data-umami-event="button-click"
|
data-umami-event="button-click"
|
||||||
data-umami-event-name="bob"
|
data-umami-event-name="bob"
|
||||||
data-umami-event-id="123"
|
data-umami-event-id="123"
|
||||||
variant="action"
|
variant="primary"
|
||||||
>
|
>
|
||||||
Send event with data
|
Send event with data
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div className={styles.header}>Javascript events</div>
|
<div className={styles.header}>Javascript events</div>
|
||||||
<Button id="manual-button" variant="action" onClick={handleClick}>
|
<Button id="manual-button" variant="primary" onClick={handleClick}>
|
||||||
Run script
|
Run script
|
||||||
</Button>
|
</Button>
|
||||||
<p />
|
<p />
|
||||||
<Button id="manual-button" variant="action" onClick={handleIdentifyClick}>
|
<Button id="manual-button" variant="primary" onClick={handleIdentifyClick}>
|
||||||
Run identify
|
Run identify
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
@ -11,22 +11,31 @@ import useApi from 'components/hooks/useApi';
|
|||||||
import useDashboard from 'store/dashboard';
|
import useDashboard from 'store/dashboard';
|
||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
import useLocale from 'components/hooks/useLocale';
|
import useLocale from 'components/hooks/useLocale';
|
||||||
import useApiFilter from 'components/hooks/useApiFilter';
|
import useFilterQuery from 'components/hooks/useFilterQuery';
|
||||||
|
|
||||||
export function Dashboard() {
|
export function Dashboard() {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { showCharts, editing } = useDashboard();
|
const { showCharts, editing } = useDashboard();
|
||||||
const { dir } = useLocale();
|
const { dir } = useLocale();
|
||||||
const { get, useQuery } = useApi();
|
const { get } = useApi();
|
||||||
const { page, handlePageChange } = useApiFilter();
|
|
||||||
const pageSize = 10;
|
const pageSize = 10;
|
||||||
const { data: result, isLoading } = useQuery(['websites', page, pageSize], () =>
|
|
||||||
get('/websites', { includeTeams: 1, page, pageSize }),
|
|
||||||
);
|
|
||||||
const { data, count } = result || {};
|
|
||||||
const hasData = data && data?.length !== 0;
|
|
||||||
|
|
||||||
if (isLoading) {
|
const { query, params, setParams, result } = useFilterQuery({
|
||||||
|
queryKey: ['dashboard:websites'],
|
||||||
|
queryFn: (params: any) => {
|
||||||
|
return get(`/websites`, { ...params, includeTeams: true, pageSize });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handlePageChange = (page: number) => {
|
||||||
|
setParams({ ...params, page });
|
||||||
|
};
|
||||||
|
|
||||||
|
const { data, count } = result || {};
|
||||||
|
const hasData = !!(data as any)?.length;
|
||||||
|
const { page } = params;
|
||||||
|
|
||||||
|
if (query.isLoading) {
|
||||||
return <Loading size="lg" />;
|
return <Loading size="lg" />;
|
||||||
}
|
}
|
||||||
|
|
@ -17,7 +17,10 @@ export function DashboardEdit() {
|
|||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const [order, setOrder] = useState(websiteOrder || []);
|
const [order, setOrder] = useState(websiteOrder || []);
|
||||||
const { get, useQuery } = useApi();
|
const { get, useQuery } = useApi();
|
||||||
const { data: result } = useQuery(['websites'], () => get('/websites', { includeTeams: 1 }));
|
const { data: result } = useQuery({
|
||||||
|
queryKey: ['websites'],
|
||||||
|
queryFn: () => get('/websites', { includeTeams: 1 }),
|
||||||
|
});
|
||||||
const { data: websites } = result || {};
|
const { data: websites } = result || {};
|
||||||
|
|
||||||
const ordered = useMemo(() => {
|
const ordered = useMemo(() => {
|
||||||
@ -57,13 +60,13 @@ export function DashboardEdit() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={styles.buttons}>
|
<div className={styles.buttons}>
|
||||||
<Button onClick={handleSave} variant="action" size="small">
|
<Button onClick={handleSave} variant="primary" size="sm">
|
||||||
{formatMessage(labels.save)}
|
{formatMessage(labels.save)}
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={handleCancel} size="small">
|
<Button onClick={handleCancel} size="sm">
|
||||||
{formatMessage(labels.cancel)}
|
{formatMessage(labels.cancel)}
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={handleReset} size="small">
|
<Button onClick={handleReset} size="sm">
|
||||||
{formatMessage(labels.reset)}
|
{formatMessage(labels.reset)}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
@ -3,13 +3,21 @@ import ConfirmDeleteForm from 'components/common/ConfirmDeleteForm';
|
|||||||
import { useApi, useMessages } from 'components/hooks';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { setValue } from 'store/cache';
|
import { setValue } from 'store/cache';
|
||||||
|
|
||||||
export function ReportDeleteButton({ reportId, reportName, onDelete }) {
|
export function ReportDeleteButton({
|
||||||
|
reportId,
|
||||||
|
reportName,
|
||||||
|
onDelete,
|
||||||
|
}: {
|
||||||
|
reportId: string;
|
||||||
|
reportName: string;
|
||||||
|
onDelete?: () => void;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { del, useMutation } = useApi();
|
const { del, useMutation } = useApi();
|
||||||
const { mutate } = useMutation(reportId => del(`/reports/${reportId}`));
|
const { mutate } = useMutation(reportId => del(`/reports/${reportId}`));
|
||||||
|
|
||||||
const handleConfirm = close => {
|
const handleConfirm = (close: () => void) => {
|
||||||
mutate(reportId, {
|
mutate(reportId as any, {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
setValue('reports', Date.now());
|
setValue('reports', Date.now());
|
||||||
onDelete?.();
|
onDelete?.();
|
@ -1,16 +1,10 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { useApi } from 'components/hooks';
|
import { useReports } from 'components/hooks';
|
||||||
import ReportsTable from './ReportsTable';
|
import ReportsTable from './ReportsTable';
|
||||||
import useFilterQuery from 'components/hooks/useFilterQuery';
|
|
||||||
import DataTable from 'components/common/DataTable';
|
import DataTable from 'components/common/DataTable';
|
||||||
import useCache from 'store/cache';
|
|
||||||
|
|
||||||
export default function ReportsDataTable({ websiteId }: { websiteId?: string }) {
|
export default function ReportsDataTable({ websiteId }: { websiteId?: string }) {
|
||||||
const { get } = useApi();
|
const queryResult = useReports(websiteId);
|
||||||
const modified = useCache(state => (state as any)?.reports);
|
|
||||||
const queryResult = useFilterQuery(['reports', { websiteId, modified }], params =>
|
|
||||||
get(websiteId ? `/websites/${websiteId}/reports` : `/reports`, params),
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataTable queryResult={queryResult}>
|
<DataTable queryResult={queryResult}>
|
||||||
|
@ -5,7 +5,7 @@ import useUser from 'components/hooks/useUser';
|
|||||||
import { REPORT_TYPES } from 'lib/constants';
|
import { REPORT_TYPES } from 'lib/constants';
|
||||||
import ReportDeleteButton from './ReportDeleteButton';
|
import ReportDeleteButton from './ReportDeleteButton';
|
||||||
|
|
||||||
export function ReportsTable({ data = [], showDomain }) {
|
export function ReportsTable({ data = [], showDomain }: { data: any[]; showDomain?: boolean }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
const breakpoint = useBreakpoint();
|
const breakpoint = useBreakpoint();
|
@ -6,12 +6,19 @@ import WebsiteSelect from 'components/input/WebsiteSelect';
|
|||||||
import { useMessages } from 'components/hooks';
|
import { useMessages } from 'components/hooks';
|
||||||
import { ReportContext } from './Report';
|
import { ReportContext } from './Report';
|
||||||
|
|
||||||
|
export interface BaseParametersProps {
|
||||||
|
showWebsiteSelect?: boolean;
|
||||||
|
allowWebsiteSelect?: boolean;
|
||||||
|
showDateSelect?: boolean;
|
||||||
|
allowDateSelect?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export function BaseParameters({
|
export function BaseParameters({
|
||||||
showWebsiteSelect = true,
|
showWebsiteSelect = true,
|
||||||
allowWebsiteSelect = true,
|
allowWebsiteSelect = true,
|
||||||
showDateSelect = true,
|
showDateSelect = true,
|
||||||
allowDateSelect = true,
|
allowDateSelect = true,
|
||||||
}) {
|
}: BaseParametersProps) {
|
||||||
const { report, updateReport } = useContext(ReportContext);
|
const { report, updateReport } = useContext(ReportContext);
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
||||||
@ -19,11 +26,11 @@ export function BaseParameters({
|
|||||||
const { websiteId, dateRange } = parameters || {};
|
const { websiteId, dateRange } = parameters || {};
|
||||||
const { value, startDate, endDate } = dateRange || {};
|
const { value, startDate, endDate } = dateRange || {};
|
||||||
|
|
||||||
const handleWebsiteSelect = websiteId => {
|
const handleWebsiteSelect = (websiteId: string) => {
|
||||||
updateReport({ websiteId, parameters: { websiteId } });
|
updateReport({ websiteId, parameters: { websiteId } });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDateChange = value => {
|
const handleDateChange = (value: string) => {
|
||||||
updateReport({ parameters: { dateRange: { ...parseDateRange(value) } } });
|
updateReport({ parameters: { dateRange: { ...parseDateRange(value) } } });
|
||||||
};
|
};
|
||||||
|
|
@ -7,10 +7,20 @@ import FieldAggregateForm from './FieldAggregateForm';
|
|||||||
import FieldFilterForm from './FieldFilterForm';
|
import FieldFilterForm from './FieldFilterForm';
|
||||||
import styles from './FieldAddForm.module.css';
|
import styles from './FieldAddForm.module.css';
|
||||||
|
|
||||||
export function FieldAddForm({ fields = [], group, onAdd, onClose }) {
|
export function FieldAddForm({
|
||||||
const [selected, setSelected] = useState();
|
fields = [],
|
||||||
|
group,
|
||||||
|
onAdd,
|
||||||
|
onClose,
|
||||||
|
}: {
|
||||||
|
fields?: any[];
|
||||||
|
group: string;
|
||||||
|
onAdd: (group: string, value: string) => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}) {
|
||||||
|
const [selected, setSelected] = useState<{ name: string; type: string; value: string }>();
|
||||||
|
|
||||||
const handleSelect = value => {
|
const handleSelect = (value: any) => {
|
||||||
const { type } = value;
|
const { type } = value;
|
||||||
|
|
||||||
if (group === REPORT_PARAMETERS.groups || type === 'array' || type === 'boolean') {
|
if (group === REPORT_PARAMETERS.groups || type === 'array' || type === 'boolean') {
|
||||||
@ -22,7 +32,7 @@ export function FieldAddForm({ fields = [], group, onAdd, onClose }) {
|
|||||||
setSelected(value);
|
setSelected(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSave = value => {
|
const handleSave = (value: any) => {
|
||||||
onAdd(group, value);
|
onAdd(group, value);
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
@ -1,7 +1,15 @@
|
|||||||
import { Form, FormRow, Menu, Item } from 'react-basics';
|
import { Form, FormRow, Menu, Item } from 'react-basics';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages } from 'components/hooks';
|
||||||
|
|
||||||
export default function FieldAggregateForm({ name, type, onSelect }) {
|
export default function FieldAggregateForm({
|
||||||
|
name,
|
||||||
|
type,
|
||||||
|
onSelect,
|
||||||
|
}: {
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
onSelect: (key: any) => void;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
@ -27,7 +35,7 @@ export default function FieldAggregateForm({ name, type, onSelect }) {
|
|||||||
|
|
||||||
const items = options[type];
|
const items = options[type];
|
||||||
|
|
||||||
const handleSelect = value => {
|
const handleSelect = (value: any) => {
|
||||||
onSelect({ name, type, value });
|
onSelect({ name, type, value });
|
||||||
};
|
};
|
||||||
|
|
@ -3,6 +3,15 @@ import { Form, FormRow, Item, Flexbox, Dropdown, Button } from 'react-basics';
|
|||||||
import { useMessages, useFilters, useFormat, useLocale } from 'components/hooks';
|
import { useMessages, useFilters, useFormat, useLocale } from 'components/hooks';
|
||||||
import styles from './FieldFilterForm.module.css';
|
import styles from './FieldFilterForm.module.css';
|
||||||
|
|
||||||
|
export interface FieldFilterFormProps {
|
||||||
|
name: string;
|
||||||
|
label?: string;
|
||||||
|
type: string;
|
||||||
|
values?: any[];
|
||||||
|
onSelect?: (key: any) => void;
|
||||||
|
allowFilterSelect?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export default function FieldFilterForm({
|
export default function FieldFilterForm({
|
||||||
name,
|
name,
|
||||||
label,
|
label,
|
||||||
@ -10,7 +19,7 @@ export default function FieldFilterForm({
|
|||||||
values,
|
values,
|
||||||
onSelect,
|
onSelect,
|
||||||
allowFilterSelect = true,
|
allowFilterSelect = true,
|
||||||
}) {
|
}: FieldFilterFormProps) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const [filter, setFilter] = useState('eq');
|
const [filter, setFilter] = useState('eq');
|
||||||
const [value, setValue] = useState();
|
const [value, setValue] = useState();
|
||||||
@ -21,7 +30,7 @@ export default function FieldFilterForm({
|
|||||||
|
|
||||||
const formattedValues = useMemo(() => {
|
const formattedValues = useMemo(() => {
|
||||||
const formatted = {};
|
const formatted = {};
|
||||||
const format = val => {
|
const format = (val: string) => {
|
||||||
formatted[val] = formatValue(val, name);
|
formatted[val] = formatValue(val, name);
|
||||||
return formatted[val];
|
return formatted[val];
|
||||||
};
|
};
|
||||||
@ -56,7 +65,7 @@ export default function FieldFilterForm({
|
|||||||
items={filters}
|
items={filters}
|
||||||
value={filter}
|
value={filter}
|
||||||
renderValue={renderFilterValue}
|
renderValue={renderFilterValue}
|
||||||
onChange={setFilter}
|
onChange={(key: any) => setFilter(key)}
|
||||||
>
|
>
|
||||||
{({ value, label }) => {
|
{({ value, label }) => {
|
||||||
return <Item key={value}>{label}</Item>;
|
return <Item key={value}>{label}</Item>;
|
||||||
@ -69,12 +78,12 @@ export default function FieldFilterForm({
|
|||||||
items={values}
|
items={values}
|
||||||
value={value}
|
value={value}
|
||||||
renderValue={renderValue}
|
renderValue={renderValue}
|
||||||
onChange={setValue}
|
onChange={(key: any) => setValue(key)}
|
||||||
style={{
|
style={{
|
||||||
minWidth: '250px',
|
minWidth: '250px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{value => {
|
{(value: string) => {
|
||||||
return <Item key={value}>{formattedValues[value]}</Item>;
|
return <Item key={value}>{formattedValues[value]}</Item>;
|
||||||
}}
|
}}
|
||||||
</Dropdown>
|
</Dropdown>
|
@ -1,15 +1,26 @@
|
|||||||
import { Menu, Item, Form, FormRow } from 'react-basics';
|
import { Menu, Item, Form, FormRow } from 'react-basics';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages } from 'components/hooks';
|
||||||
import styles from './FieldSelectForm.module.css';
|
import styles from './FieldSelectForm.module.css';
|
||||||
|
import { Key } from 'react';
|
||||||
|
|
||||||
export default function FieldSelectForm({ items, onSelect, showType = true }) {
|
export interface FieldSelectFormProps {
|
||||||
|
fields?: any[];
|
||||||
|
onSelect?: (key: any) => void;
|
||||||
|
showType?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function FieldSelectForm({
|
||||||
|
fields = [],
|
||||||
|
onSelect,
|
||||||
|
showType = true,
|
||||||
|
}: FieldSelectFormProps) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
<FormRow label={formatMessage(labels.fields)}>
|
<FormRow label={formatMessage(labels.fields)}>
|
||||||
<Menu className={styles.menu} onSelect={key => onSelect(items[key])}>
|
<Menu className={styles.menu} onSelect={key => onSelect(fields[key as any])}>
|
||||||
{items.map(({ name, label, type }, index) => {
|
{fields.map(({ name, label, type }: any, index: Key) => {
|
||||||
return (
|
return (
|
||||||
<Item key={index} className={styles.item}>
|
<Item key={index} className={styles.item}>
|
||||||
<div>{label || name}</div>
|
<div>{label || name}</div>
|
@ -5,29 +5,41 @@ import FieldSelectForm from './FieldSelectForm';
|
|||||||
import FieldFilterForm from './FieldFilterForm';
|
import FieldFilterForm from './FieldFilterForm';
|
||||||
import { useApi } from 'components/hooks';
|
import { useApi } from 'components/hooks';
|
||||||
|
|
||||||
function useValues(websiteId, type) {
|
function useValues(websiteId: string, type: string) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const { get, useQuery } = useApi();
|
const { get, useQuery } = useApi();
|
||||||
const { data, error, isLoading } = useQuery(
|
const { data, error, isLoading } = useQuery({
|
||||||
['websites:values', websiteId, type],
|
queryKey: ['websites:values', websiteId, type],
|
||||||
() =>
|
queryFn: () =>
|
||||||
get(`/websites/${websiteId}/values`, {
|
get(`/websites/${websiteId}/values`, {
|
||||||
type,
|
type,
|
||||||
startAt: +subDays(now, 90),
|
startAt: +subDays(now, 90),
|
||||||
endAt: now,
|
endAt: now,
|
||||||
}),
|
}),
|
||||||
{ enabled: !!(websiteId && type) },
|
enabled: !!(websiteId && type),
|
||||||
);
|
});
|
||||||
|
|
||||||
return { data, error, isLoading };
|
return { data, error, isLoading };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function FilterSelectForm({ websiteId, items, onSelect, allowFilterSelect }) {
|
export interface FilterSelectFormProps {
|
||||||
const [field, setField] = useState();
|
websiteId: string;
|
||||||
|
items: any[];
|
||||||
|
onSelect?: (key: any) => void;
|
||||||
|
allowFilterSelect?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function FilterSelectForm({
|
||||||
|
websiteId,
|
||||||
|
items,
|
||||||
|
onSelect,
|
||||||
|
allowFilterSelect,
|
||||||
|
}: FilterSelectFormProps) {
|
||||||
|
const [field, setField] = useState<{ name: string; label: string; type: string }>();
|
||||||
const { data, isLoading } = useValues(websiteId, field?.name);
|
const { data, isLoading } = useValues(websiteId, field?.name);
|
||||||
|
|
||||||
if (!field) {
|
if (!field) {
|
||||||
return <FieldSelectForm items={items} onSelect={setField} showType={false} />;
|
return <FieldSelectForm fields={items} onSelect={setField} showType={false} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
@ -1,10 +1,17 @@
|
|||||||
|
import { ReactNode } from 'react';
|
||||||
import { Icon, TooltipPopup } from 'react-basics';
|
import { Icon, TooltipPopup } from 'react-basics';
|
||||||
import Icons from 'components/icons';
|
import Icons from 'components/icons';
|
||||||
import Empty from 'components/common/Empty';
|
import Empty from 'components/common/Empty';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages } from 'components/hooks';
|
||||||
import styles from './ParameterList.module.css';
|
import styles from './ParameterList.module.css';
|
||||||
|
|
||||||
export function ParameterList({ items = [], children, onRemove }) {
|
export interface ParameterListProps {
|
||||||
|
items: any[];
|
||||||
|
children?: ReactNode | ((item: any) => ReactNode);
|
||||||
|
onRemove: (index: number, e: any) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ParameterList({ items = [], children, onRemove }: ParameterListProps) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
||||||
return (
|
return (
|
@ -1,7 +1,16 @@
|
|||||||
|
import { CSSProperties, ReactNode } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import styles from './PopupForm.module.css';
|
import styles from './PopupForm.module.css';
|
||||||
|
|
||||||
export function PopupForm({ className, style, children }) {
|
export function PopupForm({
|
||||||
|
className,
|
||||||
|
style,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
className?: string;
|
||||||
|
style?: CSSProperties;
|
||||||
|
children: ReactNode;
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classNames(styles.form, className)}
|
className={classNames(styles.form, className)}
|
@ -1,11 +1,19 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { createContext } from 'react';
|
import { createContext, ReactNode } from 'react';
|
||||||
import { useReport } from 'components/hooks';
|
import { useReport } from 'components/hooks';
|
||||||
import styles from './Report.module.css';
|
import styles from './Report.module.css';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
export const ReportContext = createContext(null);
|
export const ReportContext = createContext(null);
|
||||||
|
|
||||||
export function Report({ reportId, defaultParameters, children, ...props }) {
|
export interface ReportProps {
|
||||||
|
reportId: string;
|
||||||
|
defaultParameters: { [key: string]: any };
|
||||||
|
children: ReactNode;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Report({ reportId, defaultParameters, children, className }: ReportProps) {
|
||||||
const report = useReport(reportId, defaultParameters);
|
const report = useReport(reportId, defaultParameters);
|
||||||
|
|
||||||
if (!report) {
|
if (!report) {
|
||||||
@ -14,9 +22,7 @@ export function Report({ reportId, defaultParameters, children, ...props }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ReportContext.Provider value={{ ...report }}>
|
<ReportContext.Provider value={{ ...report }}>
|
||||||
<div {...props} className={styles.container}>
|
<div className={classNames(styles.container, className)}>{children}</div>
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
</ReportContext.Provider>
|
</ReportContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -12,9 +12,12 @@ const reports = {
|
|||||||
retention: RetentionReport,
|
retention: RetentionReport,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ReportDetails({ reportId }) {
|
export default function ReportDetails({ reportId }: { reportId: string }) {
|
||||||
const { get, useQuery } = useApi();
|
const { get, useQuery } = useApi();
|
||||||
const { data: report } = useQuery(['reports', reportId], () => get(`/reports/${reportId}`));
|
const { data: report } = useQuery({
|
||||||
|
queryKey: ['reports', reportId],
|
||||||
|
queryFn: () => get(`/reports/${reportId}`),
|
||||||
|
});
|
||||||
|
|
||||||
if (!report) {
|
if (!report) {
|
||||||
return null;
|
return null;
|
@ -12,8 +12,10 @@ export function ReportHeader({ icon }) {
|
|||||||
const { showToast } = useToasts();
|
const { showToast } = useToasts();
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { mutate: create, isLoading: isCreating } = useMutation(data => post(`/reports`, data));
|
const { mutate: create, isLoading: isCreating } = useMutation((data: any) =>
|
||||||
const { mutate: update, isLoading: isUpdating } = useMutation(data =>
|
post(`/reports`, data),
|
||||||
|
);
|
||||||
|
const { mutate: update, isLoading: isUpdating } = useMutation((data: any) =>
|
||||||
post(`/reports/${data.id}`, data),
|
post(`/reports/${data.id}`, data),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -26,7 +28,7 @@ export function ReportHeader({ icon }) {
|
|||||||
create(report, {
|
create(report, {
|
||||||
onSuccess: async ({ id }) => {
|
onSuccess: async ({ id }) => {
|
||||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||||
router.push(`/reports/${id}`, null, { shallow: true });
|
router.push(`/reports/${id}`);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -38,11 +40,11 @@ export function ReportHeader({ icon }) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleNameChange = name => {
|
const handleNameChange = (name: string) => {
|
||||||
updateReport({ name: name || defaultName });
|
updateReport({ name: name || defaultName });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDescriptionChange = description => {
|
const handleDescriptionChange = (description: string) => {
|
||||||
updateReport({ description });
|
updateReport({ description });
|
||||||
};
|
};
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
import { useContext, useRef } from 'react';
|
import { useContext } from 'react';
|
||||||
import { Form, FormRow, FormButtons, SubmitButton, PopupTrigger, Icon, Popup } from 'react-basics';
|
import { Form, FormRow, FormButtons, SubmitButton, PopupTrigger, Icon, Popup } from 'react-basics';
|
||||||
import Empty from 'components/common/Empty';
|
import Empty from 'components/common/Empty';
|
||||||
import Icons from 'components/icons';
|
import Icons from 'components/icons';
|
||||||
@ -12,16 +12,16 @@ import styles from './EventDataParameters.module.css';
|
|||||||
|
|
||||||
function useFields(websiteId, startDate, endDate) {
|
function useFields(websiteId, startDate, endDate) {
|
||||||
const { get, useQuery } = useApi();
|
const { get, useQuery } = useApi();
|
||||||
const { data, error, isLoading } = useQuery(
|
const { data, error, isLoading } = useQuery({
|
||||||
['fields', websiteId, startDate, endDate],
|
queryKey: ['fields', websiteId, startDate, endDate],
|
||||||
() =>
|
queryFn: () =>
|
||||||
get('/reports/event-data', {
|
get('/reports/event-data', {
|
||||||
websiteId,
|
websiteId,
|
||||||
startAt: +startDate,
|
startAt: +startDate,
|
||||||
endAt: +endDate,
|
endAt: +endDate,
|
||||||
}),
|
}),
|
||||||
{ enabled: !!(websiteId && startDate && endDate) },
|
enabled: !!(websiteId && startDate && endDate),
|
||||||
);
|
});
|
||||||
|
|
||||||
return { data, error, isLoading };
|
return { data, error, isLoading };
|
||||||
}
|
}
|
||||||
@ -29,7 +29,6 @@ function useFields(websiteId, startDate, endDate) {
|
|||||||
export function EventDataParameters() {
|
export function EventDataParameters() {
|
||||||
const { report, runReport, updateReport, isRunning } = useContext(ReportContext);
|
const { report, runReport, updateReport, isRunning } = useContext(ReportContext);
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const ref = useRef(null);
|
|
||||||
const { parameters } = report || {};
|
const { parameters } = report || {};
|
||||||
const { websiteId, dateRange, fields, filters, groups } = parameters || {};
|
const { websiteId, dateRange, fields, filters, groups } = parameters || {};
|
||||||
const { startDate, endDate } = dateRange || {};
|
const { startDate, endDate } = dateRange || {};
|
||||||
@ -53,28 +52,28 @@ export function EventDataParameters() {
|
|||||||
runReport(values);
|
runReport(values);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAdd = (group, value) => {
|
const handleAdd = (group: string, value: any) => {
|
||||||
const data = parameterData[group];
|
const data = parameterData[group];
|
||||||
|
|
||||||
if (!data.find(({ name }) => name === value.name)) {
|
if (!data.find(({ name }) => name === value?.name)) {
|
||||||
updateReport({ parameters: { [group]: data.concat(value) } });
|
updateReport({ parameters: { [group]: data.concat(value) } });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRemove = (group, index) => {
|
const handleRemove = (group: string, index: number) => {
|
||||||
const data = [...parameterData[group]];
|
const data = [...parameterData[group]];
|
||||||
data.splice(index, 1);
|
data.splice(index, 1);
|
||||||
updateReport({ parameters: { [group]: data } });
|
updateReport({ parameters: { [group]: data } });
|
||||||
};
|
};
|
||||||
|
|
||||||
const AddButton = ({ group }) => {
|
const AddButton = ({ group, onAdd }) => {
|
||||||
return (
|
return (
|
||||||
<PopupTrigger>
|
<PopupTrigger>
|
||||||
<Icon>
|
<Icon>
|
||||||
<Icons.Plus />
|
<Icons.Plus />
|
||||||
</Icon>
|
</Icon>
|
||||||
<Popup position="bottom" alignment="start">
|
<Popup position="bottom" alignment="start">
|
||||||
{close => {
|
{(close: () => void) => {
|
||||||
return (
|
return (
|
||||||
<FieldAddForm
|
<FieldAddForm
|
||||||
fields={data.map(({ eventKey, eventDataType }) => ({
|
fields={data.map(({ eventKey, eventDataType }) => ({
|
||||||
@ -82,7 +81,7 @@ export function EventDataParameters() {
|
|||||||
type: DATA_TYPES[eventDataType],
|
type: DATA_TYPES[eventDataType],
|
||||||
}))}
|
}))}
|
||||||
group={group}
|
group={group}
|
||||||
onAdd={handleAdd}
|
onAdd={onAdd}
|
||||||
onClose={close}
|
onClose={close}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@ -93,7 +92,7 @@ export function EventDataParameters() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form ref={ref} values={parameters} error={error} onSubmit={handleSubmit}>
|
<Form values={parameters} error={error} onSubmit={handleSubmit}>
|
||||||
<BaseParameters />
|
<BaseParameters />
|
||||||
{!hasData && <Empty message={formatMessage(messages.noEventData)} />}
|
{!hasData && <Empty message={formatMessage(messages.noEventData)} />}
|
||||||
{parametersSelected &&
|
{parametersSelected &&
|
@ -11,7 +11,7 @@ const defaultParameters = {
|
|||||||
parameters: { fields: [], filters: [] },
|
parameters: { fields: [], filters: [] },
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function EventDataReport({ reportId }) {
|
export default function EventDataReport({ reportId }: { reportId: string }) {
|
||||||
return (
|
return (
|
||||||
<Report reportId={reportId} defaultParameters={defaultParameters}>
|
<Report reportId={reportId} defaultParameters={defaultParameters}>
|
||||||
<ReportHeader icon={<Nodes />} />
|
<ReportHeader icon={<Nodes />} />
|
@ -1,13 +1,18 @@
|
|||||||
import { useCallback, useContext, useMemo } from 'react';
|
import { JSX, useCallback, useContext, useMemo } from 'react';
|
||||||
import { Loading, StatusLight } from 'react-basics';
|
import { Loading, StatusLight } from 'react-basics';
|
||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
import useTheme from 'components/hooks/useTheme';
|
import useTheme from 'components/hooks/useTheme';
|
||||||
import BarChart from 'components/metrics/BarChart';
|
import BarChart from 'components/metrics/BarChart';
|
||||||
import { formatLongNumber } from 'lib/format';
|
import { formatLongNumber } from 'lib/format';
|
||||||
import styles from './FunnelChart.module.css';
|
|
||||||
import { ReportContext } from '../[id]/Report';
|
import { ReportContext } from '../[id]/Report';
|
||||||
|
import styles from './FunnelChart.module.css';
|
||||||
|
|
||||||
export function FunnelChart({ className, loading }) {
|
export interface FunnelChartProps {
|
||||||
|
className?: string;
|
||||||
|
isLoading?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FunnelChart({ className, isLoading }: FunnelChartProps) {
|
||||||
const { report } = useContext(ReportContext);
|
const { report } = useContext(ReportContext);
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { colors } = useTheme();
|
const { colors } = useTheme();
|
||||||
@ -15,33 +20,39 @@ export function FunnelChart({ className, loading }) {
|
|||||||
const { parameters, data } = report || {};
|
const { parameters, data } = report || {};
|
||||||
|
|
||||||
const renderXLabel = useCallback(
|
const renderXLabel = useCallback(
|
||||||
(label, index) => {
|
(label: string, index: number) => {
|
||||||
return parameters.urls[index];
|
return parameters.urls[index];
|
||||||
},
|
},
|
||||||
[parameters],
|
[parameters],
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderTooltipPopup = useCallback((setTooltipPopup, model) => {
|
const renderTooltipPopup = useCallback(
|
||||||
const { opacity, labelColors, dataPoints } = model.tooltip;
|
(
|
||||||
|
setTooltipPopup: (arg0: JSX.Element) => void,
|
||||||
|
model: { tooltip: { opacity: any; labelColors: any; dataPoints: any } },
|
||||||
|
) => {
|
||||||
|
const { opacity, labelColors, dataPoints } = model.tooltip;
|
||||||
|
|
||||||
if (!dataPoints?.length || !opacity) {
|
if (!dataPoints?.length || !opacity) {
|
||||||
setTooltipPopup(null);
|
setTooltipPopup(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setTooltipPopup(
|
setTooltipPopup(
|
||||||
<>
|
<>
|
||||||
<div>
|
<div>
|
||||||
{formatLongNumber(dataPoints[0].raw.y)} {formatMessage(labels.visitors)}
|
{formatLongNumber(dataPoints[0].raw.y)} {formatMessage(labels.visitors)}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<StatusLight color={labelColors?.[0]?.backgroundColor}>
|
<StatusLight color={labelColors?.[0]?.backgroundColor}>
|
||||||
{formatLongNumber(dataPoints[0].raw.z)}% {formatMessage(labels.dropoff)}
|
{formatLongNumber(dataPoints[0].raw.z)}% {formatMessage(labels.dropoff)}
|
||||||
</StatusLight>
|
</StatusLight>
|
||||||
</div>
|
</div>
|
||||||
</>,
|
</>,
|
||||||
);
|
);
|
||||||
}, []);
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
const datasets = useMemo(() => {
|
const datasets = useMemo(() => {
|
||||||
return [
|
return [
|
||||||
@ -54,7 +65,7 @@ export function FunnelChart({ className, loading }) {
|
|||||||
];
|
];
|
||||||
}, [data, colors, formatMessage, labels]);
|
}, [data, colors, formatMessage, labels]);
|
||||||
|
|
||||||
if (loading) {
|
if (isLoading) {
|
||||||
return <Loading icon="dots" className={styles.loading} />;
|
return <Loading icon="dots" className={styles.loading} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +74,7 @@ export function FunnelChart({ className, loading }) {
|
|||||||
className={className}
|
className={className}
|
||||||
datasets={datasets}
|
datasets={datasets}
|
||||||
unit="day"
|
unit="day"
|
||||||
loading={loading}
|
isLoading={isLoading}
|
||||||
renderXLabel={renderXLabel}
|
renderXLabel={renderXLabel}
|
||||||
renderTooltipPopup={renderTooltipPopup}
|
renderTooltipPopup={renderTooltipPopup}
|
||||||
XAxisType="category"
|
XAxisType="category"
|
@ -1,4 +1,4 @@
|
|||||||
import { useContext, useRef } from 'react';
|
import { useContext } from 'react';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages } from 'components/hooks';
|
||||||
import {
|
import {
|
||||||
Icon,
|
Icon,
|
||||||
@ -21,13 +21,12 @@ import PopupForm from '../[id]/PopupForm';
|
|||||||
export function FunnelParameters() {
|
export function FunnelParameters() {
|
||||||
const { report, runReport, updateReport, isRunning } = useContext(ReportContext);
|
const { report, runReport, updateReport, isRunning } = useContext(ReportContext);
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const ref = useRef(null);
|
|
||||||
|
|
||||||
const { parameters } = report || {};
|
const { parameters } = report || {};
|
||||||
const { websiteId, dateRange, urls } = parameters || {};
|
const { websiteId, dateRange, urls } = parameters || {};
|
||||||
const queryDisabled = !websiteId || !dateRange || urls?.length < 2;
|
const queryDisabled = !websiteId || !dateRange || urls?.length < 2;
|
||||||
|
|
||||||
const handleSubmit = (data, e) => {
|
const handleSubmit = (data: any, e: any) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!queryDisabled) {
|
if (!queryDisabled) {
|
||||||
@ -35,11 +34,11 @@ export function FunnelParameters() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddUrl = url => {
|
const handleAddUrl = (url: string) => {
|
||||||
updateReport({ parameters: { urls: parameters.urls.concat(url) } });
|
updateReport({ parameters: { urls: parameters.urls.concat(url) } });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRemoveUrl = (index, e) => {
|
const handleRemoveUrl = (index: number, e: any) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const urls = [...parameters.urls];
|
const urls = [...parameters.urls];
|
||||||
urls.splice(index, 1);
|
urls.splice(index, 1);
|
||||||
@ -62,7 +61,7 @@ export function FunnelParameters() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form ref={ref} values={parameters} onSubmit={handleSubmit} preventSubmit={true}>
|
<Form values={parameters} onSubmit={handleSubmit} preventSubmit={true}>
|
||||||
<BaseParameters />
|
<BaseParameters />
|
||||||
<FormRow label={formatMessage(labels.window)}>
|
<FormRow label={formatMessage(labels.window)}>
|
||||||
<FormInput
|
<FormInput
|
||||||
@ -73,7 +72,10 @@ export function FunnelParameters() {
|
|||||||
</FormInput>
|
</FormInput>
|
||||||
</FormRow>
|
</FormRow>
|
||||||
<FormRow label={formatMessage(labels.urls)} action={<AddUrlButton />}>
|
<FormRow label={formatMessage(labels.urls)} action={<AddUrlButton />}>
|
||||||
<ParameterList items={urls} onRemove={handleRemoveUrl} />
|
<ParameterList
|
||||||
|
items={urls}
|
||||||
|
onRemove={(index: number, e: any) => handleRemoveUrl(index, e)}
|
||||||
|
/>
|
||||||
</FormRow>
|
</FormRow>
|
||||||
<FormButtons>
|
<FormButtons>
|
||||||
<SubmitButton variant="primary" disabled={queryDisabled} isLoading={isRunning}>
|
<SubmitButton variant="primary" disabled={queryDisabled} isLoading={isRunning}>
|
@ -3,7 +3,12 @@ import { useMessages } from 'components/hooks';
|
|||||||
import { Button, Form, FormRow, TextField, Flexbox } from 'react-basics';
|
import { Button, Form, FormRow, TextField, Flexbox } from 'react-basics';
|
||||||
import styles from './UrlAddForm.module.css';
|
import styles from './UrlAddForm.module.css';
|
||||||
|
|
||||||
export function UrlAddForm({ defaultValue = '', onAdd }) {
|
export interface UrlAddFormProps {
|
||||||
|
defaultValue?: string;
|
||||||
|
onAdd?: (url: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function UrlAddForm({ defaultValue = '', onAdd }: UrlAddFormProps) {
|
||||||
const [url, setUrl] = useState(defaultValue);
|
const [url, setUrl] = useState(defaultValue);
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
import { useContext, useRef } from 'react';
|
import { useContext } from 'react';
|
||||||
import { useFormat, useMessages, useFilters } from 'components/hooks';
|
import { useFormat, useMessages, useFilters } from 'components/hooks';
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
@ -24,7 +24,6 @@ export function InsightsParameters() {
|
|||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { formatValue } = useFormat();
|
const { formatValue } = useFormat();
|
||||||
const { filterLabels } = useFilters();
|
const { filterLabels } = useFilters();
|
||||||
const ref = useRef(null);
|
|
||||||
const { parameters } = report || {};
|
const { parameters } = report || {};
|
||||||
const { websiteId, dateRange, fields, filters } = parameters || {};
|
const { websiteId, dateRange, fields, filters } = parameters || {};
|
||||||
const { startDate, endDate } = dateRange || {};
|
const { startDate, endDate } = dateRange || {};
|
||||||
@ -72,7 +71,7 @@ export function InsightsParameters() {
|
|||||||
updateReport({ parameters: { [id]: data } });
|
updateReport({ parameters: { [id]: data } });
|
||||||
};
|
};
|
||||||
|
|
||||||
const AddButton = ({ id }) => {
|
const AddButton = ({ id, onAdd }) => {
|
||||||
return (
|
return (
|
||||||
<PopupTrigger>
|
<PopupTrigger>
|
||||||
<TooltipPopup label={formatMessage(labels.add)} position="top">
|
<TooltipPopup label={formatMessage(labels.add)} position="top">
|
||||||
@ -84,8 +83,8 @@ export function InsightsParameters() {
|
|||||||
<PopupForm>
|
<PopupForm>
|
||||||
{id === 'fields' && (
|
{id === 'fields' && (
|
||||||
<FieldSelectForm
|
<FieldSelectForm
|
||||||
items={fieldOptions}
|
fields={fieldOptions}
|
||||||
onSelect={handleAdd.bind(null, id)}
|
onSelect={onAdd.bind(null, id)}
|
||||||
showType={false}
|
showType={false}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@ -93,7 +92,7 @@ export function InsightsParameters() {
|
|||||||
<FilterSelectForm
|
<FilterSelectForm
|
||||||
websiteId={websiteId}
|
websiteId={websiteId}
|
||||||
items={fieldOptions}
|
items={fieldOptions}
|
||||||
onSelect={handleAdd.bind(null, id)}
|
onSelect={onAdd.bind(null, id)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</PopupForm>
|
</PopupForm>
|
||||||
@ -103,7 +102,7 @@ export function InsightsParameters() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form ref={ref} values={parameters} onSubmit={handleSubmit}>
|
<Form values={parameters} onSubmit={handleSubmit}>
|
||||||
<BaseParameters />
|
<BaseParameters />
|
||||||
{parametersSelected &&
|
{parametersSelected &&
|
||||||
parameterGroups.map(({ id, label }) => {
|
parameterGroups.map(({ id, label }) => {
|
@ -13,7 +13,7 @@ const defaultParameters = {
|
|||||||
parameters: { fields: [], filters: [] },
|
parameters: { fields: [], filters: [] },
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function InsightsReport({ reportId }) {
|
export default function InsightsReport({ reportId }: { reportId: string }) {
|
||||||
return (
|
return (
|
||||||
<Report reportId={reportId} defaultParameters={defaultParameters}>
|
<Report reportId={reportId} defaultParameters={defaultParameters}>
|
||||||
<ReportHeader icon={<Lightbulb />} />
|
<ReportHeader icon={<Lightbulb />} />
|
@ -5,7 +5,7 @@ import { ReportContext } from '../[id]/Report';
|
|||||||
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
||||||
|
|
||||||
export function InsightsTable() {
|
export function InsightsTable() {
|
||||||
const [fields, setFields] = useState();
|
const [fields, setFields] = useState([]);
|
||||||
const { report } = useContext(ReportContext);
|
const { report } = useContext(ReportContext);
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { formatValue } = useFormat();
|
const { formatValue } = useFormat();
|
||||||
@ -37,10 +37,10 @@ export function InsightsTable() {
|
|||||||
width="100px"
|
width="100px"
|
||||||
alignment="end"
|
alignment="end"
|
||||||
>
|
>
|
||||||
{row => row.visitors.toLocaleString()}
|
{row => row?.visitors?.toLocaleString()}
|
||||||
</GridColumn>
|
</GridColumn>
|
||||||
<GridColumn name="views" label={formatMessage(labels.views)} width="100px" alignment="end">
|
<GridColumn name="views" label={formatMessage(labels.views)} width="100px" alignment="end">
|
||||||
{row => row.views.toLocaleString()}
|
{row => row?.views?.toLocaleString()}
|
||||||
</GridColumn>
|
</GridColumn>
|
||||||
</GridTable>
|
</GridTable>
|
||||||
);
|
);
|
@ -1,4 +1,4 @@
|
|||||||
import { useContext, useRef } from 'react';
|
import { useContext } from 'react';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages } from 'components/hooks';
|
||||||
import { Form, FormButtons, FormRow, SubmitButton } from 'react-basics';
|
import { Form, FormButtons, FormRow, SubmitButton } from 'react-basics';
|
||||||
import { ReportContext } from '../[id]/Report';
|
import { ReportContext } from '../[id]/Report';
|
||||||
@ -9,14 +9,13 @@ import { parseDateRange } from 'lib/date';
|
|||||||
export function RetentionParameters() {
|
export function RetentionParameters() {
|
||||||
const { report, runReport, isRunning, updateReport } = useContext(ReportContext);
|
const { report, runReport, isRunning, updateReport } = useContext(ReportContext);
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const ref = useRef(null);
|
|
||||||
|
|
||||||
const { parameters } = report || {};
|
const { parameters } = report || {};
|
||||||
const { websiteId, dateRange } = parameters || {};
|
const { websiteId, dateRange } = parameters || {};
|
||||||
const { startDate } = dateRange || {};
|
const { startDate } = dateRange || {};
|
||||||
const queryDisabled = !websiteId || !dateRange;
|
const queryDisabled = !websiteId || !dateRange;
|
||||||
|
|
||||||
const handleSubmit = (data, e) => {
|
const handleSubmit = (data: any, e: any) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@ -30,7 +29,7 @@ export function RetentionParameters() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form ref={ref} values={parameters} onSubmit={handleSubmit} preventSubmit={true}>
|
<Form values={parameters} onSubmit={handleSubmit} preventSubmit={true}>
|
||||||
<BaseParameters showDateSelect={false} />
|
<BaseParameters showDateSelect={false} />
|
||||||
<FormRow label={formatMessage(labels.date)}>
|
<FormRow label={formatMessage(labels.date)}>
|
||||||
<MonthSelect date={startDate} onChange={handleDateChange} />
|
<MonthSelect date={startDate} onChange={handleDateChange} />
|
@ -19,7 +19,7 @@ const defaultParameters = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function RetentionReport({ reportId }) {
|
export default function RetentionReport({ reportId }: { reportId: string }) {
|
||||||
return (
|
return (
|
||||||
<Report reportId={reportId} defaultParameters={defaultParameters}>
|
<Report reportId={reportId} defaultParameters={defaultParameters}>
|
||||||
<ReportHeader icon={<Magnet />} />
|
<ReportHeader icon={<Magnet />} />
|
@ -18,7 +18,7 @@ export function RetentionTable({ days = DAYS }) {
|
|||||||
return <EmptyPlaceholder />;
|
return <EmptyPlaceholder />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rows = data.reduce((arr, row) => {
|
const rows = data.reduce((arr: any[], row: { date: any; visitors: any; day: any }) => {
|
||||||
const { date, visitors, day } = row;
|
const { date, visitors, day } = row;
|
||||||
if (day === 0) {
|
if (day === 0) {
|
||||||
return arr.concat({
|
return arr.concat({
|
@ -6,10 +6,10 @@ import useMessages from 'components/hooks/useMessages';
|
|||||||
export function PasswordEditForm({ onSave, onClose }) {
|
export function PasswordEditForm({ onSave, onClose }) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error, isLoading } = useMutation(data => post('/me/password', data));
|
const { mutate, error, isLoading } = useMutation((data: any) => post('/me/password', data));
|
||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
|
|
||||||
const handleSubmit = async data => {
|
const handleSubmit = async (data: any) => {
|
||||||
mutate(data, {
|
mutate(data, {
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
onSave();
|
onSave();
|
||||||
@ -18,7 +18,7 @@ export function PasswordEditForm({ onSave, onClose }) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const samePassword = value => {
|
const samePassword = (value: string) => {
|
||||||
if (value !== ref?.current?.getValues('newPassword')) {
|
if (value !== ref?.current?.getValues('newPassword')) {
|
||||||
return formatMessage(messages.noMatchPassword);
|
return formatMessage(messages.noMatchPassword);
|
||||||
}
|
}
|
@ -1,4 +1,3 @@
|
|||||||
import { useRef } from 'react';
|
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormRow,
|
FormRow,
|
||||||
@ -12,11 +11,12 @@ import { setValue } from 'store/cache';
|
|||||||
import useApi from 'components/hooks/useApi';
|
import useApi from 'components/hooks/useApi';
|
||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
|
|
||||||
export function TeamAddForm({ onSave, onClose }) {
|
export function TeamAddForm({ onSave, onClose }: { onSave: () => void; onClose: () => void }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error, isLoading } = useMutation(data => post('/teams', data));
|
const { mutate, error, isPending } = useMutation({
|
||||||
const ref = useRef(null);
|
mutationFn: (data: any) => post('/teams', data),
|
||||||
|
});
|
||||||
|
|
||||||
const handleSubmit = async data => {
|
const handleSubmit = async data => {
|
||||||
mutate(data, {
|
mutate(data, {
|
||||||
@ -29,17 +29,17 @@ export function TeamAddForm({ onSave, onClose }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form ref={ref} onSubmit={handleSubmit} error={error}>
|
<Form onSubmit={handleSubmit} error={error}>
|
||||||
<FormRow label={formatMessage(labels.name)}>
|
<FormRow label={formatMessage(labels.name)}>
|
||||||
<FormInput name="name" rules={{ required: formatMessage(labels.required) }}>
|
<FormInput name="name" rules={{ required: formatMessage(labels.required) }}>
|
||||||
<TextField autoComplete="off" />
|
<TextField autoComplete="off" />
|
||||||
</FormInput>
|
</FormInput>
|
||||||
</FormRow>
|
</FormRow>
|
||||||
<FormButtons flex>
|
<FormButtons flex>
|
||||||
<SubmitButton variant="primary" disabled={isLoading}>
|
<SubmitButton variant="primary" disabled={isPending}>
|
||||||
{formatMessage(labels.save)}
|
{formatMessage(labels.save)}
|
||||||
</SubmitButton>
|
</SubmitButton>
|
||||||
<Button disabled={isLoading} onClick={onClose}>
|
<Button disabled={isPending} onClick={onClose}>
|
||||||
{formatMessage(labels.cancel)}
|
{formatMessage(labels.cancel)}
|
||||||
</Button>
|
</Button>
|
||||||
</FormButtons>
|
</FormButtons>
|
@ -2,7 +2,15 @@ import { Button, Icon, Icons, Modal, ModalTrigger, Text } from 'react-basics';
|
|||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
import TeamDeleteForm from './TeamDeleteForm';
|
import TeamDeleteForm from './TeamDeleteForm';
|
||||||
|
|
||||||
export function TeamDeleteButton({ teamId, teamName, onDelete }) {
|
export function TeamDeleteButton({
|
||||||
|
teamId,
|
||||||
|
teamName,
|
||||||
|
onDelete,
|
||||||
|
}: {
|
||||||
|
teamId: string;
|
||||||
|
teamName: string;
|
||||||
|
onDelete?: () => void;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -14,7 +22,7 @@ export function TeamDeleteButton({ teamId, teamName, onDelete }) {
|
|||||||
<Text>{formatMessage(labels.delete)}</Text>
|
<Text>{formatMessage(labels.delete)}</Text>
|
||||||
</Button>
|
</Button>
|
||||||
<Modal title={formatMessage(labels.deleteTeam)}>
|
<Modal title={formatMessage(labels.deleteTeam)}>
|
||||||
{close => (
|
{(close: any) => (
|
||||||
<TeamDeleteForm teamId={teamId} teamName={teamName} onSave={onDelete} onClose={close} />
|
<TeamDeleteForm teamId={teamId} teamName={teamName} onSave={onDelete} onClose={close} />
|
||||||
)}
|
)}
|
||||||
</Modal>
|
</Modal>
|
@ -3,10 +3,22 @@ import useApi from 'components/hooks/useApi';
|
|||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
import { setValue } from 'store/cache';
|
import { setValue } from 'store/cache';
|
||||||
|
|
||||||
export function TeamDeleteForm({ teamId, teamName, onSave, onClose }) {
|
export function TeamDeleteForm({
|
||||||
|
teamId,
|
||||||
|
teamName,
|
||||||
|
onSave,
|
||||||
|
onClose,
|
||||||
|
}: {
|
||||||
|
teamId: string;
|
||||||
|
teamName: string;
|
||||||
|
onSave: () => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
||||||
const { del, useMutation } = useApi();
|
const { del, useMutation } = useApi();
|
||||||
const { mutate, error, isLoading } = useMutation(data => del(`/teams/${teamId}`, data));
|
const { mutate, error, isPending } = useMutation({
|
||||||
|
mutationFn: (data: any) => del(`/teams/${teamId}`, data),
|
||||||
|
});
|
||||||
|
|
||||||
const handleSubmit = async data => {
|
const handleSubmit = async data => {
|
||||||
mutate(data, {
|
mutate(data, {
|
||||||
@ -24,7 +36,7 @@ export function TeamDeleteForm({ teamId, teamName, onSave, onClose }) {
|
|||||||
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{teamName}</b> }} />
|
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{teamName}</b> }} />
|
||||||
</p>
|
</p>
|
||||||
<FormButtons flex>
|
<FormButtons flex>
|
||||||
<SubmitButton variant="danger" disabled={isLoading}>
|
<SubmitButton variant="danger" disabled={isPending}>
|
||||||
{formatMessage(labels.delete)}
|
{formatMessage(labels.delete)}
|
||||||
</SubmitButton>
|
</SubmitButton>
|
||||||
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
@ -12,10 +12,10 @@ import useApi from 'components/hooks/useApi';
|
|||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
import { setValue } from 'store/cache';
|
import { setValue } from 'store/cache';
|
||||||
|
|
||||||
export function TeamJoinForm({ onSave, onClose }) {
|
export function TeamJoinForm({ onSave, onClose }: { onSave: () => void; onClose: () => void }) {
|
||||||
const { formatMessage, labels, getMessage } = useMessages();
|
const { formatMessage, labels, getMessage } = useMessages();
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error } = useMutation(data => post('/teams/join', data));
|
const { mutate, error } = useMutation({ mutationFn: (data: any) => post('/teams/join', data) });
|
||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
|
|
||||||
const handleSubmit = async data => {
|
const handleSubmit = async data => {
|
@ -4,7 +4,15 @@ import useLocale from 'components/hooks/useLocale';
|
|||||||
import useUser from 'components/hooks/useUser';
|
import useUser from 'components/hooks/useUser';
|
||||||
import TeamDeleteForm from './TeamLeaveForm';
|
import TeamDeleteForm from './TeamLeaveForm';
|
||||||
|
|
||||||
export function TeamLeaveButton({ teamId, teamName, onLeave }) {
|
export function TeamLeaveButton({
|
||||||
|
teamId,
|
||||||
|
teamName,
|
||||||
|
onLeave,
|
||||||
|
}: {
|
||||||
|
teamId: string;
|
||||||
|
teamName: string;
|
||||||
|
onLeave?: () => void;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { dir } = useLocale();
|
const { dir } = useLocale();
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
@ -3,22 +3,33 @@ import useApi from 'components/hooks/useApi';
|
|||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
import { setValue } from 'store/cache';
|
import { setValue } from 'store/cache';
|
||||||
|
|
||||||
export function TeamLeaveForm({ teamId, userId, teamName, onSave, onClose }) {
|
export function TeamLeaveForm({
|
||||||
|
teamId,
|
||||||
|
userId,
|
||||||
|
teamName,
|
||||||
|
onSave,
|
||||||
|
onClose,
|
||||||
|
}: {
|
||||||
|
teamId: string;
|
||||||
|
userId: string;
|
||||||
|
teamName: string;
|
||||||
|
onSave: () => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
||||||
const { del, useMutation } = useApi();
|
const { del, useMutation } = useApi();
|
||||||
const { mutate, error, isLoading } = useMutation(() => del(`/teams/${teamId}/users/${userId}`));
|
const { mutate, error, isPending } = useMutation({
|
||||||
|
mutationFn: () => del(`/teams/${teamId}/users/${userId}`),
|
||||||
|
});
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
mutate(
|
mutate(null, {
|
||||||
{},
|
onSuccess: async () => {
|
||||||
{
|
setValue('team:members', Date.now());
|
||||||
onSuccess: async () => {
|
onSave();
|
||||||
setValue('team:members', Date.now());
|
onClose();
|
||||||
onSave();
|
|
||||||
onClose();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -27,7 +38,7 @@ export function TeamLeaveForm({ teamId, userId, teamName, onSave, onClose }) {
|
|||||||
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{teamName}</b> }} />
|
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{teamName}</b> }} />
|
||||||
</p>
|
</p>
|
||||||
<FormButtons flex>
|
<FormButtons flex>
|
||||||
<SubmitButton variant="danger" disabled={isLoading}>
|
<SubmitButton variant="danger" disabled={isPending}>
|
||||||
{formatMessage(labels.leave)}
|
{formatMessage(labels.leave)}
|
||||||
</SubmitButton>
|
</SubmitButton>
|
||||||
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
@ -3,7 +3,7 @@ import Icons from 'components/icons';
|
|||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
import TeamAddForm from './TeamAddForm';
|
import TeamAddForm from './TeamAddForm';
|
||||||
|
|
||||||
export function TeamsAddButton({ onAdd }) {
|
export function TeamsAddButton({ onAdd }: { onAdd?: () => void }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -15,7 +15,7 @@ export function TeamsAddButton({ onAdd }) {
|
|||||||
<Text>{formatMessage(labels.createTeam)}</Text>
|
<Text>{formatMessage(labels.createTeam)}</Text>
|
||||||
</Button>
|
</Button>
|
||||||
<Modal title={formatMessage(labels.createTeam)}>
|
<Modal title={formatMessage(labels.createTeam)}>
|
||||||
{close => <TeamAddForm onSave={onAdd} onClose={close} />}
|
{(close: () => void) => <TeamAddForm onSave={onAdd} onClose={close} />}
|
||||||
</Modal>
|
</Modal>
|
||||||
</ModalTrigger>
|
</ModalTrigger>
|
||||||
);
|
);
|
@ -7,11 +7,14 @@ import useCache from 'store/cache';
|
|||||||
|
|
||||||
export function TeamsDataTable() {
|
export function TeamsDataTable() {
|
||||||
const { get } = useApi();
|
const { get } = useApi();
|
||||||
const modified = useCache(state => state?.teams);
|
const modified = useCache((state: any) => state?.teams);
|
||||||
const queryResult = useFilterQuery(['teams', { modified }], params => {
|
const queryResult = useFilterQuery({
|
||||||
return get(`/teams`, {
|
queryKey: ['teams', { modified }],
|
||||||
...params,
|
queryFn: (params: any) => {
|
||||||
});
|
return get(`/teams`, {
|
||||||
|
...params,
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
@ -7,7 +7,7 @@ import { Button, GridColumn, GridTable, Icon, Icons, Text, useBreakpoint } from
|
|||||||
import TeamDeleteButton from './TeamDeleteButton';
|
import TeamDeleteButton from './TeamDeleteButton';
|
||||||
import TeamLeaveButton from './TeamLeaveButton';
|
import TeamLeaveButton from './TeamLeaveButton';
|
||||||
|
|
||||||
export function TeamsTable({ data = [] }) {
|
export function TeamsTable({ data = [] }: { data: any[] }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
const breakpoint = useBreakpoint();
|
const breakpoint = useBreakpoint();
|
@ -1,7 +1,15 @@
|
|||||||
import { Button, Icon, Icons, Text } from 'react-basics';
|
import { Button, Icon, Icons, Text } from 'react-basics';
|
||||||
import styles from './WebsiteTags.module.css';
|
import styles from './WebsiteTags.module.css';
|
||||||
|
|
||||||
export function WebsiteTags({ items = [], websites = [], onClick }) {
|
export function WebsiteTags({
|
||||||
|
items = [],
|
||||||
|
websites = [],
|
||||||
|
onClick,
|
||||||
|
}: {
|
||||||
|
items: any[];
|
||||||
|
websites: any[];
|
||||||
|
onClick: (e: Event) => void;
|
||||||
|
}) {
|
||||||
if (websites.length === 0) {
|
if (websites.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
@ -3,28 +3,37 @@ import useMessages from 'components/hooks/useMessages';
|
|||||||
import { Icon, Icons, LoadingButton, Text } from 'react-basics';
|
import { Icon, Icons, LoadingButton, Text } from 'react-basics';
|
||||||
import { setValue } from 'store/cache';
|
import { setValue } from 'store/cache';
|
||||||
|
|
||||||
export function TeamMemberRemoveButton({ teamId, userId, disabled, onSave }) {
|
export function TeamMemberRemoveButton({
|
||||||
|
teamId,
|
||||||
|
userId,
|
||||||
|
disabled,
|
||||||
|
onSave,
|
||||||
|
}: {
|
||||||
|
teamId: string;
|
||||||
|
userId: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
onSave?: () => void;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { del, useMutation } = useApi();
|
const { del, useMutation } = useApi();
|
||||||
const { mutate, isLoading } = useMutation(() => del(`/teams/${teamId}/users/${userId}`));
|
const { mutate, isPending } = useMutation({
|
||||||
|
mutationFn: () => del(`/teams/${teamId}/users/${userId}`),
|
||||||
|
});
|
||||||
|
|
||||||
const handleRemoveTeamMember = () => {
|
const handleRemoveTeamMember = () => {
|
||||||
mutate(
|
mutate(null, {
|
||||||
{},
|
onSuccess: () => {
|
||||||
{
|
setValue('team:members', Date.now());
|
||||||
onSuccess: () => {
|
onSave?.();
|
||||||
setValue('team:members', Date.now());
|
|
||||||
onSave?.();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
onClick={() => handleRemoveTeamMember()}
|
onClick={() => handleRemoveTeamMember()}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
isLoading={isLoading}
|
isLoading={isPending}
|
||||||
>
|
>
|
||||||
<Icon>
|
<Icon>
|
||||||
<Icons.Close />
|
<Icons.Close />
|
@ -4,18 +4,18 @@ import useFilterQuery from 'components/hooks/useFilterQuery';
|
|||||||
import DataTable from 'components/common/DataTable';
|
import DataTable from 'components/common/DataTable';
|
||||||
import useCache from 'store/cache';
|
import useCache from 'store/cache';
|
||||||
|
|
||||||
export function TeamMembers({ teamId, readOnly }) {
|
export function TeamMembers({ teamId, readOnly }: { teamId: string; readOnly: boolean }) {
|
||||||
const { get } = useApi();
|
const { get } = useApi();
|
||||||
const modified = useCache(state => state?.['team:members']);
|
const modified = useCache(state => state?.['team:members']);
|
||||||
const queryResult = useFilterQuery(
|
const queryResult = useFilterQuery({
|
||||||
['team:members', { teamId, modified }],
|
queryKey: ['team:members', { teamId, modified }],
|
||||||
params => {
|
queryFn: params => {
|
||||||
return get(`/teams/${teamId}/users`, {
|
return get(`/teams/${teamId}/users`, {
|
||||||
...params,
|
...params,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
{ enabled: !!teamId },
|
enabled: !!teamId,
|
||||||
);
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
@ -4,7 +4,15 @@ import useUser from 'components/hooks/useUser';
|
|||||||
import { ROLES } from 'lib/constants';
|
import { ROLES } from 'lib/constants';
|
||||||
import TeamMemberRemoveButton from './TeamMemberRemoveButton';
|
import TeamMemberRemoveButton from './TeamMemberRemoveButton';
|
||||||
|
|
||||||
export function TeamMembersTable({ data = [], teamId, readOnly }) {
|
export function TeamMembersTable({
|
||||||
|
data = [],
|
||||||
|
teamId,
|
||||||
|
readOnly,
|
||||||
|
}: {
|
||||||
|
data: any[];
|
||||||
|
teamId: string;
|
||||||
|
readOnly: boolean;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
const breakpoint = useBreakpoint();
|
const breakpoint = useBreakpoint();
|
@ -10,22 +10,22 @@ import TeamEditForm from './TeamEditForm';
|
|||||||
import TeamMembers from './TeamMembers';
|
import TeamMembers from './TeamMembers';
|
||||||
import TeamWebsites from './TeamWebsites';
|
import TeamWebsites from './TeamWebsites';
|
||||||
|
|
||||||
export function TeamSettings({ teamId }) {
|
export function TeamSettings({ teamId }: { teamId: string }) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
const [values, setValues] = useState(null);
|
const [values, setValues] = useState(null);
|
||||||
const [tab, setTab] = useState('details');
|
const [tab, setTab] = useState('details');
|
||||||
const { get, useQuery } = useApi();
|
const { get, useQuery } = useApi();
|
||||||
const { showToast } = useToasts();
|
const { showToast } = useToasts();
|
||||||
const { data, isLoading } = useQuery(
|
const { data, isLoading } = useQuery({
|
||||||
['team', teamId],
|
queryKey: ['team', teamId],
|
||||||
() => {
|
queryFn: () => {
|
||||||
if (teamId) {
|
if (teamId) {
|
||||||
return get(`/teams/${teamId}`);
|
return get(`/teams/${teamId}`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ cacheTime: 0 },
|
gcTime: 0,
|
||||||
);
|
});
|
||||||
const canEdit = data?.teamUser?.find(
|
const canEdit = data?.teamUser?.find(
|
||||||
({ userId, role }) => role === ROLES.teamOwner && userId === user.id,
|
({ userId, role }) => role === ROLES.teamOwner && userId === user.id,
|
||||||
);
|
);
|
||||||
@ -48,7 +48,7 @@ export function TeamSettings({ teamId }) {
|
|||||||
return (
|
return (
|
||||||
<Flexbox direction="column">
|
<Flexbox direction="column">
|
||||||
<PageHeader title={values?.name} />
|
<PageHeader title={values?.name} />
|
||||||
<Tabs selectedKey={tab} onSelect={setTab} style={{ marginBottom: 30 }}>
|
<Tabs selectedKey={tab} onSelect={(value: any) => setTab(value)} style={{ marginBottom: 30 }}>
|
||||||
<Item key="details">{formatMessage(labels.details)}</Item>
|
<Item key="details">{formatMessage(labels.details)}</Item>
|
||||||
<Item key="members">{formatMessage(labels.members)}</Item>
|
<Item key="members">{formatMessage(labels.members)}</Item>
|
||||||
<Item key="websites">{formatMessage(labels.websites)}</Item>
|
<Item key="websites">{formatMessage(labels.websites)}</Item>
|
@ -7,12 +7,25 @@ import Empty from 'components/common/Empty';
|
|||||||
import { setValue } from 'store/cache';
|
import { setValue } from 'store/cache';
|
||||||
import { useUser } from 'components/hooks';
|
import { useUser } from 'components/hooks';
|
||||||
|
|
||||||
export function TeamWebsiteAddForm({ teamId, onSave, onClose }) {
|
export function TeamWebsiteAddForm({
|
||||||
|
teamId,
|
||||||
|
onSave,
|
||||||
|
onClose,
|
||||||
|
}: {
|
||||||
|
teamId: string;
|
||||||
|
onSave: () => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}) {
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { get, post, useQuery, useMutation } = useApi();
|
const { get, post, useQuery, useMutation } = useApi();
|
||||||
const { mutate, error } = useMutation(data => post(`/teams/${teamId}/websites`, data));
|
const { mutate, error } = useMutation({
|
||||||
const { data: websites, isLoading } = useQuery(['websites'], () => get('/websites'));
|
mutationFn: (data: any) => post(`/teams/${teamId}/websites`, data),
|
||||||
|
});
|
||||||
|
const { data: websites, isLoading } = useQuery({
|
||||||
|
queryKey: ['websites'],
|
||||||
|
queryFn: () => get('/websites'),
|
||||||
|
});
|
||||||
const [selected, setSelected] = useState([]);
|
const [selected, setSelected] = useState([]);
|
||||||
const hasData = websites && websites.data.length > 0;
|
const hasData = websites && websites.data.length > 0;
|
||||||
|
|
||||||
@ -39,7 +52,7 @@ export function TeamWebsiteAddForm({ teamId, onSave, onClose }) {
|
|||||||
{!isLoading && !hasData && <Empty />}
|
{!isLoading && !hasData && <Empty />}
|
||||||
{hasData && (
|
{hasData && (
|
||||||
<Form onSubmit={handleSubmit} error={error}>
|
<Form onSubmit={handleSubmit} error={error}>
|
||||||
<WebsitesDataTable userId={user.id} showHeader={false} showActions={false}>
|
<WebsitesDataTable userId={user.id} showActions={false}>
|
||||||
<GridColumn name="select" label={formatMessage(labels.selectWebsite)} alignment="end">
|
<GridColumn name="select" label={formatMessage(labels.selectWebsite)} alignment="end">
|
||||||
{row => (
|
{row => (
|
||||||
<Toggle
|
<Toggle
|
@ -8,23 +8,23 @@ import useFilterQuery from 'components/hooks/useFilterQuery';
|
|||||||
import DataTable from 'components/common/DataTable';
|
import DataTable from 'components/common/DataTable';
|
||||||
import useCache from 'store/cache';
|
import useCache from 'store/cache';
|
||||||
|
|
||||||
export function TeamWebsites({ teamId }) {
|
export function TeamWebsites({ teamId, readOnly }: { teamId: string; readOnly: boolean }) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
const { get } = useApi();
|
const { get } = useApi();
|
||||||
const modified = useCache(state => state?.['team:websites']);
|
const modified = useCache(state => state?.['team:websites']);
|
||||||
const queryResult = useFilterQuery(
|
const queryResult = useFilterQuery({
|
||||||
['team:websites', { teamId, modified }],
|
queryKey: ['team:websites', { teamId, modified }],
|
||||||
params => {
|
queryFn: params => {
|
||||||
return get(`/teams/${teamId}/websites`, {
|
return get(`/teams/${teamId}/websites`, {
|
||||||
...params,
|
...params,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
{ enabled: !!user },
|
enabled: !!user,
|
||||||
);
|
});
|
||||||
|
|
||||||
const handleChange = () => {
|
const handleChange = () => {
|
||||||
queryResult.refetch();
|
queryResult.query.refetch();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -43,7 +43,9 @@ export function TeamWebsites({ teamId }) {
|
|||||||
</ModalTrigger>
|
</ModalTrigger>
|
||||||
</ActionForm>
|
</ActionForm>
|
||||||
<DataTable queryResult={queryResult}>
|
<DataTable queryResult={queryResult}>
|
||||||
{({ data }) => <TeamWebsitesTable data={data} onRemove={handleChange} />}
|
{({ data }) => (
|
||||||
|
<TeamWebsitesTable data={data} onRemove={handleChange} readOnly={readOnly} />
|
||||||
|
)}
|
||||||
</DataTable>
|
</DataTable>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
@ -4,7 +4,15 @@ import useMessages from 'components/hooks/useMessages';
|
|||||||
import useUser from 'components/hooks/useUser';
|
import useUser from 'components/hooks/useUser';
|
||||||
import TeamWebsiteRemoveButton from './TeamWebsiteRemoveButton';
|
import TeamWebsiteRemoveButton from './TeamWebsiteRemoveButton';
|
||||||
|
|
||||||
export function TeamWebsitesTable({ data = [], onRemove }) {
|
export function TeamWebsitesTable({
|
||||||
|
data = [],
|
||||||
|
readOnly,
|
||||||
|
onRemove,
|
||||||
|
}: {
|
||||||
|
data: any[];
|
||||||
|
readOnly: boolean;
|
||||||
|
onRemove: () => void;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
|
|
||||||
@ -17,7 +25,7 @@ export function TeamWebsitesTable({ data = [], onRemove }) {
|
|||||||
const { id: teamId, teamUser } = row.teamWebsite[0].team;
|
const { id: teamId, teamUser } = row.teamWebsite[0].team;
|
||||||
const { id: websiteId, userId } = row;
|
const { id: websiteId, userId } = row;
|
||||||
const owner = teamUser[0];
|
const owner = teamUser[0];
|
||||||
const canRemove = user.id === userId || user.id === owner.userId;
|
const canRemove = !readOnly && (user.id === userId || user.id === owner.userId);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{canRemove && (
|
{canRemove && (
|
@ -3,7 +3,7 @@ import UserAddForm from './UserAddForm';
|
|||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
import { setValue } from 'store/cache';
|
import { setValue } from 'store/cache';
|
||||||
|
|
||||||
export function UserAddButton({ onSave }) {
|
export function UserAddButton({ onSave }: { onSave?: () => void }) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { showToast } = useToasts();
|
const { showToast } = useToasts();
|
||||||
|
|
@ -16,7 +16,9 @@ import useMessages from 'components/hooks/useMessages';
|
|||||||
|
|
||||||
export function UserAddForm({ onSave, onClose }) {
|
export function UserAddForm({ onSave, onClose }) {
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error, isLoading } = useMutation(data => post(`/users`, data));
|
const { mutate, error, isPending } = useMutation({
|
||||||
|
mutationFn: (data: any) => post(`/users`, data),
|
||||||
|
});
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
||||||
const handleSubmit = async data => {
|
const handleSubmit = async data => {
|
||||||
@ -65,7 +67,7 @@ export function UserAddForm({ onSave, onClose }) {
|
|||||||
<SubmitButton variant="primary" disabled={false}>
|
<SubmitButton variant="primary" disabled={false}>
|
||||||
{formatMessage(labels.save)}
|
{formatMessage(labels.save)}
|
||||||
</SubmitButton>
|
</SubmitButton>
|
||||||
<Button disabled={isLoading} onClick={onClose}>
|
<Button disabled={isPending} onClick={onClose}>
|
||||||
{formatMessage(labels.cancel)}
|
{formatMessage(labels.cancel)}
|
||||||
</Button>
|
</Button>
|
||||||
</FormButtons>
|
</FormButtons>
|
@ -3,7 +3,15 @@ import useMessages from 'components/hooks/useMessages';
|
|||||||
import useUser from 'components/hooks/useUser';
|
import useUser from 'components/hooks/useUser';
|
||||||
import UserDeleteForm from './UserDeleteForm';
|
import UserDeleteForm from './UserDeleteForm';
|
||||||
|
|
||||||
export function UserDeleteButton({ userId, username, onDelete }) {
|
export function UserDeleteButton({
|
||||||
|
userId,
|
||||||
|
username,
|
||||||
|
onDelete,
|
||||||
|
}: {
|
||||||
|
userId: string;
|
||||||
|
username: string;
|
||||||
|
onDelete?: () => void;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
|
|
@ -1,14 +1,13 @@
|
|||||||
import { useMutation } from '@tanstack/react-query';
|
|
||||||
import { Button, Form, FormButtons, SubmitButton } from 'react-basics';
|
import { Button, Form, FormButtons, SubmitButton } from 'react-basics';
|
||||||
import useApi from 'components/hooks/useApi';
|
import useApi from 'components/hooks/useApi';
|
||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
|
|
||||||
export function UserDeleteForm({ userId, username, onSave, onClose }) {
|
export function UserDeleteForm({ userId, username, onSave, onClose }) {
|
||||||
const { formatMessage, FormattedMessage, labels, messages } = useMessages();
|
const { formatMessage, FormattedMessage, labels, messages } = useMessages();
|
||||||
const { del } = useApi();
|
const { del, useMutation } = useApi();
|
||||||
const { mutate, error, isLoading } = useMutation(() => del(`/users/${userId}`));
|
const { mutate, error, isPending } = useMutation({ mutationFn: () => del(`/users/${userId}`) });
|
||||||
|
|
||||||
const handleSubmit = async data => {
|
const handleSubmit = async (data: any) => {
|
||||||
mutate(data, {
|
mutate(data, {
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
onSave();
|
onSave();
|
||||||
@ -23,10 +22,10 @@ export function UserDeleteForm({ userId, username, onSave, onClose }) {
|
|||||||
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{username}</b> }} />
|
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{username}</b> }} />
|
||||||
</p>
|
</p>
|
||||||
<FormButtons flex>
|
<FormButtons flex>
|
||||||
<SubmitButton variant="danger" disabled={isLoading}>
|
<SubmitButton variant="danger" disabled={isPending}>
|
||||||
{formatMessage(labels.delete)}
|
{formatMessage(labels.delete)}
|
||||||
</SubmitButton>
|
</SubmitButton>
|
||||||
<Button disabled={isLoading} onClick={onClose}>
|
<Button disabled={isPending} onClick={onClose}>
|
||||||
{formatMessage(labels.cancel)}
|
{formatMessage(labels.cancel)}
|
||||||
</Button>
|
</Button>
|
||||||
</FormButtons>
|
</FormButtons>
|
@ -13,14 +13,30 @@ import useApi from 'components/hooks/useApi';
|
|||||||
import { ROLES } from 'lib/constants';
|
import { ROLES } from 'lib/constants';
|
||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
|
|
||||||
export function UserEditForm({ userId, data, onSave }) {
|
export function UserEditForm({
|
||||||
|
userId,
|
||||||
|
data,
|
||||||
|
onSave,
|
||||||
|
}: {
|
||||||
|
userId: string;
|
||||||
|
data: any[];
|
||||||
|
onSave: (data: any) => void;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error } = useMutation(({ username, password, role }) =>
|
const { mutate, error } = useMutation({
|
||||||
post(`/users/${userId}`, { username, password, role }),
|
mutationFn: ({
|
||||||
);
|
username,
|
||||||
|
password,
|
||||||
|
role,
|
||||||
|
}: {
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
role: string;
|
||||||
|
}) => post(`/users/${userId}`, { username, password, role }),
|
||||||
|
});
|
||||||
|
|
||||||
const handleSubmit = async data => {
|
const handleSubmit = async (data: any) => {
|
||||||
mutate(data, {
|
mutate(data, {
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
onSave(data);
|
onSave(data);
|
@ -1,36 +0,0 @@
|
|||||||
import Page from 'components/layout/Page';
|
|
||||||
import useApi from 'components/hooks/useApi';
|
|
||||||
import WebsitesTable from 'app/(main)/settings/websites/WebsitesTable';
|
|
||||||
import useApiFilter from 'components/hooks/useApiFilter';
|
|
||||||
|
|
||||||
export function UserWebsites({ userId }) {
|
|
||||||
const { filter, page, pageSize, handleFilterChange, handlePageChange, handlePageSizeChange } =
|
|
||||||
useApiFilter();
|
|
||||||
const { get, useQuery } = useApi();
|
|
||||||
const { data, isLoading, error } = useQuery(
|
|
||||||
['user:websites', userId, filter, page, pageSize],
|
|
||||||
() =>
|
|
||||||
get(`/users/${userId}/websites`, {
|
|
||||||
filter,
|
|
||||||
page,
|
|
||||||
pageSize,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const hasData = data && data.length !== 0;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Page loading={isLoading} error={error}>
|
|
||||||
{hasData && (
|
|
||||||
<WebsitesTable
|
|
||||||
data={data.data}
|
|
||||||
onFilterChange={handleFilterChange}
|
|
||||||
onPageChange={handlePageChange}
|
|
||||||
onPageSizeChange={handlePageSizeChange}
|
|
||||||
filterValue={filter}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Page>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default UserWebsites;
|
|
26
src/app/(main)/settings/users/UserWebsites.tsx
Normal file
26
src/app/(main)/settings/users/UserWebsites.tsx
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import Page from 'components/layout/Page';
|
||||||
|
import useApi from 'components/hooks/useApi';
|
||||||
|
import WebsitesTable from 'app/(main)/settings/websites/WebsitesTable';
|
||||||
|
import useFilterQuery from 'components/hooks/useFilterQuery';
|
||||||
|
import DataTable from 'components/common/DataTable';
|
||||||
|
|
||||||
|
export function UserWebsites({ userId }) {
|
||||||
|
const { get } = useApi();
|
||||||
|
const queryResult = useFilterQuery({
|
||||||
|
queryKey: ['user:websites', userId],
|
||||||
|
queryFn: (params: any) => get(`/users/${userId}/websites`, params),
|
||||||
|
});
|
||||||
|
const hasData = queryResult.result && queryResult.result.data.length !== 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Page isLoading={queryResult.query.isLoading} error={queryResult.query.error}>
|
||||||
|
{hasData && (
|
||||||
|
<DataTable queryResult={queryResult}>
|
||||||
|
{({ data }) => <WebsitesTable data={data} />}
|
||||||
|
</DataTable>
|
||||||
|
)}
|
||||||
|
</Page>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UserWebsites;
|
@ -8,11 +8,10 @@ import useCache from 'store/cache';
|
|||||||
|
|
||||||
export function UsersDataTable() {
|
export function UsersDataTable() {
|
||||||
const { get } = useApi();
|
const { get } = useApi();
|
||||||
const modified = useCache(state => state?.users);
|
const modified = useCache((state: any) => state?.users);
|
||||||
const queryResult = useFilterQuery(['users', { modified }], params => {
|
const queryResult = useFilterQuery({
|
||||||
return get(`/users`, {
|
queryKey: ['users', { modified }],
|
||||||
...params,
|
queryFn: (params: { [key: string]: any }) => get(`/users`, params),
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
@ -3,7 +3,7 @@ import PageHeader from 'components/layout/PageHeader';
|
|||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
import UserAddButton from './UserAddButton';
|
import UserAddButton from './UserAddButton';
|
||||||
|
|
||||||
export function UsersHeader({ onAdd }) {
|
export function UsersHeader({ onAdd }: { onAdd?: () => void }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
||||||
return (
|
return (
|
@ -6,7 +6,7 @@ import useMessages from 'components/hooks/useMessages';
|
|||||||
import useLocale from 'components/hooks/useLocale';
|
import useLocale from 'components/hooks/useLocale';
|
||||||
import UserDeleteButton from './UserDeleteButton';
|
import UserDeleteButton from './UserDeleteButton';
|
||||||
|
|
||||||
export function UsersTable({ data = [] }) {
|
export function UsersTable({ data = [] }: { data: any[] }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { dateLocale } = useLocale();
|
const { dateLocale } = useLocale();
|
||||||
const breakpoint = useBreakpoint();
|
const breakpoint = useBreakpoint();
|
@ -14,15 +14,15 @@ export function UserSettings({ userId }) {
|
|||||||
const [tab, setTab] = useState('details');
|
const [tab, setTab] = useState('details');
|
||||||
const { get, useQuery } = useApi();
|
const { get, useQuery } = useApi();
|
||||||
const { showToast } = useToasts();
|
const { showToast } = useToasts();
|
||||||
const { data, isLoading } = useQuery(
|
const { data, isLoading } = useQuery({
|
||||||
['user', userId],
|
queryKey: ['user', userId],
|
||||||
() => {
|
queryFn: () => {
|
||||||
if (userId) {
|
if (userId) {
|
||||||
return get(`/users/${userId}`);
|
return get(`/users/${userId}`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ cacheTime: 0 },
|
gcTime: 0,
|
||||||
);
|
});
|
||||||
|
|
||||||
const handleSave = data => {
|
const handleSave = data => {
|
||||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||||
|
@ -3,7 +3,7 @@ import WebsiteAddForm from './WebsiteAddForm';
|
|||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
import { setValue } from 'store/cache';
|
import { setValue } from 'store/cache';
|
||||||
|
|
||||||
export function WebsiteAddButton({ onSave }) {
|
export function WebsiteAddButton({ onSave }: { onSave?: () => void }) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { showToast } = useToasts();
|
const { showToast } = useToasts();
|
||||||
|
|
@ -14,7 +14,9 @@ import useMessages from 'components/hooks/useMessages';
|
|||||||
export function WebsiteAddForm({ onSave, onClose }: { onSave?: () => void; onClose?: () => void }) {
|
export function WebsiteAddForm({ onSave, onClose }: { onSave?: () => void; onClose?: () => void }) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error, isLoading } = useMutation(data => post('/websites', data));
|
const { mutate, error, isPending } = useMutation({
|
||||||
|
mutationFn: (data: any) => post('/websites', data),
|
||||||
|
});
|
||||||
|
|
||||||
const handleSubmit = async (data: any) => {
|
const handleSubmit = async (data: any) => {
|
||||||
mutate(data, {
|
mutate(data, {
|
||||||
@ -26,7 +28,7 @@ export function WebsiteAddForm({ onSave, onClose }: { onSave?: () => void; onClo
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form onSubmit={handleSubmit} error={error as string}>
|
<Form onSubmit={handleSubmit} error={error}>
|
||||||
<FormRow label={formatMessage(labels.name)}>
|
<FormRow label={formatMessage(labels.name)}>
|
||||||
<FormInput name="name" rules={{ required: formatMessage(labels.required) }}>
|
<FormInput name="name" rules={{ required: formatMessage(labels.required) }}>
|
||||||
<TextField autoComplete="off" />
|
<TextField autoComplete="off" />
|
||||||
@ -48,7 +50,7 @@ export function WebsiteAddForm({ onSave, onClose }: { onSave?: () => void; onClo
|
|||||||
{formatMessage(labels.save)}
|
{formatMessage(labels.save)}
|
||||||
</SubmitButton>
|
</SubmitButton>
|
||||||
{onClose && (
|
{onClose && (
|
||||||
<Button disabled={isLoading} onClick={onClose}>
|
<Button disabled={isPending} onClick={onClose}>
|
||||||
{formatMessage(labels.cancel)}
|
{formatMessage(labels.cancel)}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Item, Tabs, useToasts, Button, Text, Icon, Icons } from 'react-basics';
|
import { Item, Tabs, useToasts, Button, Text, Icon, Icons, Loading } from 'react-basics';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import PageHeader from 'components/layout/PageHeader';
|
import PageHeader from 'components/layout/PageHeader';
|
||||||
@ -16,9 +16,11 @@ export function WebsiteSettings({ websiteId, openExternal = false, analyticsUrl
|
|||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { get, useQuery } = useApi();
|
const { get, useQuery } = useApi();
|
||||||
const { showToast } = useToasts();
|
const { showToast } = useToasts();
|
||||||
const { data } = useQuery(['website', websiteId], () => get(`/websites/${websiteId}`), {
|
const { data, isLoading } = useQuery({
|
||||||
|
queryKey: ['website', websiteId],
|
||||||
|
queryFn: () => get(`/websites/${websiteId}`),
|
||||||
enabled: !!websiteId,
|
enabled: !!websiteId,
|
||||||
cacheTime: 0,
|
gcTime: 0,
|
||||||
});
|
});
|
||||||
const [values, setValues] = useState(null);
|
const [values, setValues] = useState(null);
|
||||||
const [tab, setTab] = useState('details');
|
const [tab, setTab] = useState('details');
|
||||||
@ -46,6 +48,10 @@ export function WebsiteSettings({ websiteId, openExternal = false, analyticsUrl
|
|||||||
}
|
}
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
|
if (isLoading || !values) {
|
||||||
|
return <Loading />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader title={values?.name}>
|
<PageHeader title={values?.name}>
|
||||||
|
@ -21,17 +21,17 @@ function useWebsites(userId: string, { includeTeams, onlyTeams }) {
|
|||||||
const { get } = useApi();
|
const { get } = useApi();
|
||||||
const modified = useCache((state: any) => state?.websites);
|
const modified = useCache((state: any) => state?.websites);
|
||||||
|
|
||||||
return useFilterQuery(
|
return useFilterQuery({
|
||||||
['websites', { includeTeams, onlyTeams, modified }],
|
queryKey: ['websites', { includeTeams, onlyTeams, modified }],
|
||||||
(params: any) => {
|
queryFn: (params: any) => {
|
||||||
return get(`/users/${userId}/websites`, {
|
return get(`/users/${userId}/websites`, {
|
||||||
includeTeams,
|
includeTeams,
|
||||||
onlyTeams,
|
onlyTeams,
|
||||||
...params,
|
...params,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
{ enabled: !!userId },
|
enabled: !!userId,
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function WebsitesDataTable({
|
export function WebsitesDataTable({
|
||||||
|
@ -1,8 +1,18 @@
|
|||||||
|
import { ReactNode } from 'react';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { Button, Text, Icon, Icons, GridTable, GridColumn, useBreakpoint } from 'react-basics';
|
import { Button, Text, Icon, Icons, GridTable, GridColumn, useBreakpoint } from 'react-basics';
|
||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
import useUser from 'components/hooks/useUser';
|
import useUser from 'components/hooks/useUser';
|
||||||
|
|
||||||
|
export interface WebsitesTableProps {
|
||||||
|
data: any[];
|
||||||
|
showTeam?: boolean;
|
||||||
|
showActions?: boolean;
|
||||||
|
allowEdit?: boolean;
|
||||||
|
allowView?: boolean;
|
||||||
|
children?: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
export function WebsitesTable({
|
export function WebsitesTable({
|
||||||
data = [],
|
data = [],
|
||||||
showTeam,
|
showTeam,
|
||||||
@ -10,7 +20,7 @@ export function WebsitesTable({
|
|||||||
allowEdit,
|
allowEdit,
|
||||||
allowView,
|
allowView,
|
||||||
children,
|
children,
|
||||||
}) {
|
}: WebsitesTableProps) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
const breakpoint = useBreakpoint();
|
const breakpoint = useBreakpoint();
|
@ -20,9 +20,9 @@ export function ShareUrl({ websiteId, data, analyticsUrl, onSave }) {
|
|||||||
const { name, shareId } = data;
|
const { name, shareId } = data;
|
||||||
const [id, setId] = useState(shareId);
|
const [id, setId] = useState(shareId);
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error } = useMutation(({ shareId }) =>
|
const { mutate, error } = useMutation({
|
||||||
post(`/websites/${websiteId}`, { shareId }),
|
mutationFn: (data: any) => post(`/websites/${websiteId}`, data),
|
||||||
);
|
});
|
||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
const url = useMemo(
|
const url = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@ -32,7 +32,7 @@ export function ShareUrl({ websiteId, data, analyticsUrl, onSave }) {
|
|||||||
[id, name],
|
[id, name],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSubmit = async data => {
|
const handleSubmit = async (data: any) => {
|
||||||
mutate(data, {
|
mutate(data, {
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
onSave(data);
|
onSave(data);
|
||||||
@ -50,7 +50,7 @@ export function ShareUrl({ websiteId, data, analyticsUrl, onSave }) {
|
|||||||
setId(id);
|
setId(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCheck = checked => {
|
const handleCheck = (checked: boolean) => {
|
||||||
const data = { shareId: checked ? generateId() : null };
|
const data = { shareId: checked ? generateId() : null };
|
||||||
mutate(data, {
|
mutate(data, {
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
@ -2,7 +2,13 @@ import { TextArea } from 'react-basics';
|
|||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
import useConfig from 'components/hooks/useConfig';
|
import useConfig from 'components/hooks/useConfig';
|
||||||
|
|
||||||
export function TrackingCode({ websiteId, analyticsUrl }) {
|
export function TrackingCode({
|
||||||
|
websiteId,
|
||||||
|
analyticsUrl,
|
||||||
|
}: {
|
||||||
|
websiteId: string;
|
||||||
|
analyticsUrl: string;
|
||||||
|
}) {
|
||||||
const { formatMessage, messages } = useMessages();
|
const { formatMessage, messages } = useMessages();
|
||||||
const config = useConfig();
|
const config = useConfig();
|
||||||
|
|
@ -3,7 +3,13 @@ import WebsiteDeleteForm from './WebsiteDeleteForm';
|
|||||||
import WebsiteResetForm from './WebsiteResetForm';
|
import WebsiteResetForm from './WebsiteResetForm';
|
||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
|
|
||||||
export function WebsiteData({ websiteId, onSave }) {
|
export function WebsiteData({
|
||||||
|
websiteId,
|
||||||
|
onSave,
|
||||||
|
}: {
|
||||||
|
websiteId: string;
|
||||||
|
onSave?: (value: string) => void;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
|
|
||||||
const handleReset = async () => {
|
const handleReset = async () => {
|
@ -12,10 +12,20 @@ import useMessages from 'components/hooks/useMessages';
|
|||||||
|
|
||||||
const CONFIRM_VALUE = 'DELETE';
|
const CONFIRM_VALUE = 'DELETE';
|
||||||
|
|
||||||
export function WebsiteDeleteForm({ websiteId, onSave, onClose }) {
|
export function WebsiteDeleteForm({
|
||||||
|
websiteId,
|
||||||
|
onSave,
|
||||||
|
onClose,
|
||||||
|
}: {
|
||||||
|
websiteId: string;
|
||||||
|
onSave?: () => void;
|
||||||
|
onClose?: () => void;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
||||||
const { del, useMutation } = useApi();
|
const { del, useMutation } = useApi();
|
||||||
const { mutate, error } = useMutation(data => del(`/websites/${websiteId}`, data));
|
const { mutate, error } = useMutation({
|
||||||
|
mutationFn: (data: any) => del(`/websites/${websiteId}`, data),
|
||||||
|
});
|
||||||
|
|
||||||
const handleSubmit = async data => {
|
const handleSubmit = async data => {
|
||||||
mutate(data, {
|
mutate(data, {
|
@ -4,10 +4,20 @@ import useApi from 'components/hooks/useApi';
|
|||||||
import { DOMAIN_REGEX } from 'lib/constants';
|
import { DOMAIN_REGEX } from 'lib/constants';
|
||||||
import useMessages from 'components/hooks/useMessages';
|
import useMessages from 'components/hooks/useMessages';
|
||||||
|
|
||||||
export function WebsiteEditForm({ websiteId, data, onSave }) {
|
export function WebsiteEditForm({
|
||||||
|
websiteId,
|
||||||
|
data,
|
||||||
|
onSave,
|
||||||
|
}: {
|
||||||
|
websiteId: string;
|
||||||
|
data: any[];
|
||||||
|
onSave?: (data: any) => void;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error } = useMutation(data => post(`/websites/${websiteId}`, data));
|
const { mutate, error } = useMutation({
|
||||||
|
mutationFn: (data: any) => post(`/websites/${websiteId}`, data),
|
||||||
|
});
|
||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
|
|
||||||
const handleSubmit = async data => {
|
const handleSubmit = async data => {
|
@ -12,12 +12,22 @@ import useMessages from 'components/hooks/useMessages';
|
|||||||
|
|
||||||
const CONFIRM_VALUE = 'RESET';
|
const CONFIRM_VALUE = 'RESET';
|
||||||
|
|
||||||
export function WebsiteResetForm({ websiteId, onSave, onClose }) {
|
export function WebsiteResetForm({
|
||||||
|
websiteId,
|
||||||
|
onSave,
|
||||||
|
onClose,
|
||||||
|
}: {
|
||||||
|
websiteId: string;
|
||||||
|
onSave?: () => void;
|
||||||
|
onClose?: () => void;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error } = useMutation(data => post(`/websites/${websiteId}/reset`, data));
|
const { mutate, error } = useMutation({
|
||||||
|
mutationFn: (data: any) => post(`/websites/${websiteId}/reset`, data),
|
||||||
|
});
|
||||||
|
|
||||||
const handleSubmit = async data => {
|
const handleSubmit = async (data: any) => {
|
||||||
mutate(data, {
|
mutate(data, {
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
onSave();
|
onSave();
|
@ -17,7 +17,7 @@ export function WebsitesBrowse() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Tabs selectedKey={tab} onSelect={setTab} style={{ marginBottom: 30 }}>
|
<Tabs selectedKey={tab} onSelect={(tab: any) => setTab(tab)} style={{ marginBottom: 30 }}>
|
||||||
<Item key={TABS.myWebsites}>{formatMessage(labels.myWebsites)}</Item>
|
<Item key={TABS.myWebsites}>{formatMessage(labels.myWebsites)}</Item>
|
||||||
<Item key={TABS.teamWebsites}>{formatMessage(labels.teamWebsites)}</Item>
|
<Item key={TABS.teamWebsites}>{formatMessage(labels.teamWebsites)}</Item>
|
||||||
</Tabs>
|
</Tabs>
|
@ -3,7 +3,7 @@ import PageviewsChart from 'components/metrics/PageviewsChart';
|
|||||||
import { useApi, useDateRange, useTimezone, useNavigation } from 'components/hooks';
|
import { useApi, useDateRange, useTimezone, useNavigation } from 'components/hooks';
|
||||||
import { getDateArray } from 'lib/date';
|
import { getDateArray } from 'lib/date';
|
||||||
|
|
||||||
export function WebsiteChart({ websiteId }) {
|
export function WebsiteChart({ websiteId }: { websiteId: string }) {
|
||||||
const [dateRange] = useDateRange(websiteId);
|
const [dateRange] = useDateRange(websiteId);
|
||||||
const { startDate, endDate, unit, modified } = dateRange;
|
const { startDate, endDate, unit, modified } = dateRange;
|
||||||
const [timezone] = useTimezone();
|
const [timezone] = useTimezone();
|
||||||
@ -12,12 +12,12 @@ export function WebsiteChart({ websiteId }) {
|
|||||||
} = useNavigation();
|
} = useNavigation();
|
||||||
const { get, useQuery } = useApi();
|
const { get, useQuery } = useApi();
|
||||||
|
|
||||||
const { data, isLoading } = useQuery(
|
const { data, isLoading } = useQuery({
|
||||||
[
|
queryKey: [
|
||||||
'websites:pageviews',
|
'websites:pageviews',
|
||||||
{ websiteId, modified, url, referrer, os, browser, device, country, region, city, title },
|
{ websiteId, modified, url, referrer, os, browser, device, country, region, city, title },
|
||||||
],
|
],
|
||||||
() =>
|
queryFn: () =>
|
||||||
get(`/websites/${websiteId}/pageviews`, {
|
get(`/websites/${websiteId}/pageviews`, {
|
||||||
startAt: +startDate,
|
startAt: +startDate,
|
||||||
endAt: +endDate,
|
endAt: +endDate,
|
||||||
@ -33,7 +33,7 @@ export function WebsiteChart({ websiteId }) {
|
|||||||
city,
|
city,
|
||||||
title,
|
title,
|
||||||
}),
|
}),
|
||||||
);
|
});
|
||||||
|
|
||||||
const chartData = useMemo(() => {
|
const chartData = useMemo(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
@ -45,7 +45,7 @@ export function WebsiteChart({ websiteId }) {
|
|||||||
return { pageviews: [], sessions: [] };
|
return { pageviews: [], sessions: [] };
|
||||||
}, [data, startDate, endDate, unit]);
|
}, [data, startDate, endDate, unit]);
|
||||||
|
|
||||||
return <PageviewsChart websiteId={websiteId} data={chartData} unit={unit} loading={isLoading} />;
|
return <PageviewsChart data={chartData} unit={unit} isLoading={isLoading} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default WebsiteChart;
|
export default WebsiteChart;
|
@ -8,7 +8,15 @@ import WebsiteHeader from './WebsiteHeader';
|
|||||||
import { WebsiteMetricsBar } from './WebsiteMetricsBar';
|
import { WebsiteMetricsBar } from './WebsiteMetricsBar';
|
||||||
import { useMessages, useLocale } from 'components/hooks';
|
import { useMessages, useLocale } from 'components/hooks';
|
||||||
|
|
||||||
export default function WebsiteChartList({ websites, showCharts, limit }) {
|
export default function WebsiteChartList({
|
||||||
|
websites,
|
||||||
|
showCharts,
|
||||||
|
limit,
|
||||||
|
}: {
|
||||||
|
websites: any[];
|
||||||
|
showCharts?: boolean;
|
||||||
|
limit?: number;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { websiteOrder } = useDashboard();
|
const { websiteOrder } = useDashboard();
|
||||||
const { dir } = useLocale();
|
const { dir } = useLocale();
|
@ -11,7 +11,7 @@ import WebsiteHeader from './WebsiteHeader';
|
|||||||
import WebsiteMetricsBar from './WebsiteMetricsBar';
|
import WebsiteMetricsBar from './WebsiteMetricsBar';
|
||||||
import WebsiteTableView from './WebsiteTableView';
|
import WebsiteTableView from './WebsiteTableView';
|
||||||
|
|
||||||
export default function WebsiteDetails({ websiteId }) {
|
export default function WebsiteDetails({ websiteId }: { websiteId: string }) {
|
||||||
const { data: website, isLoading, error } = useWebsite(websiteId);
|
const { data: website, isLoading, error } = useWebsite(websiteId);
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const showLinks = !pathname.includes('/share/');
|
const showLinks = !pathname.includes('/share/');
|
||||||
@ -27,10 +27,7 @@ export default function WebsiteDetails({ websiteId }) {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WebsiteHeader websiteId={websiteId} showLinks={showLinks} />
|
<WebsiteHeader websiteId={websiteId} showLinks={showLinks} />
|
||||||
<FilterTags
|
<FilterTags params={{ url, referrer, os, browser, device, country, region, city, title }} />
|
||||||
websiteId={websiteId}
|
|
||||||
params={{ url, referrer, os, browser, device, country, region, city, title }}
|
|
||||||
/>
|
|
||||||
<WebsiteMetricsBar websiteId={websiteId} sticky={true} />
|
<WebsiteMetricsBar websiteId={websiteId} sticky={true} />
|
||||||
<WebsiteChart websiteId={websiteId} />
|
<WebsiteChart websiteId={websiteId} />
|
||||||
{!website && <Loading icon="dots" style={{ minHeight: 300 }} />}
|
{!website && <Loading icon="dots" style={{ minHeight: 300 }} />}
|
@ -3,7 +3,13 @@ import PopupForm from 'app/(main)/reports/[id]/PopupForm';
|
|||||||
import FilterSelectForm from 'app/(main)/reports/[id]/FilterSelectForm';
|
import FilterSelectForm from 'app/(main)/reports/[id]/FilterSelectForm';
|
||||||
import { useMessages, useNavigation } from 'components/hooks';
|
import { useMessages, useNavigation } from 'components/hooks';
|
||||||
|
|
||||||
export function WebsiteFilterButton({ websiteId, className }) {
|
export function WebsiteFilterButton({
|
||||||
|
websiteId,
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
websiteId: string;
|
||||||
|
className?: string;
|
||||||
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { makeUrl, router } = useNavigation();
|
const { makeUrl, router } = useNavigation();
|
||||||
|
|
||||||
@ -31,9 +37,9 @@ export function WebsiteFilterButton({ websiteId, className }) {
|
|||||||
<Text>{formatMessage(labels.filter)}</Text>
|
<Text>{formatMessage(labels.filter)}</Text>
|
||||||
</Button>
|
</Button>
|
||||||
<Popup position="bottom" alignment="start">
|
<Popup position="bottom" alignment="start">
|
||||||
{close => {
|
{(close: () => void) => {
|
||||||
return (
|
return (
|
||||||
<PopupForm onClose={close}>
|
<PopupForm>
|
||||||
<FilterSelectForm
|
<FilterSelectForm
|
||||||
websiteId={websiteId}
|
websiteId={websiteId}
|
||||||
items={fieldOptions}
|
items={fieldOptions}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user