added tooling (eslint, typescript and prettier)
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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' });
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user