diff --git a/apps/nextjs/src/app/_components/header.tsx b/apps/nextjs/src/app/_components/header.tsx index c15e516..cfe7e3e 100644 --- a/apps/nextjs/src/app/_components/header.tsx +++ b/apps/nextjs/src/app/_components/header.tsx @@ -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 (
; + return ; } diff --git a/apps/nextjs/src/app/team/[teamId]/@tabs/history/[year]/[month]/_components/import.tsx b/apps/nextjs/src/app/team/[teamId]/@tabs/history/[year]/[month]/_components/import.tsx index 56855a2..9945b11 100644 --- a/apps/nextjs/src/app/team/[teamId]/@tabs/history/[year]/[month]/_components/import.tsx +++ b/apps/nextjs/src/app/team/[teamId]/@tabs/history/[year]/[month]/_components/import.tsx @@ -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(); const [array, setArray] = useState< Record[] @@ -34,7 +34,7 @@ export function Import({ teamId }: { teamId: string }) { const { mutate } = api.timeRecord.batch.useMutation({ onSuccess: () => { - back(); + router.back(); }, }); @@ -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; diff --git a/apps/nextjs/src/app/team/[teamId]/@tabs/history/[year]/[month]/page.tsx b/apps/nextjs/src/app/team/[teamId]/@tabs/history/[year]/[month]/page.tsx index 69b0971..3efa522 100644 --- a/apps/nextjs/src/app/team/[teamId]/@tabs/history/[year]/[month]/page.tsx +++ b/apps/nextjs/src/app/team/[teamId]/@tabs/history/[year]/[month]/page.tsx @@ -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"; @@ -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]; @@ -159,17 +160,10 @@ const AddTime: React.FC<{ teamId: string; date: Dayjs }> = ({ diff --git a/apps/nextjs/src/app/team/[teamId]/@tabs/info/page.tsx b/apps/nextjs/src/app/team/[teamId]/@tabs/info/page.tsx index 889a475..2d415a9 100644 --- a/apps/nextjs/src/app/team/[teamId]/@tabs/info/page.tsx +++ b/apps/nextjs/src/app/team/[teamId]/@tabs/info/page.tsx @@ -16,5 +16,5 @@ export default async function Page({ const history = await api.timeRecord.history({ teamId }); - return ; + return ; } diff --git a/apps/nextjs/src/app/team/[teamId]/_components/registered-times.tsx b/apps/nextjs/src/app/team/[teamId]/_components/registered-times.tsx index 63699bf..8ba31dd 100644 --- a/apps/nextjs/src/app/team/[teamId]/_components/registered-times.tsx +++ b/apps/nextjs/src/app/team/[teamId]/_components/registered-times.tsx @@ -22,7 +22,7 @@ export function RegisteredTimes({ teamId }: { teamId: string }) {

Pontos registrados

- {timeRecords?.map((timeRecord) => ( + {timeRecords.map((timeRecord) => (
{displayTime({ date: timeRecord.time })}
diff --git a/apps/nextjs/src/app/team/[teamId]/_components/user-info.tsx b/apps/nextjs/src/app/team/[teamId]/_components/user-info.tsx index aec2af9..2138bf3 100644 --- a/apps/nextjs/src/app/team/[teamId]/_components/user-info.tsx +++ b/apps/nextjs/src/app/team/[teamId]/_components/user-info.tsx @@ -1,4 +1,4 @@ -import { RouterOutputs } from "@acme/api"; +import type { RouterOutputs } from "@acme/api"; import dayjs, { displayTime } from "~/utils/dayjs"; @@ -6,11 +6,9 @@ type TeamMember = RouterOutputs["teamMember"]["get"]; type History = RouterOutputs["timeRecord"]["history"]; export function UserInfo({ - teamId, teamMember, history, }: { - teamId: string; teamMember: TeamMember; history: History; }) { @@ -44,7 +42,7 @@ export function UserInfo({
{displayTime({ - date: dayjs(teamMember?.createdAt), + date: dayjs(teamMember.createdAt), format: "DD/MM/YYYY", })}
@@ -59,7 +57,7 @@ export function UserInfo({
SALDO
ACUMULADO
- {history?.map((month, i) => ( + {history.map((month, i) => (
{month.label}
diff --git a/apps/nextjs/src/app/team/join/page.tsx b/apps/nextjs/src/app/team/join/page.tsx index 7df6cbc..c94c59f 100644 --- a/apps/nextjs/src/app/team/join/page.tsx +++ b/apps/nextjs/src/app/team/join/page.tsx @@ -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); diff --git a/apps/nextjs/src/app/team/new/page.tsx b/apps/nextjs/src/app/team/new/page.tsx index 890742b..dba94f2 100644 --- a/apps/nextjs/src/app/team/new/page.tsx +++ b/apps/nextjs/src/app/team/new/page.tsx @@ -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( diff --git a/apps/nextjs/src/env.mjs b/apps/nextjs/src/env.ts similarity index 100% rename from apps/nextjs/src/env.mjs rename to apps/nextjs/src/env.ts diff --git a/apps/nextjs/src/trpc/react.tsx b/apps/nextjs/src/trpc/react.tsx index 9921249..b9ac6f1 100644 --- a/apps/nextjs/src/trpc/react.tsx +++ b/apps/nextjs/src/trpc/react.tsx @@ -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({ diff --git a/apps/nextjs/src/utils/dayjs.ts b/apps/nextjs/src/utils/dayjs.ts index 27f3466..2d3ea9c 100644 --- a/apps/nextjs/src/utils/dayjs.ts +++ b/apps/nextjs/src/utils/dayjs.ts @@ -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"; diff --git a/apps/nextjs/tsconfig.json b/apps/nextjs/tsconfig.json index 91fc90a..893effc 100644 --- a/apps/nextjs/tsconfig.json +++ b/apps/nextjs/tsconfig.json @@ -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": [ { @@ -22,11 +16,6 @@ "module": "esnext", "strictNullChecks": true }, - "include": [ - ".", - ".next/types/**/*.ts" - ], - "exclude": [ - "node_modules" - ] -} \ No newline at end of file + "include": [".", ".next/types/**/*.ts"], + "exclude": ["node_modules"] +} diff --git a/packages/api/src/root.ts b/packages/api/src/root.ts index c4e3d5c..d10519c 100644 --- a/packages/api/src/root.ts +++ b/packages/api/src/root.ts @@ -1,4 +1,3 @@ - import { authRouter } from "./router/auth"; import { teamRouter } from "./router/team"; import { teamMemberRouter } from "./router/team-member"; diff --git a/packages/api/src/router/team.ts b/packages/api/src/router/team.ts index 39c2973..0d66bb8 100644 --- a/packages/api/src/router/team.ts +++ b/packages/api/src/router/team.ts @@ -1,3 +1,4 @@ +import { TRPCError } from "@trpc/server"; import { z } from "zod"; import { and, eq, schema } from "@acme/db"; @@ -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, diff --git a/packages/api/src/router/time-record.ts b/packages/api/src/router/time-record.ts index 79cfcf7..b499bf7 100644 --- a/packages/api/src/router/time-record.ts +++ b/packages/api/src/router/time-record.ts @@ -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), @@ -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>>, - ) ?? {}; + 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>>, + ); const historyResult: { label: string; diff --git a/packages/auth/env.ts b/packages/auth/env.ts index 627caa1..770c20d 100644 --- a/packages/auth/env.ts +++ b/packages/auth/env.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-restricted-properties */ import { createEnv } from "@t3-oss/env-nextjs"; import { z } from "zod"; diff --git a/packages/ui/src/calendar.tsx b/packages/ui/src/calendar.tsx index 175f779..38d9e32 100644 --- a/packages/ui/src/calendar.tsx +++ b/packages/ui/src/calendar.tsx @@ -61,8 +61,8 @@ function Calendar({ ...classNames, }} components={{ - IconLeft: ({ ...props }) => , - IconRight: ({ ...props }) => , + IconLeft: () => , + IconRight: () => , }} {...props} />