Skip to content

Commit

Permalink
fix: lint e format
Browse files Browse the repository at this point in the history
  • Loading branch information
ErickCReis committed Apr 29, 2024
1 parent b0ae793 commit 9513416
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 73 deletions.
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/_components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Link from "next/link";
import { auth, signIn, signOut } from "@acme/auth";
import { Button } from "@acme/ui/button";

export async function Header() {
export function Header() {
return (
<div className="flex items-end justify-between py-4">
<Link
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { GET, POST } from "@acme/auth";

export const runtime = "edge";
export const preferredRegion = ["iad1"]
export const preferredRegion = ["iad1"];
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/api/trpc/[trpc]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { appRouter, createTRPCContext } from "@acme/api";
import { auth } from "@acme/auth";

export const runtime = "edge";
export const preferredRegion = ["iad1"]
export const preferredRegion = ["iad1"];

/**
* Configure basic CORS headers
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { TRPCReactProvider } from "~/trpc/react";

import "~/app/globals.css";

import { env } from "~/env.mjs";
import { env } from "~/env";
import { Header } from "./_components/header";

export const runtime = "edge";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export default async function Page({

const history = await api.timeRecord.history({ teamId, userId });

return <UserInfo teamId={teamId} teamMember={teamMember} history={history} />;
return <UserInfo teamMember={teamMember} history={history} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const isAllowedCsvHeader = (header: unknown): header is AllowedCsvHeaders =>
allowedCsvHeaders.includes(header as AllowedCsvHeaders);

export function Import({ teamId }: { teamId: string }) {
const { back } = useRouter();
const router = useRouter();
const [file, setFile] = useState<File>();
const [array, setArray] = useState<
Record<AllowedCsvHeaders, Dayjs | undefined>[]
Expand All @@ -34,7 +34,7 @@ export function Import({ teamId }: { teamId: string }) {

const { mutate } = api.timeRecord.batch.useMutation({
onSuccess: () => {
back();
router.back();
},
});

Expand Down Expand Up @@ -89,7 +89,6 @@ export function Import({ teamId }: { teamId: string }) {

object[header] = date;
} else {
if (!date) return object;
const [hour, minute] = value.split(":");
if (!hour || !minute) {
object[header] = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useMemo } from "react";
import Link from "next/link";
import { CalendarIcon, ChevronLeft, ChevronRight, FileUp } from "lucide-react";

import { RouterOutputs } from "@acme/api";
import type { RouterOutputs } from "@acme/api";
import { cn } from "@acme/ui";
import { Button } from "@acme/ui/button";
import { Calendar } from "@acme/ui/calendar";
Expand All @@ -19,9 +19,10 @@ import {
} from "@acme/ui/tooltip";
import { CreateTimeRecordSchema } from "@acme/validators";

import type { Dayjs } from "~/utils/dayjs";
import { useConfirmClick } from "~/hooks/use-confirm-click";
import { api } from "~/trpc/react";
import dayjs, { Dayjs, displayTime } from "~/utils/dayjs";
import dayjs, { displayTime } from "~/utils/dayjs";
import { Import } from "./_components/import";

type TimeRecord = RouterOutputs["timeRecord"]["all"][number];
Expand Down Expand Up @@ -159,17 +160,10 @@ const AddTime: React.FC<{ teamId: string; date: Dayjs }> = ({
<PopoverTrigger asChild>
<Button
variant={"outline"}
className={cn(
"justify-start rounded-r-none text-left font-normal",
!field.value && "text-muted-foreground",
)}
className="justify-start rounded-r-none text-left font-normal"
>
<CalendarIcon className="mr-2 h-4 w-4" />
{field.value ? (
displayTime({ date: field.value, format: "DD/MM/YYYY" })
) : (
<span>Pick a date</span>
)}
{displayTime({ date: field.value, format: "DD/MM/YYYY" })}
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0">
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/team/[teamId]/@tabs/info/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export default async function Page({

const history = await api.timeRecord.history({ teamId });

return <UserInfo teamId={teamId} teamMember={teamMember} history={history} />;
return <UserInfo teamMember={teamMember} history={history} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function RegisteredTimes({ teamId }: { teamId: string }) {
<div className="flex flex-col items-center gap-4">
<h2 className="text-xl font-semibold">Pontos registrados</h2>
<div className="flex flex-col items-center">
{timeRecords?.map((timeRecord) => (
{timeRecords.map((timeRecord) => (
<div key={timeRecord.id} className="flex items-center">
<div className="w-2" />
<div>{displayTime({ date: timeRecord.time })}</div>
Expand Down
8 changes: 3 additions & 5 deletions apps/nextjs/src/app/team/[teamId]/_components/user-info.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { RouterOutputs } from "@acme/api";
import type { RouterOutputs } from "@acme/api";

import dayjs, { displayTime } from "~/utils/dayjs";

type TeamMember = RouterOutputs["teamMember"]["get"];
type History = RouterOutputs["timeRecord"]["history"];

export function UserInfo({
teamId,
teamMember,
history,
}: {
teamId: string;
teamMember: TeamMember;
history: History;
}) {
Expand Down Expand Up @@ -44,7 +42,7 @@ export function UserInfo({
<div className=" flex-1 border-b border-dashed border-primary"></div>
<div>
{displayTime({
date: dayjs(teamMember?.createdAt),
date: dayjs(teamMember.createdAt),
format: "DD/MM/YYYY",
})}
</div>
Expand All @@ -59,7 +57,7 @@ export function UserInfo({
<div className="flex-1">SALDO</div>
<div className="flex-1">ACUMULADO</div>
</div>
{history?.map((month, i) => (
{history.map((month, i) => (
<div key={i} className="flex divide-x">
<div className="flex-1">{month.label}</div>
<div className="flex-1">
Expand Down
4 changes: 2 additions & 2 deletions apps/nextjs/src/app/team/join/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export default function Page({
});

const createTeamMember = api.teamMember.create.useMutation({
onSuccess: async (team) => {
await router.push(`/team/${team.id}`);
onSuccess: (team) => {
router.push(`/team/${team.id}`);
},
onError: (err) => {
toast.error(err.message);
Expand Down
4 changes: 2 additions & 2 deletions apps/nextjs/src/app/team/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export default function Page() {
});

const createTeam = api.team.create.useMutation({
onSuccess: async (team) => {
await router.push(`/team/${team.id}`);
onSuccess: (team) => {
router.push(`/team/${team.id}`);
},
onError: (err) => {
toast.error(
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion apps/nextjs/src/trpc/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SuperJSON from "superjson";

import type { AppRouter } from "@acme/api";

import { env } from "~/env.mjs";
import { env } from "~/env";

const createQueryClient = () =>
new QueryClient({
Expand Down
3 changes: 2 additions & 1 deletion apps/nextjs/src/utils/dayjs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import lib, { ConfigType, Dayjs, OptionType } from "dayjs";
import type { ConfigType, OptionType } from "dayjs";
import lib, { Dayjs } from "dayjs";
import ptbr from "dayjs/locale/pt-br";
import minMax from "dayjs/plugin/minMax";
import timezone from "dayjs/plugin/timezone";
Expand Down
21 changes: 5 additions & 16 deletions apps/nextjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
{
"extends": "@acme/tsconfig/base.json",
"compilerOptions": {
"lib": [
"es2022",
"dom",
"dom.iterable"
],
"lib": ["es2022", "dom", "dom.iterable"],
"jsx": "preserve",
"baseUrl": ".",
"paths": {
"~/*": [
"src/*"
]
"~/*": ["src/*"]
},
"plugins": [
{
Expand All @@ -22,11 +16,6 @@
"module": "esnext",
"strictNullChecks": true
},
"include": [
".",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}
"include": [".", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
1 change: 0 additions & 1 deletion packages/api/src/root.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { authRouter } from "./router/auth";
import { teamRouter } from "./router/team";
import { teamMemberRouter } from "./router/team-member";
Expand Down
10 changes: 9 additions & 1 deletion packages/api/src/router/team.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TRPCError } from "@trpc/server";
import { z } from "zod";

import { and, eq, schema } from "@acme/db";
Expand Down Expand Up @@ -55,7 +56,14 @@ export const teamRouter = {
})
.returning();

const team = res[0]!;
const team = res[0];

if (!team) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Time não encontrado",
});
}

await ctx.db.insert(schema.teamMember).values({
teamId: team.id,
Expand Down
39 changes: 18 additions & 21 deletions packages/api/src/router/time-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ export const timeRecordRouter = {
userId: true,
time: true,
},
// where: {
// userId: input.userId ?? ctx.session.user.id,
// time: { gte: input?.start, lte: input?.end },
// teamId: input.teamId,
// },
where: and(
eq(schema.timeRecord.teamId, input.teamId),
eq(schema.timeRecord.userId, input.userId ?? ctx.session.user.id),
Expand Down Expand Up @@ -125,22 +120,24 @@ export const timeRecordRouter = {
orderBy: schema.timeRecord.time,
});

const groupByYearMonthDay =
timeRecords?.reduce(
(acc, timeRecord) => {
const day = timeRecord.time.getDate();
const month = timeRecord.time.getMonth();
const year = timeRecord.time.getFullYear();

if (!acc[year]) acc[year] = {};
if (!acc[year]?.[month]) acc[year]![month] = {};
if (!acc[year]?.[month]?.[day]) acc[year]![month]![day] = [];

acc[year]![month]![day]!.push(timeRecord.time);
return acc;
},
{} as Record<number, Record<number, Record<number, Date[]>>>,
) ?? {};
const groupByYearMonthDay = timeRecords.reduce(
(acc, timeRecord) => {
const day = timeRecord.time.getDate();
const month = timeRecord.time.getMonth();
const year = timeRecord.time.getFullYear();

if (!acc[year]) acc[year] = {};
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (!acc[year]?.[month]) acc[year]![month] = {};
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (!acc[year]?.[month]?.[day]) acc[year]![month]![day] = [];

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
acc[year]![month]![day]!.push(timeRecord.time);
return acc;
},
{} as Record<number, Record<number, Record<number, Date[]>>>,
);

const historyResult: {
label: string;
Expand Down
1 change: 1 addition & 0 deletions packages/auth/env.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-restricted-properties */
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";

Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ function Calendar({
...classNames,
}}
components={{
IconLeft: ({ ...props }) => <ChevronLeftIcon className="h-4 w-4" />,
IconRight: ({ ...props }) => <ChevronRightIcon className="h-4 w-4" />,
IconLeft: () => <ChevronLeftIcon className="h-4 w-4" />,
IconRight: () => <ChevronRightIcon className="h-4 w-4" />,
}}
{...props}
/>
Expand Down

0 comments on commit 9513416

Please sign in to comment.