minor fixes
This commit is contained in:
@@ -4,7 +4,11 @@
|
|||||||
|
|
||||||
# mixan
|
# 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?
|
## Whats left?
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { RadioGroup, RadioGroupItem } from "../ui/radio-group";
|
|||||||
import { changeDateRanges, changeInterval } from "./reportSlice";
|
import { changeDateRanges, changeInterval } from "./reportSlice";
|
||||||
import { Combobox } from "../ui/combobox";
|
import { Combobox } from "../ui/combobox";
|
||||||
import { type IInterval } from "@/types";
|
import { type IInterval } from "@/types";
|
||||||
|
import { timeRanges } from "@/utils/constants";
|
||||||
|
import { entries } from "@/utils/object";
|
||||||
|
|
||||||
export function ReportDateRange() {
|
export function ReportDateRange() {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -12,62 +14,17 @@ export function ReportDateRange() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<RadioGroup>
|
<RadioGroup>
|
||||||
<RadioGroupItem
|
{entries(timeRanges).map(([range, title]) => (
|
||||||
onClick={() => {
|
<RadioGroupItem
|
||||||
dispatch(changeDateRanges("today"));
|
key={range}
|
||||||
}}
|
// active={range === interval}
|
||||||
>
|
onClick={() => {
|
||||||
Today
|
dispatch(changeDateRanges(range));
|
||||||
</RadioGroupItem>
|
}}
|
||||||
<RadioGroupItem
|
>
|
||||||
onClick={() => {
|
{title}
|
||||||
dispatch(changeDateRanges(1));
|
</RadioGroupItem>
|
||||||
}}
|
))}
|
||||||
>
|
|
||||||
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>
|
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
{chartType === "linear" && (
|
{chartType === "linear" && (
|
||||||
<div className="w-full max-w-[200px]">
|
<div className="w-full max-w-[200px]">
|
||||||
|
|||||||
@@ -1,16 +1,25 @@
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { useReportId } from "../hooks/useReportId";
|
import { useReportId } from "../hooks/useReportId";
|
||||||
import { api } from "@/utils/api";
|
import { api, handleError } from "@/utils/api";
|
||||||
import { useSelector } from "@/redux";
|
import { useSelector } from "@/redux";
|
||||||
import { pushModal } from "@/modals";
|
import { pushModal } from "@/modals";
|
||||||
|
import { toast } from "@/components/ui/use-toast";
|
||||||
|
|
||||||
export function ReportSaveButton() {
|
export function ReportSaveButton() {
|
||||||
const { reportId } = useReportId();
|
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);
|
const report = useSelector((state) => state.report);
|
||||||
|
|
||||||
if (reportId) {
|
if (reportId) {
|
||||||
return <Button onClick={() => {
|
return <Button loading={update.isLoading} onClick={() => {
|
||||||
update.mutate({
|
update.mutate({
|
||||||
reportId,
|
reportId,
|
||||||
report,
|
report,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Slot } from "@radix-ui/react-slot";
|
|||||||
import { cva, type VariantProps } from "class-variance-authority";
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
import { cn } from "@/utils/cn";
|
import { cn } from "@/utils/cn";
|
||||||
|
import { Loader2 } from "lucide-react";
|
||||||
|
|
||||||
const buttonVariants = cva(
|
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",
|
"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 ButtonProps
|
|||||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||||
VariantProps<typeof buttonVariants> {
|
VariantProps<typeof buttonVariants> {
|
||||||
asChild?: boolean;
|
asChild?: boolean;
|
||||||
|
loading?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
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";
|
const Comp = asChild ? Slot : "button";
|
||||||
return (
|
return (
|
||||||
// @ts-expect-error
|
|
||||||
<Comp
|
<Comp
|
||||||
className={cn(buttonVariants({ variant, size, className }))}
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
|
disabled={loading ?? disabled}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
>
|
||||||
|
{loading ? <Loader2 className="animate-spin" /> : <>{children}</>}
|
||||||
|
</Comp>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ import * as React from "react"
|
|||||||
import { cn } from "@/utils/cn"
|
import { cn } from "@/utils/cn"
|
||||||
|
|
||||||
export type RadioGroupProps = React.InputHTMLAttributes<HTMLDivElement>
|
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>(
|
const RadioGroup = React.forwardRef<HTMLDivElement, RadioGroupProps>(
|
||||||
({ className, type, ...props }, ref) => {
|
({ 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 (
|
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} />
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { type IChartInput } from "@/types";
|
|||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Combobox } from "@/components/ui/combobox";
|
import { Combobox } from "@/components/ui/combobox";
|
||||||
import { useOrganizationParams } from "@/hooks/useOrganizationParams";
|
import { useOrganizationParams } from "@/hooks/useOrganizationParams";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
type SaveReportProps = {
|
type SaveReportProps = {
|
||||||
report: IChartInput;
|
report: IChartInput;
|
||||||
@@ -28,17 +29,19 @@ const validator = z.object({
|
|||||||
type IForm = z.infer<typeof validator>;
|
type IForm = z.infer<typeof validator>;
|
||||||
|
|
||||||
export default function SaveReport({ report }: SaveReportProps) {
|
export default function SaveReport({ report }: SaveReportProps) {
|
||||||
|
const router = useRouter()
|
||||||
const { organization } = useOrganizationParams();
|
const { organization } = useOrganizationParams();
|
||||||
const refetch = useRefetchActive();
|
const refetch = useRefetchActive();
|
||||||
const save = api.report.save.useMutation({
|
const save = api.report.save.useMutation({
|
||||||
onError: handleError,
|
onError: handleError,
|
||||||
onSuccess() {
|
onSuccess(res) {
|
||||||
toast({
|
toast({
|
||||||
title: "Success",
|
title: "Success",
|
||||||
description: "Report saved.",
|
description: "Report saved.",
|
||||||
});
|
});
|
||||||
popModal();
|
popModal();
|
||||||
refetch();
|
refetch();
|
||||||
|
router.push(`/${organization}/reports/${res.id}`)
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ export const reportRouter = createTRPCRouter({
|
|||||||
range: dateDifferanceInDays(new Date(report.endDate), new Date(report.startDate)),
|
range: dateDifferanceInDays(new Date(report.endDate), new Date(report.startDate)),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
}),
|
}),
|
||||||
update: protectedProcedure
|
update: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
|
|||||||
@@ -19,4 +19,15 @@ export const intervals = {
|
|||||||
month: "Month",
|
month: "Month",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const alphabetIds = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"] as const;
|
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',
|
||||||
|
}
|
||||||
@@ -1,16 +1,24 @@
|
|||||||
|
export function toDots(
|
||||||
export function toDots(obj: Record<string, unknown>, path = ''): Record<string, number | string | boolean> {
|
obj: Record<string, unknown>,
|
||||||
|
path = "",
|
||||||
|
): Record<string, number | string | boolean> {
|
||||||
return Object.entries(obj).reduce((acc, [key, value]) => {
|
return Object.entries(obj).reduce((acc, [key, value]) => {
|
||||||
if(typeof value === 'object' && value !== null) {
|
if (typeof value === "object" && value !== null) {
|
||||||
return {
|
return {
|
||||||
...acc,
|
...acc,
|
||||||
...toDots(value as Record<string, unknown>, `${path}${key}.`)
|
...toDots(value as Record<string, unknown>, `${path}${key}.`),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...acc,
|
...acc,
|
||||||
[`${path}${key}`]: value,
|
[`${path}${key}`]: value,
|
||||||
}
|
};
|
||||||
}, {})
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function entries<K extends string | number | symbol, V>(
|
||||||
|
obj: Record<K, V>,
|
||||||
|
): [K, V][] {
|
||||||
|
return Object.entries(obj) as [K, V][];
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user