added tooling (eslint, typescript and prettier)

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-11-02 12:14:37 +01:00
parent 575b3c23bf
commit 493e1b7650
82 changed files with 1890 additions and 1363 deletions

View File

@@ -1,27 +1,32 @@
import { type IInterval } from "@/types";
import { type IInterval } from '@/types';
export function formatDateInterval(interval: IInterval, date: Date): string {
if (interval === "hour" || interval === "minute") {
return new Intl.DateTimeFormat("en-GB", {
hour: "2-digit",
minute: "2-digit",
if (interval === 'hour' || interval === 'minute') {
return new Intl.DateTimeFormat('en-GB', {
hour: '2-digit',
minute: '2-digit',
}).format(date);
}
if (interval === "month") {
return new Intl.DateTimeFormat("en-GB", { month: "short" }).format(date);
if (interval === 'month') {
return new Intl.DateTimeFormat('en-GB', { month: 'short' }).format(date);
}
if (interval === "day") {
return new Intl.DateTimeFormat("en-GB", { weekday: "short", day: '2-digit', month: '2-digit' }).format(
date,
);
if (interval === 'day') {
return new Intl.DateTimeFormat('en-GB', {
weekday: 'short',
day: '2-digit',
month: '2-digit',
}).format(date);
}
return date.toISOString();
}
export function useFormatDateInterval(interval: IInterval) {
return (date: Date | string) => formatDateInterval(interval, typeof date === "string" ? new Date(date) : date);
}
return (date: Date | string) =>
formatDateInterval(
interval,
typeof date === 'string' ? new Date(date) : date
);
}

View File

@@ -1,7 +1,7 @@
import mappings from '@/mappings.json'
import mappings from '@/mappings.json';
export function useMappings() {
return (val: string) => {
return mappings.find((item) => item.id === val)?.name ?? val
}
}
return mappings.find((item) => item.id === val)?.name ?? val;
};
}

View File

@@ -1,5 +1,6 @@
import { z } from "zod";
import { useQueryParams } from "./useQueryParams";
import { z } from 'zod';
import { useQueryParams } from './useQueryParams';
export function useOrganizationParams() {
return useQueryParams(
@@ -8,6 +9,6 @@ export function useOrganizationParams() {
project: z.string(),
dashboard: z.string(),
profileId: z.string().optional(),
}),
})
);
}
}

View File

@@ -1,7 +1,6 @@
import { useMemo } from "react";
import { useRouter } from "next/router";
import { type z } from "zod";
import { useMemo } from 'react';
import { useRouter } from 'next/router';
import { type z } from 'zod';
export function useQueryParams<Z extends z.ZodTypeAny = z.ZodNever>(zod: Z) {
const router = useRouter();

View File

@@ -1,6 +1,6 @@
import { useQueryClient } from "@tanstack/react-query";
import { useQueryClient } from '@tanstack/react-query';
export function useRefetchActive() {
const client = useQueryClient()
return () => client.refetchQueries({type: 'active'})
}
const client = useQueryClient();
return () => client.refetchQueries({ type: 'active' });
}

View File

@@ -1,5 +1,5 @@
import { useRouter } from "next/router";
import { useEffect, useRef } from "react";
import { useEffect, useRef } from 'react';
import { useRouter } from 'next/router';
export function useRouterBeforeLeave(callback: () => void) {
const router = useRouter();
@@ -8,14 +8,14 @@ export function useRouterBeforeLeave(callback: () => void) {
useEffect(() => {
const handleRouteChange = (url: string) => {
if (prevUrl.current !== url) {
callback()
callback();
}
prevUrl.current = url;
};
router.events.on("routeChangeStart", handleRouteChange);
router.events.on('routeChangeStart', handleRouteChange);
return () => {
router.events.off("routeChangeStart", handleRouteChange);
router.events.off('routeChangeStart', handleRouteChange);
};
}, [router, callback]);
}
}