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();
|
const root = process.cwd();
|
||||||
|
|
||||||
export async function getTrainingFiles() {
|
export function getTrainingFiles() {
|
||||||
return fs.readdirSync(path.join(root, 'content', 'training'), 'utf-8');
|
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 source = fs.readFileSync(path.join(root, 'content', 'training', `${slug}.md`), 'utf8');
|
||||||
|
|
||||||
const { data, content } = matter(source);
|
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'))
|
const files = fs.readdirSync(path.join(root, 'content', 'training'))
|
||||||
|
|
||||||
// @ts-ignore
|
const trainings = [] as Training[];
|
||||||
return files.reduce((allTrainings, fileName) => {
|
|
||||||
const source = fs.readFileSync(path.join(root, 'content', 'training', fileName), 'utf8');
|
|
||||||
const { data, content } = matter(source);
|
|
||||||
|
|
||||||
return [
|
for (const fileName of files) {
|
||||||
{
|
const source = fs.readFileSync(path.join(root, 'content', 'training', fileName), 'utf8');
|
||||||
metadata: data,
|
const { data: metadata, content: content } = matter(source);
|
||||||
content: content,
|
trainings.push({metadata, content} as Training);
|
||||||
},
|
}
|
||||||
...allTrainings,
|
|
||||||
]
|
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, {
|
const currencyFormatter = new Intl.NumberFormat(locale, {
|
||||||
style: 'currency',
|
style: 'currency',
|
||||||
currency: currency,
|
currency: currency,
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
|
import clsx from "clsx";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { ReactNode } from "react";
|
import { type ReactNode } from "react";
|
||||||
|
|
||||||
function classNames(...classes: any) {
|
|
||||||
return classes.filter(Boolean).join(' ')
|
|
||||||
}
|
|
||||||
|
|
||||||
const baseStyles = {
|
const baseStyles = {
|
||||||
solid:
|
solid:
|
||||||
|
|
@ -58,7 +55,7 @@ export function Button({
|
||||||
throw new Error("Outline buttons cannot be amber");
|
throw new Error("Outline buttons cannot be amber");
|
||||||
}
|
}
|
||||||
|
|
||||||
className = classNames(
|
className = clsx(
|
||||||
baseStyles[variant],
|
baseStyles[variant],
|
||||||
variantStyles[variant][color],
|
variantStyles[variant][color],
|
||||||
sizeStyles[size],
|
sizeStyles[size],
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import clsx from "clsx";
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { Fragment, useState } from 'react';
|
import { Fragment, useState } from 'react';
|
||||||
|
|
@ -15,10 +16,6 @@ const navigation = [
|
||||||
{ name: 'Trainings', href: '/trainings', icon: AcademicCapIcon },
|
{ name: 'Trainings', href: '/trainings', icon: AcademicCapIcon },
|
||||||
]
|
]
|
||||||
|
|
||||||
function classNames(...classes: any) {
|
|
||||||
return classes.filter(Boolean).join(' ')
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Sidebar() {
|
export function Sidebar() {
|
||||||
const [sidebarOpen, setSidebarOpen] = useState(false)
|
const [sidebarOpen, setSidebarOpen] = useState(false)
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -79,7 +76,7 @@ export function Sidebar() {
|
||||||
<li key={item.name}>
|
<li key={item.name}>
|
||||||
<Link
|
<Link
|
||||||
href={item.href}
|
href={item.href}
|
||||||
className={classNames(
|
className={clsx(
|
||||||
router.pathname === item.href
|
router.pathname === item.href
|
||||||
? 'bg-gray-800 text-white'
|
? 'bg-gray-800 text-white'
|
||||||
: 'text-gray-400 hover:text-white hover:bg-gray-800',
|
: 'text-gray-400 hover:text-white hover:bg-gray-800',
|
||||||
|
|
@ -117,7 +114,7 @@ export function Sidebar() {
|
||||||
<li key={item.name}>
|
<li key={item.name}>
|
||||||
<Link
|
<Link
|
||||||
href={item.href}
|
href={item.href}
|
||||||
className={classNames(
|
className={clsx(
|
||||||
router.pathname === item.href
|
router.pathname === item.href
|
||||||
? 'bg-gray-800 text-white'
|
? 'bg-gray-800 text-white'
|
||||||
: 'text-gray-400 hover:text-white hover:bg-gray-800',
|
: 'text-gray-400 hover:text-white hover:bg-gray-800',
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import ReactMarkdown from 'react-markdown';
|
import ReactMarkdown from 'react-markdown';
|
||||||
import { GetServerSideProps } from "next";
|
import { type GetServerSideProps } from "next";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
|
|
@ -7,9 +7,21 @@ import { formatCurrency } from "~/lib/currency/formatter";
|
||||||
|
|
||||||
import { getServerAuthSession } from "~/server/auth";
|
import { getServerAuthSession } from "~/server/auth";
|
||||||
import { prisma } from "~/server/db";
|
import { prisma } from "~/server/db";
|
||||||
import { Training } from "lib/content/training";
|
|
||||||
import { Layout } from "~/components/Layout";
|
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) => {
|
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||||
const session = await getServerAuthSession(ctx);
|
const session = await getServerAuthSession(ctx);
|
||||||
|
|
@ -23,7 +35,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||||
return { props: { training: training, session } };
|
return { props: { training: training, session } };
|
||||||
}
|
}
|
||||||
|
|
||||||
function Detail({ training }: { training: any }) {
|
function Detail({ training }: { training: Training }) {
|
||||||
return (
|
return (
|
||||||
<div className="overflow-hidden bg-white shadow ring-1 ring-black ring-opacity-5 sm:rounded-lg">
|
<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">
|
<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>
|
<title>Training | MaresHQ backoffice</title>
|
||||||
</Head>
|
</Head>
|
||||||
<Layout>
|
<Layout>
|
||||||
{/* { JSON.stringify(trainings) } */}
|
|
||||||
<Detail training={training} />
|
<Detail training={training} />
|
||||||
</Layout>
|
</Layout>
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { GetServerSideProps } from "next";
|
import { type GetServerSideProps } from "next";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
|
|
@ -10,6 +10,18 @@ import { Training } from "lib/content/training";
|
||||||
import { Layout } from "~/components/Layout";
|
import { Layout } from "~/components/Layout";
|
||||||
import { Button } from "~/components/Button";
|
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) => {
|
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||||
const session = await getServerAuthSession(ctx);
|
const session = await getServerAuthSession(ctx);
|
||||||
|
|
||||||
|
|
@ -26,10 +38,11 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||||
priceCorporate: true,
|
priceCorporate: true,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return { props: { trainings: trainings, session } };
|
return { props: { trainings: trainings, session } };
|
||||||
}
|
}
|
||||||
|
|
||||||
function Table({trainings}: { trainings: Training[] }) {
|
function Table({trainings}: { trainings: Trainings }) {
|
||||||
return (
|
return (
|
||||||
<div className="px-4 sm:px-6 lg:px-8">
|
<div className="px-4 sm:px-6 lg:px-8">
|
||||||
<div className="sm:flex sm:items-center">
|
<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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
|
|
|
||||||
Reference in a new issue