import { useQuery } from "@apollo/client/react"; import { ResponsiveLine } from "@nivo/line"; import { useParams } from "react-router-dom"; import styles from "./UserDetail.module.css"; import { GQLError } from "../../components/GQLError"; import { SchemaUser as User, UserDetailDocument, SchemaUserProfile as UserProfile } from "../../types"; import { formatMonth, formatTime } from "../../utils/time"; import { chartTheme, chartTooltipStyle } from "../stats/chartTheme"; const UserDetail = () => { const { userId } = useParams(); const { data, loading, error } = useQuery(UserDetailDocument, { variables: { userId: userId || "" }, skip: !userId }); if (loading) return
Loading...
; if (error) return ; const user = data?.user as User; const profile = user?.profile as UserProfile; const series = (profile?.productOrderStats || []).map(({ productName: id, data }) => ({ id, data: data.map((point, index, points) => ({ x: point.x, y: point.y + (points[index - 1]?.y || 0), })), })); return (

{profile.image && {`${user.firstName}s} {user.firstName}

Stats
  • Saldo: {Number(profile.balance).toLocaleString("no")} kr
  • Siste kjøp: {formatTime(profile.lastPurchaseDate)}
  • Kjøp totalt: {Number(profile.orderSumTotal).toLocaleString("no")} kr

Top 5 måneder
    {profile.topMonths.map((topMonth) => (
  • {formatMonth(topMonth.period)}: {topMonth.count} kjøp på totalt{" "} {topMonth.sum} kr
  • ))}

Kjøp over tid

(
{point.data.xFormatted}
{" "} {String(point.data.yFormatted)} {point.seriesId}
)} />
); }; export default UserDetail;