minor fixes

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-10-28 21:57:43 +02:00
parent aa2939f302
commit c8c86d8c23
9 changed files with 78 additions and 76 deletions

View File

@@ -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?

View File

@@ -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]">

View File

@@ -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,

View File

@@ -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 ButtonProps
extends 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
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
disabled={loading ?? disabled}
{...props}
/>
>
{loading ? <Loader2 className="animate-spin" /> : <>{children}</>}
</Comp>
);
},
);

View File

@@ -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} />
)
})

View File

@@ -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}`)
},
});

View File

@@ -106,6 +106,7 @@ export const reportRouter = createTRPCRouter({
range: dateDifferanceInDays(new Date(report.endDate), new Date(report.startDate)),
},
});
}),
update: protectedProcedure
.input(

View File

@@ -19,4 +19,15 @@ export const intervals = {
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',
}

View File

@@ -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,
}
}, {})
}
};
}, {});
}
export function entries<K extends string | number | symbol, V>(
obj: Record<K, V>,
): [K, V][] {
return Object.entries(obj) as [K, V][];
}