OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
minor fixes
Carl-Gerhard Lindesvärdc8c86d8c23fa
diff --git a/README.md b/README.mdindex a19cc5451..d1789cb73 100644--- a/README.md+++ b/README.md@@ -4,7 +4,11 @@# mixan-Mixan is a simple analytics tool for logging events on web and react-native. My goal is to make a minimal mixpanel copy with the most basic features (for now).+Mixan is a simple analytics tool for logging events on web and react-native. My goal is to make a minimal mixpanel copy with the most basic features (for now).++* Easy to use+* Own your own data+* GDPR friendly## Whats left?diff --git a/apps/web/src/components/report/ReportDateRange.tsx b/apps/web/src/components/report/ReportDateRange.tsxindex fc0380422..2904f803f 100644--- a/apps/web/src/components/report/ReportDateRange.tsx+++ b/apps/web/src/components/report/ReportDateRange.tsx@@ -3,6 +3,8 @@ import { RadioGroup, RadioGroupItem } from "../ui/radio-group";import { changeDateRanges, changeInterval } from "./reportSlice";import { Combobox } from "../ui/combobox";import { type IInterval } from "@/types";+import { timeRanges } from "@/utils/constants";+import { entries } from "@/utils/object";export function ReportDateRange() {const dispatch = useDispatch();@@ -12,62 +14,17 @@ export function ReportDateRange() {return (<><RadioGroup>- <RadioGroupItem- onClick={() => {- dispatch(changeDateRanges("today"));- }}- >- Today- </RadioGroupItem>- <RadioGroupItem- onClick={() => {- dispatch(changeDateRanges(1));- }}- >- 24 hours- </RadioGroupItem>- <RadioGroupItem- onClick={() => {- dispatch(changeDateRanges(7));- }}- >- 7 days- </RadioGroupItem>- <RadioGroupItem- onClick={() => {- dispatch(changeDateRanges(14));- }}- >- 14 days- </RadioGroupItem>- <RadioGroupItem- onClick={() => {- dispatch(changeDateRanges(30));- }}- >- 1 month- </RadioGroupItem>- <RadioGroupItem- onClick={() => {- dispatch(changeDateRanges(90));- }}- >- 3 month- </RadioGroupItem>- <RadioGroupItem- onClick={() => {- dispatch(changeDateRanges(180));- }}- >- 6 month- </RadioGroupItem>- <RadioGroupItem- onClick={() => {- dispatch(changeDateRanges(356));- }}- >- 1 year- </RadioGroupItem>+ {entries(timeRanges).map(([range, title]) => (+ <RadioGroupItem+ key={range}+ // active={range === interval}+ onClick={() => {+ dispatch(changeDateRanges(range));+ }}+ >+ {title}+ </RadioGroupItem>+ ))}</RadioGroup>{chartType === "linear" && (<div className="w-full max-w-[200px]">diff --git a/apps/web/src/components/report/sidebar/ReportSaveButton.tsx b/apps/web/src/components/report/sidebar/ReportSaveButton.tsxindex c7cbdadac..022fe42e3 100644--- a/apps/web/src/components/report/sidebar/ReportSaveButton.tsx+++ b/apps/web/src/components/report/sidebar/ReportSaveButton.tsx@@ -1,16 +1,25 @@import { Button } from "@/components/ui/button";import { useReportId } from "../hooks/useReportId";-import { api } from "@/utils/api";+import { api, handleError } from "@/utils/api";import { useSelector } from "@/redux";import { pushModal } from "@/modals";+import { toast } from "@/components/ui/use-toast";export function ReportSaveButton() {const { reportId } = useReportId();- const update = api.report.update.useMutation();+ const update = api.report.update.useMutation({+ onSuccess() {+ toast({+ title: "Success",+ description: "Report updated.",+ });+ },+ onError: handleError+ });const report = useSelector((state) => state.report);if (reportId) {- return <Button onClick={() => {+ return <Button loading={update.isLoading} onClick={() => {update.mutate({reportId,report,diff --git a/apps/web/src/components/ui/button.tsx b/apps/web/src/components/ui/button.tsxindex ad9de739d..047d5354d 100644--- a/apps/web/src/components/ui/button.tsx+++ b/apps/web/src/components/ui/button.tsx@@ -3,6 +3,7 @@ import { Slot } from "@radix-ui/react-slot";import { cva, type VariantProps } from "class-variance-authority";import { cn } from "@/utils/cn";+import { Loader2 } from "lucide-react";const buttonVariants = cva("inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",@@ -37,18 +38,24 @@ interface ButtonPropsextends React.ButtonHTMLAttributes<HTMLButtonElement>,VariantProps<typeof buttonVariants> {asChild?: boolean;+ loading?: boolean;}const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(- ({ className, variant, size, asChild = false, ...props }, ref) => {+ (+ { className, variant, size, asChild = false, children, loading, disabled, ...props },+ ref,+ ) => {const Comp = asChild ? Slot : "button";return (- // @ts-expect-error<CompclassName={cn(buttonVariants({ variant, size, className }))}ref={ref}+ disabled={loading ?? disabled}{...props}- />+ >+ {loading ? <Loader2 className="animate-spin" /> : <>{children}</>}+ </Comp>);},);diff --git a/apps/web/src/components/ui/radio-group.tsx b/apps/web/src/components/ui/radio-group.tsxindex 3f7b7ead9..2409a267a 100644--- a/apps/web/src/components/ui/radio-group.tsx+++ b/apps/web/src/components/ui/radio-group.tsx@@ -3,7 +3,9 @@ import * as React from "react"import { cn } from "@/utils/cn"export type RadioGroupProps = React.InputHTMLAttributes<HTMLDivElement>-export type RadioGroupItemProps = React.InputHTMLAttributes<HTMLButtonElement>+export type RadioGroupItemProps = React.InputHTMLAttributes<HTMLButtonElement> & {+ active?: boolean+}const RadioGroup = React.forwardRef<HTMLDivElement, RadioGroupProps>(({ className, type, ...props }, ref) => {@@ -20,9 +22,9 @@ const RadioGroup = React.forwardRef<HTMLDivElement, RadioGroupProps>(})-const RadioGroupItem = React.forwardRef<HTMLButtonElement, RadioGroupItemProps>(({className, ...props}, ref) => {+const RadioGroupItem = React.forwardRef<HTMLButtonElement, RadioGroupItemProps>(({className, active, ...props}, ref) => {return (- <button {...props} className={cn('flex-1 px-3 whitespace-nowrap leading-none hover:bg-slate-100 transition-colors font-medium', className)} type="button" ref={ref} />+ <button {...props} className={cn('flex-1 px-3 whitespace-nowrap leading-none hover:bg-slate-100 transition-colors font-medium', className, active && 'bg-slate-100')} type="button" ref={ref} />)})diff --git a/apps/web/src/modals/SaveReport.tsx b/apps/web/src/modals/SaveReport.tsxindex 1edfe61cc..00e7c427d 100644--- a/apps/web/src/modals/SaveReport.tsx+++ b/apps/web/src/modals/SaveReport.tsx@@ -13,6 +13,7 @@ import { type IChartInput } from "@/types";import { Label } from "@/components/ui/label";import { Combobox } from "@/components/ui/combobox";import { useOrganizationParams } from "@/hooks/useOrganizationParams";+import { useRouter } from "next/router";type SaveReportProps = {report: IChartInput;@@ -28,17 +29,19 @@ const validator = z.object({type IForm = z.infer<typeof validator>;export default function SaveReport({ report }: SaveReportProps) {+ const router = useRouter()const { organization } = useOrganizationParams();const refetch = useRefetchActive();const save = api.report.save.useMutation({onError: handleError,- onSuccess() {+ onSuccess(res) {toast({title: "Success",description: "Report saved.",});popModal();refetch();+ router.push(`/${organization}/reports/${res.id}`)},});diff --git a/apps/web/src/server/api/routers/report.ts b/apps/web/src/server/api/routers/report.tsindex 594a7e405..e788af785 100644--- a/apps/web/src/server/api/routers/report.ts+++ b/apps/web/src/server/api/routers/report.ts@@ -106,6 +106,7 @@ export const reportRouter = createTRPCRouter({range: dateDifferanceInDays(new Date(report.endDate), new Date(report.startDate)),},});+}),update: protectedProcedure.input(diff --git a/apps/web/src/utils/constants.ts b/apps/web/src/utils/constants.tsindex 53a7ab565..26af4d75c 100644--- a/apps/web/src/utils/constants.ts+++ b/apps/web/src/utils/constants.ts@@ -19,4 +19,15 @@ export const intervals = {month: "Month",};-export const alphabetIds = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"] as const;\ No newline at end of file+export const alphabetIds = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"] as const;++export const timeRanges = {+ 'today': 'Today',+ 1: '24 hours',+ 7: '7 days',+ 14: '14 days',+ 30: '30 days',+ 90: '3 months',+ 180: '6 months',+ 365: '1 year',+}\ No newline at end of filediff --git a/apps/web/src/utils/object.ts b/apps/web/src/utils/object.tsindex e90efb750..b5af96488 100644--- a/apps/web/src/utils/object.ts+++ b/apps/web/src/utils/object.ts@@ -1,16 +1,24 @@--export function toDots(obj: Record<string, unknown>, path = ''): Record<string, number | string | boolean> {+export function toDots(+ obj: Record<string, unknown>,+ path = "",+): Record<string, number | string | boolean> {return Object.entries(obj).reduce((acc, [key, value]) => {- if(typeof value === 'object' && value !== null) {+ if (typeof value === "object" && value !== null) {return {...acc,- ...toDots(value as Record<string, unknown>, `${path}${key}.`)- }+ ...toDots(value as Record<string, unknown>, `${path}${key}.`),+ };}return {...acc,[`${path}${key}`]: value,- }- }, {})-}\ No newline at end of file+ };+ }, {});+}++export function entries<K extends string | number | symbol, V>(+ obj: Record<K, V>,+): [K, V][] {+ return Object.entries(obj) as [K, V][];+}