* init page * init insights frontend * nit * nit * nit * merge * fixed icons * i18n, needs features * Init insights trpc * Using trpc on client * Added events timeline * Seed analytics script * connect ui with trpc * Added and fixed event time lines * WIP popular days and avg time duration event type * added new metric graphs * improved upgrade tip * always show upgrade screen * upgrade tremor.so and select inputs for page * Remove log * Move everything to components and add context * Fix select types using calcom ui one * Adding translations * Add missing translations * Add more translations * min fix * Fixes for date select * Prefer early return and mobile design fixes * Fix style for mobile * Fix data with userId filter from popular events * add user id to average time duration * fix types for select-react * Removed submodules * Delete website * Update yarn.lock * Code organization and type fixes * trpc fixes * Builds are now passing * Relocates server code * Add url state in insights * Update FiltersProvider.tsx * Cleanup * Update embed-iframe.ts * Update FilterType.tsx * Update seed-app-store.config.json * Update index.tsx * Renamed seeder * Update FiltersProvider.tsx * Fix for query params * no wrap on lg screen * Fix shadow borders from tremor components, fix title font * Add ring-gray to match filters * add cursor pointer * copy improvements * blue to black * fixed date select focus * text right for table * Adds missing translation strings * Fix url state for filter type * more layout improvements * more padding improvements * more UI fixes (padding, sizes) requested by ciaran * Apply suggestions from code review * WIP user without team metrics * yarn * Adds loading state for graphs and tables * fix average render when no data * Multiple fixes in insights * Fix most and least booked members querys * More fix for clear filters --------- Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: zomars <[email protected]>
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { LineChart, Title } from "@tremor/react";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { trpc } from "@calcom/trpc";
|
|
|
|
import { useFilterContext } from "../context/provider";
|
|
import { valueFormatter } from "../lib/valueFormatter";
|
|
import { CardInsights } from "./Card";
|
|
import { LoadingInsight } from "./LoadingInsights";
|
|
|
|
export const AverageEventDurationChart = () => {
|
|
const { t } = useLocale();
|
|
const { filter } = useFilterContext();
|
|
const { dateRange, selectedMemberUserId } = filter;
|
|
const [startDate, endDate] = dateRange;
|
|
const { selectedTeamId: teamId, selectedUserId } = filter;
|
|
|
|
const { data, isSuccess, isLoading } = trpc.viewer.insights.averageEventDuration.useQuery({
|
|
startDate: startDate.toISOString(),
|
|
endDate: endDate.toISOString(),
|
|
teamId: teamId ?? undefined,
|
|
memberUserId: selectedMemberUserId ?? undefined,
|
|
userId: selectedUserId ?? undefined,
|
|
});
|
|
|
|
if (isLoading) return <LoadingInsight />;
|
|
|
|
if (!isSuccess || !startDate || !endDate || (!teamId && !selectedUserId)) return null;
|
|
const isNoData = (data && data.length === 0) || data.every((item) => item["Average"] === 0);
|
|
return (
|
|
<CardInsights>
|
|
<Title>{t("average_event_duration")}</Title>
|
|
{isNoData && (
|
|
<div className="flex h-60 text-center">
|
|
<p className="m-auto text-sm font-light">{t("insights_no_data_found_for_filter")}</p>
|
|
</div>
|
|
)}
|
|
{data && data.length > 0 && !isNoData && (
|
|
<LineChart
|
|
className="mt-4 h-80"
|
|
data={data}
|
|
index="Date"
|
|
categories={["Average"]}
|
|
colors={["blue"]}
|
|
valueFormatter={valueFormatter}
|
|
/>
|
|
)}
|
|
</CardInsights>
|
|
);
|
|
};
|