fix: eslint errors
This commit is contained in:
parent
1cfdda4e19
commit
44a95cbf1c
6 changed files with 60 additions and 36 deletions
|
|
@ -24,11 +24,11 @@ export type { Training };
|
|||
|
||||
const root = process.cwd();
|
||||
|
||||
export async function getTrainingFiles() {
|
||||
export function getTrainingFiles() {
|
||||
return fs.readdirSync(path.join(root, 'content', 'training'), 'utf-8');
|
||||
}
|
||||
|
||||
export async function getTrainingBySlug(slug: string, fields: string[] = []) {
|
||||
export function getTrainingBySlug(slug: string) {
|
||||
const source = fs.readFileSync(path.join(root, 'content', 'training', `${slug}.md`), 'utf8');
|
||||
|
||||
const { data, content } = matter(source);
|
||||
|
|
@ -39,21 +39,27 @@ export async function getTrainingBySlug(slug: string, fields: string[] = []) {
|
|||
};
|
||||
}
|
||||
|
||||
export async function getAllTrainingsWithMetadata(): Promise<Training[]> {
|
||||
export function getAllTrainingsWithMetadata(): Training[] {
|
||||
const files = fs.readdirSync(path.join(root, 'content', 'training'))
|
||||
|
||||
// @ts-ignore
|
||||
return files.reduce((allTrainings, fileName) => {
|
||||
const source = fs.readFileSync(path.join(root, 'content', 'training', fileName), 'utf8');
|
||||
const { data, content } = matter(source);
|
||||
const trainings = [] as Training[];
|
||||
|
||||
return [
|
||||
{
|
||||
metadata: data,
|
||||
content: content,
|
||||
},
|
||||
...allTrainings,
|
||||
]
|
||||
}, [])
|
||||
for (const fileName of files) {
|
||||
const source = fs.readFileSync(path.join(root, 'content', 'training', fileName), 'utf8');
|
||||
const { data: metadata, content: content } = matter(source);
|
||||
trainings.push({metadata, content} as Training);
|
||||
}
|
||||
|
||||
return trainings;
|
||||
|
||||
// return files.reduce((allTrainings, fileName) => {
|
||||
// const source = fs.readFileSync(path.join(root, 'content', 'training', fileName), 'utf8');
|
||||
// const training = matter(source);
|
||||
|
||||
// return [
|
||||
// training,
|
||||
// ...allTrainings,
|
||||
// ]
|
||||
// }, [])
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
export function formatCurrency(price: number | bigint, locale: string = 'en-US', currency: string = 'CZK'): string {
|
||||
export function formatCurrency(price: number | bigint, locale ='en-US', currency = 'CZK'): string {
|
||||
const currencyFormatter = new Intl.NumberFormat(locale, {
|
||||
style: 'currency',
|
||||
currency: currency,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
import clsx from "clsx";
|
||||
import Link from "next/link";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
function classNames(...classes: any) {
|
||||
return classes.filter(Boolean).join(' ')
|
||||
}
|
||||
import { type ReactNode } from "react";
|
||||
|
||||
const baseStyles = {
|
||||
solid:
|
||||
|
|
@ -58,7 +55,7 @@ export function Button({
|
|||
throw new Error("Outline buttons cannot be amber");
|
||||
}
|
||||
|
||||
className = classNames(
|
||||
className = clsx(
|
||||
baseStyles[variant],
|
||||
variantStyles[variant][color],
|
||||
sizeStyles[size],
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import clsx from "clsx";
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
import { Fragment, useState } from 'react';
|
||||
|
|
@ -15,10 +16,6 @@ const navigation = [
|
|||
{ name: 'Trainings', href: '/trainings', icon: AcademicCapIcon },
|
||||
]
|
||||
|
||||
function classNames(...classes: any) {
|
||||
return classes.filter(Boolean).join(' ')
|
||||
}
|
||||
|
||||
export function Sidebar() {
|
||||
const [sidebarOpen, setSidebarOpen] = useState(false)
|
||||
const router = useRouter();
|
||||
|
|
@ -79,7 +76,7 @@ export function Sidebar() {
|
|||
<li key={item.name}>
|
||||
<Link
|
||||
href={item.href}
|
||||
className={classNames(
|
||||
className={clsx(
|
||||
router.pathname === item.href
|
||||
? 'bg-gray-800 text-white'
|
||||
: 'text-gray-400 hover:text-white hover:bg-gray-800',
|
||||
|
|
@ -117,7 +114,7 @@ export function Sidebar() {
|
|||
<li key={item.name}>
|
||||
<Link
|
||||
href={item.href}
|
||||
className={classNames(
|
||||
className={clsx(
|
||||
router.pathname === item.href
|
||||
? 'bg-gray-800 text-white'
|
||||
: 'text-gray-400 hover:text-white hover:bg-gray-800',
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import ReactMarkdown from 'react-markdown';
|
||||
import { GetServerSideProps } from "next";
|
||||
import { type GetServerSideProps } from "next";
|
||||
import Head from "next/head";
|
||||
import Link from "next/link";
|
||||
|
||||
|
|
@ -7,9 +7,21 @@ import { formatCurrency } from "~/lib/currency/formatter";
|
|||
|
||||
import { getServerAuthSession } from "~/server/auth";
|
||||
import { prisma } from "~/server/db";
|
||||
import { Training } from "lib/content/training";
|
||||
import { Layout } from "~/components/Layout";
|
||||
// import { Button } from "~/components/Button";
|
||||
|
||||
type Training = {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
days: number;
|
||||
draft: boolean;
|
||||
priceOpen: number;
|
||||
priceCorporate: number;
|
||||
logoURL: string;
|
||||
svgIconURL: string;
|
||||
repositoryURL: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const session = await getServerAuthSession(ctx);
|
||||
|
|
@ -23,7 +35,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
|||
return { props: { training: training, session } };
|
||||
}
|
||||
|
||||
function Detail({ training }: { training: any }) {
|
||||
function Detail({ training }: { training: Training }) {
|
||||
return (
|
||||
<div className="overflow-hidden bg-white shadow ring-1 ring-black ring-opacity-5 sm:rounded-lg">
|
||||
<div className="px-4 py-6 sm:px-6">
|
||||
|
|
@ -88,7 +100,6 @@ export default function Training({ training }: { training: Training }) {
|
|||
<title>Training | MaresHQ backoffice</title>
|
||||
</Head>
|
||||
<Layout>
|
||||
{/* { JSON.stringify(trainings) } */}
|
||||
<Detail training={training} />
|
||||
</Layout>
|
||||
</>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { GetServerSideProps } from "next";
|
||||
import { type GetServerSideProps } from "next";
|
||||
import Head from "next/head";
|
||||
import Link from "next/link";
|
||||
|
||||
|
|
@ -10,6 +10,18 @@ import { Training } from "lib/content/training";
|
|||
import { Layout } from "~/components/Layout";
|
||||
import { Button } from "~/components/Button";
|
||||
|
||||
type Trainings = [
|
||||
{
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
days: number;
|
||||
draft: boolean;
|
||||
priceOpen: number;
|
||||
priceCorporate: number;
|
||||
}
|
||||
];
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const session = await getServerAuthSession(ctx);
|
||||
|
||||
|
|
@ -26,10 +38,11 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
|||
priceCorporate: true,
|
||||
}
|
||||
});
|
||||
|
||||
return { props: { trainings: trainings, session } };
|
||||
}
|
||||
|
||||
function Table({trainings}: { trainings: Training[] }) {
|
||||
function Table({trainings}: { trainings: Trainings }) {
|
||||
return (
|
||||
<div className="px-4 sm:px-6 lg:px-8">
|
||||
<div className="sm:flex sm:items-center">
|
||||
|
|
@ -105,7 +118,7 @@ function Table({trainings}: { trainings: Training[] }) {
|
|||
)
|
||||
}
|
||||
|
||||
export default function Training({ trainings }: { trainings: Training[] }) {
|
||||
export default function Training({ trainings }: { trainings: Trainings }) {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
|
|
|
|||
Reference in a new issue