Updated profile menu. Fixed dashboard.

This commit is contained in:
Mike Cao 2024-02-02 21:06:55 -08:00
parent a91b9c9716
commit 400657d59e
12 changed files with 73 additions and 70 deletions

View file

@ -7,39 +7,30 @@ import WebsiteChartList from '../websites/[websiteId]/WebsiteChartList';
import DashboardSettingsButton from 'app/(main)/dashboard/DashboardSettingsButton';
import DashboardEdit from 'app/(main)/dashboard/DashboardEdit';
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
import { useApi } from 'components/hooks';
import { useMessages, useLocale, useTeamContext, useWebsites } from 'components/hooks';
import useDashboard from 'store/dashboard';
import { useMessages, useLocale, useLogin, useFilterQuery } from 'components/hooks';
export function Dashboard() {
const { formatMessage, labels, messages } = useMessages();
const { user } = useLogin();
const { teamId } = useTeamContext();
const { showCharts, editing } = useDashboard();
const { dir } = useLocale();
const { get } = useApi();
const pageSize = 10;
const { query, params, setParams, result } = useFilterQuery({
queryKey: ['dashboard:websites'],
queryFn: (params: any) => {
return get(`/users/${user.id}/websites`, { ...params, includeTeams: true, pageSize });
},
});
const { result, query, params, setParams } = useWebsites({}, { pageSize });
const { page } = params;
const hasData = !!result?.data;
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 />;
}
return (
<>
<section style={{ marginBottom: 60 }}>
<PageHeader title={formatMessage(labels.dashboard)}>
{!editing && hasData && <DashboardSettingsButton />}
</PageHeader>
@ -57,21 +48,25 @@ export function Dashboard() {
)}
{hasData && (
<>
{editing && <DashboardEdit />}
{editing && <DashboardEdit teamId={teamId} />}
{!editing && (
<>
<WebsiteChartList websites={data as any} showCharts={showCharts} limit={pageSize} />
<WebsiteChartList
websites={result?.data as any}
showCharts={showCharts}
limit={pageSize}
/>
<Pager
page={page}
pageSize={pageSize}
count={count}
count={result?.count}
onPageChange={handlePageChange}
/>
</>
)}
</>
)}
</>
</section>
);
}

View file

@ -2,31 +2,30 @@
import { useState, useMemo } from 'react';
import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd';
import classNames from 'classnames';
import { Button } from 'react-basics';
import { Button, Loading } from 'react-basics';
import { firstBy } from 'thenby';
import useDashboard, { saveDashboard } from 'store/dashboard';
import { useMessages } from 'components/hooks';
import { useApi } from 'components/hooks';
import { useMessages, useWebsites } from 'components/hooks';
import styles from './DashboardEdit.module.css';
const dragId = 'dashboard-website-ordering';
const DRAG_ID = 'dashboard-website-ordering';
export function DashboardEdit() {
export function DashboardEdit({ teamId }: { teamId: string }) {
const settings = useDashboard();
const { websiteOrder } = settings;
const { formatMessage, labels } = useMessages();
const [order, setOrder] = useState(websiteOrder || []);
const { get, useQuery } = useApi();
const { data: result } = useQuery({
queryKey: ['websites'],
queryFn: () => get('/websites'),
});
const { data: websites } = result || {};
const {
result,
query: { isLoading },
} = useWebsites({ teamId });
const websites = result?.data;
const ordered = useMemo(() => {
if (websites) {
return websites
.map(website => ({ ...website, order: order.indexOf(website.id) }))
.map((website: { id: any }) => ({ ...website, order: order.indexOf(website.id) }))
.sort(firstBy('order'));
}
return [];
@ -57,6 +56,10 @@ export function DashboardEdit() {
setOrder([]);
}
if (isLoading) {
return <Loading />;
}
return (
<>
<div className={styles.buttons}>
@ -72,7 +75,7 @@ export function DashboardEdit() {
</div>
<div className={styles.dragActive}>
<DragDropContext onDragEnd={handleWebsiteDrag}>
<Droppable droppableId={dragId}>
<Droppable droppableId={DRAG_ID}>
{(provided, snapshot) => (
<div
{...provided.droppableProps}
@ -80,7 +83,7 @@ export function DashboardEdit() {
style={{ marginBottom: snapshot.isDraggingOver ? 260 : null }}
>
{ordered.map(({ id, name, domain }, index) => (
<Draggable key={id} draggableId={`${dragId}-${id}`} index={index}>
<Draggable key={id} draggableId={`${DRAG_ID}-${id}`} index={index}>
{(provided, snapshot) => (
<div
ref={provided.innerRef}

View file

@ -18,5 +18,4 @@
min-height: 0;
height: calc(100vh - 60px);
overflow-y: auto;
padding-bottom: 60px;
}

View file

@ -3,7 +3,7 @@ import { FormRow } from 'react-basics';
import { parseDateRange } from 'lib/date';
import DateFilter from 'components/input/DateFilter';
import WebsiteSelect from 'components/input/WebsiteSelect';
import { useLogin, useMessages, useTeamContext } from 'components/hooks';
import { useMessages, useTeamContext } from 'components/hooks';
import { ReportContext } from './Report';
export interface BaseParametersProps {
@ -21,7 +21,6 @@ export function BaseParameters({
}: BaseParametersProps) {
const { report, updateReport } = useContext(ReportContext);
const { formatMessage, labels } = useMessages();
const { user } = useLogin();
const { teamId } = useTeamContext();
const { parameters } = report || {};
@ -41,12 +40,7 @@ export function BaseParameters({
{showWebsiteSelect && (
<FormRow label={formatMessage(labels.website)}>
{allowWebsiteSelect && (
<WebsiteSelect
userId={user.id}
teamId={teamId}
websiteId={websiteId}
onSelect={handleWebsiteSelect}
/>
<WebsiteSelect teamId={teamId} websiteId={websiteId} onSelect={handleWebsiteSelect} />
)}
</FormRow>
)}

View file

@ -12,7 +12,7 @@ export default function SettingsLayout({ children }) {
const { teamId, renderTeamUrl } = useTeamContext();
const items = [
{
teamId && {
key: 'team',
label: formatMessage(labels.team),
url: renderTeamUrl('/settings/team'),

View file

@ -0,0 +1,3 @@
import Page from 'app/(main)/dashboard/page';
export default Page;