Separate client & server utility functions

This commit is contained in:
2023-09-05 14:44:41 -05:00
parent 380b950fca
commit ac23bf774a
6 changed files with 39 additions and 13 deletions

22
src/components/Layout.tsx Normal file
View File

@@ -0,0 +1,22 @@
import { FunctionComponent } from 'react';
import { classNames } from '@/utils/client';
export type LayoutProps = {
className?: string;
children: React.ReactNode;
};
const Layout: FunctionComponent<LayoutProps> = ({ children, className }) => {
return (
<div
className={classNames(
'flex text-zinc-200 bg-zinc-900 min-h-screen h-full flex-col justify-center py-12 sm:px-6 lg:px-8',
className
)}
>
{children}
</div>
);
};
export default Layout;

View File

@@ -1,5 +1,5 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { unauthorized } from '@/utils/helpers';
import { unauthorized } from '@/utils/server';
type StatusData = { status: ResponseStatus };

View File

@@ -1,7 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { fetchConfiguration, setConfiguration } from '@/db';
import { Configuration, ConfigurationSchema } from '@/timing';
import { unauthorized } from '@/utils/helpers';
import { unauthorized } from '@/utils/server';
type StatusData = { status: ResponseStatus };

View File

@@ -11,7 +11,8 @@ import {
} from '@/db';
import { localNow } from '@/utils/timezone';
import logger from '@/logger';
import { parseBoolean, unauthorized } from '@/utils/helpers';
import { parseBoolean } from '@/utils/client';
import { unauthorized } from '@/utils/server';
type ResponseData = {
diff: number;

12
src/utils/client.ts Normal file
View File

@@ -0,0 +1,12 @@
export function parseBoolean(
value: string | string[] | undefined | null
): boolean {
if (value == undefined) return false;
if (Array.isArray(value)) return false;
value = value.toLowerCase();
return value === 'true' || value === '1' || value === 'yes';
}
export function classNames(...classes: (string | undefined)[]): string {
return classes.filter(Boolean).join(' ');
}

View File

@@ -13,12 +13,3 @@ export function unauthorized(
}
return false;
}
export function parseBoolean(
value: string | string[] | undefined | null
): boolean {
if (value == undefined) return false;
if (Array.isArray(value)) return false;
value = value.toLowerCase();
return value === 'true' || value === '1' || value === 'yes';
}