Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
reacto11mecha committed Jun 16, 2024
1 parent e146274 commit 530603c
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 56 deletions.
6 changes: 6 additions & 0 deletions apps/web/src/app/(auth)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export default async function RootLayout(props: { children: React.ReactNode }) {
const layout = cookies().get("react-resizable-panels:layout");
const collapsed = cookies().get("react-resizable-panels:collapsed");

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const defaultLayout = layout ? JSON.parse(layout.value) : undefined;

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const defaultCollapsed = collapsed ? JSON.parse(collapsed.value) : undefined;

if (!isLoggedIn) redirect("/login");
Expand Down Expand Up @@ -80,11 +83,14 @@ export default async function RootLayout(props: { children: React.ReactNode }) {
>
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
<ResizeableNav
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
defaultLayout={defaultLayout}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
defaultCollapsed={defaultCollapsed}
name={isLoggedIn.user.name ?? ""}
email={isLoggedIn.user.email ?? ""}
nameFallback={isLoggedIn.user.name?.slice(0, 2) ?? ""}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
role={isLoggedIn.user.role!}
>
<TRPCReactProvider>{props.children}</TRPCReactProvider>
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/app/(noauth)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Metadata, Viewport } from "next";
import localFont from "next/font/local";
import { GeistMono } from "geist/font/mono";
import { GeistSans } from "geist/font/sans";

Expand Down
1 change: 0 additions & 1 deletion apps/web/src/app/(noauth)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import localFont from "next/font/local";

import { cn } from "@sora-vp/ui";
import { Button } from "@sora-vp/ui/button";

const sundaneseFont = localFont({
src: "../fonts/NotoSansSundanese-Regular.ttf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const columns: ColumnDef<PendingUserList>[] = [
<UpdateRole
isOpen={openUpdate}
toggleOpen={toggleOpen}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
currRole={user.role!}
userId={user.id}
/>
Expand Down Expand Up @@ -202,8 +203,7 @@ export function AllRegisteredUser() {
</TableRow>
) : null}

{allRegisteredUserQuery.isLoading &&
!allRegisteredUserQuery.isError ? (
{allRegisteredUserQuery.isLoading ? (
<>
{Array.from({ length: 5 }).map((_, idx) => (
<TableRow key={idx}>
Expand All @@ -215,7 +215,7 @@ export function AllRegisteredUser() {
</>
) : null}

{table.getRowModel().rows?.length ? (
{table.getRowModel().rows.length ? (
table.getRowModel().rows.map((row) => (
<TableRow
key={row.id}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";

import type { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import { Loader2 } from "lucide-react";
import { useForm } from "react-hook-form";
import { z } from "zod";

import { Button } from "@sora-vp/ui/button";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";

import type { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import { Loader2 } from "lucide-react";
import { useForm } from "react-hook-form";
import { z } from "zod";

import { Button } from "@sora-vp/ui/button";
import {
Expand Down
5 changes: 2 additions & 3 deletions apps/web/src/app/_components/admin/pending-user/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export const columns: ColumnDef<PendingUserList>[] = [
id: "accept",
enableHiding: false,
cell: ({ row }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const apiUtils = api.useUtils();

// eslint-disable-next-line react-hooks/rules-of-hooks
Expand Down Expand Up @@ -207,7 +206,7 @@ export function PendingUser() {
</TableRow>
) : null}

{pendingUserQuery.isLoading && !pendingUserQuery.isError ? (
{pendingUserQuery.isLoading ? (
<>
{Array.from({ length: 5 }).map((_, idx) => (
<TableRow key={idx}>
Expand All @@ -219,7 +218,7 @@ export function PendingUser() {
</>
) : null}

{table.getRowModel().rows?.length ? (
{table.getRowModel().rows.length ? (
table.getRowModel().rows.map((row) => (
<TableRow
key={row.id}
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/app/_components/admin/toggle-can-login.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";

import type { z } from "zod";
import { useEffect } from "react";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";

import {
Form,
Expand Down Expand Up @@ -33,6 +33,8 @@ export const ToggleCanLogin = () => {
if (canLoginQuery.data) {
form.setValue("canLogin", canLoginQuery.data.canLogin);
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [form.setValue, canLoginQuery.data]);

const canLoginMutation = api.settings.updateCanLogin.useMutation({
Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/app/_components/auth/login-page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"use client";

import { useState } from "react";
import type { z } from "zod";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { zodResolver } from "@hookform/resolvers/zod";
import { signIn } from "next-auth/react";
import { useForm } from "react-hook-form";
import { z } from "zod";

import { Button } from "@sora-vp/ui/button";
import {
Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/app/_components/auth/registration-page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"use client";

import { useState } from "react";
import type { z } from "zod";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";

import { Button } from "@sora-vp/ui/button";
import {
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/app/_components/participant/sudden-qr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ import {
DialogTitle,
DialogTrigger,
} from "@sora-vp/ui/dialog";
import { FormControl, FormItem, FormLabel } from "@sora-vp/ui/form";
import { Input } from "@sora-vp/ui/input";

type Timer = ReturnType<typeof setTimeout>;
type SomeFunction = (...args: any[]) => void;
type SomeFunction = (fn: never) => void;
/**
*
* @param func The original, non debounced function (You can pass any number of args to it)
Expand Down Expand Up @@ -52,6 +51,7 @@ export function useDebounce<Func extends SomeFunction>(
}

export function SuddenQr() {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const canvasRef = useRef<HTMLCanvasElement>(null!);

const [isOpen, setDialogOpen] = useState(false);
Expand All @@ -65,7 +65,7 @@ export function SuddenQr() {
return;
}

QRCode.toCanvas(canvasRef.current, qr, { width: 296 });
void QRCode.toCanvas(canvasRef.current, qr, { width: 296 });
});

return (
Expand Down
9 changes: 5 additions & 4 deletions apps/web/src/app/_components/settings/behaviour.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";

import type { z } from "zod";
import { useEffect } from "react";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";

import { Button } from "@sora-vp/ui/button";
import {
Expand All @@ -13,7 +13,6 @@ import {
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@sora-vp/ui/form";
import { Switch } from "@sora-vp/ui/switch";
import { toast } from "@sora-vp/ui/toast";
Expand Down Expand Up @@ -55,9 +54,11 @@ export function Behaviour() {

useEffect(() => {
if (settingsQuery.data && !changeBehaviour.isPending) {
form.setValue("canVote", settingsQuery.data.canVote ?? undefined);
form.setValue("canAttend", settingsQuery.data.canAttend ?? undefined);
form.setValue("canVote", settingsQuery.data.canVote);
form.setValue("canAttend", settingsQuery.data.canAttend);
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [settingsQuery.data, changeBehaviour.isPending]);

return (
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/router/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const adminRouter = {
ctx.db.query.users.findMany({
where: and(
sql`${schema.users.verifiedAt} IS NULL`,

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
not(eq(schema.users.email, ctx.session.user.email!)),
),
}),
Expand Down Expand Up @@ -110,6 +112,8 @@ export const adminRouter = {
ctx.db.query.users.findMany({
where: and(
sql`${schema.users.verifiedAt} IS NOT NULL`,

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
not(eq(schema.users.email, ctx.session.user.email!)),
),
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/router/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import bcrypt from "bcrypt";
import { countUserTable, preparedGetUserByEmail, schema } from "@sora-vp/db";
import { auth as authValidator } from "@sora-vp/validators";

import { protectedProcedure, publicProcedure } from "../trpc";
import { publicProcedure } from "../trpc";

export const authRouter = {
register: publicProcedure
Expand Down
9 changes: 3 additions & 6 deletions packages/api/src/router/candidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import type { TRPCRouterRecord } from "@trpc/server";
import { TRPCError } from "@trpc/server";
import mime from "mime-types";

import {
eq,
preparedAdminGetCandidates,
// preparedGetExcelParticipants,
schema,
} from "@sora-vp/db";
import { eq, preparedAdminGetCandidates, schema } from "@sora-vp/db";
import { randomFileName } from "@sora-vp/id-generator";
import { canVoteNow } from "@sora-vp/settings";
import { candidate } from "@sora-vp/validators";
Expand Down Expand Up @@ -81,6 +76,7 @@ export const candidateRouter = {
})
.where(eq(schema.candidates.id, input.id));

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const fileName = `${randomFileName()}.${mime.extension(input.type!)}`;

if (!existsSync(NEXT_ROOT_PATH)) mkdirSync(NEXT_ROOT_PATH);
Expand All @@ -89,6 +85,7 @@ export const candidateRouter = {
if (existsSync(path.join(NEXT_ROOT_PATH, candidate.image)))
await unlink(path.join(NEXT_ROOT_PATH, candidate.image));

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const imageContent = Buffer.from(input.image!, "base64");

await writeFile(path.join(NEXT_ROOT_PATH, fileName), imageContent);
Expand Down
6 changes: 4 additions & 2 deletions packages/api/src/router/participant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const participantRouter = {

if (
normalizedCheckThing.length > 0 &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
normalizedCheckThing.every((data) => data !== null)
) {
throw new TRPCError({
Expand All @@ -53,6 +54,7 @@ export const participantRouter = {

if (
normalizedCheckThing.length > 0 &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
normalizedCheckThing.some((data) => data !== null)
) {
throw new TRPCError({
Expand Down Expand Up @@ -131,7 +133,7 @@ export const participantRouter = {
exportJsonData: protectedProcedure.mutation(async () => {
const participants = await preparedGetExcelParticipants.execute();

if (!participants || participants.length < 0)
if (participants.length < 0)
throw new TRPCError({
code: "NOT_FOUND",
message: "Tidak ada data peserta pemilihan!",
Expand All @@ -143,7 +145,7 @@ export const participantRouter = {
exportXlsxForParticipantToRetrieve: protectedProcedure.mutation(async () => {
const participants = await preparedGetExcelParticipants.execute();

if (!participants || participants.length < 1)
if (participants.length < 1)
throw new TRPCError({
code: "NOT_FOUND",
message: "Tidak ada data peserta pemilihan!",
Expand Down
14 changes: 8 additions & 6 deletions packages/api/src/router/statistic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ export const statisticRouter = {
essentialInfoQuery: adminProcedure.query(async () => {
const candidates = await preparedGetCandidateCountsOnly.execute();

if (!candidates || candidates.length < 1)
if (candidates.length < 1)
return {
isMatch: null,
participants: null,
candidates: null,
};

const participantCounter = await preparedGetAttendedAndVoted.execute();

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const extractCount = participantCounter.at(0)!;
const participantsAccumulation = extractCount.count;

Expand All @@ -38,9 +40,9 @@ export const statisticRouter = {
};
}),

dataReportMutation: adminProcedure.mutation(async ({ ctx }) => {
return {
success: true,
};
}),
// dataReportMutation: adminProcedure.mutation(async ({ ctx }) => {
// return {
// success: true,
// };
// }),
} satisfies TRPCRouterRecord;
10 changes: 8 additions & 2 deletions packages/auth/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { preparedGetUserByEmail } from "@sora-vp/db";
class UnexpectedLoginError extends CredentialsSignin {
code = "Terjadi kesalahan yang terduga, mohon coba lagi nanti.";
}
class UserNotFound extends CredentialsSignin {
code = "Pengguna tidka ditemukan!";
}
class InvalidLoginError extends CredentialsSignin {
code = "Mohon masukan email dan kata sandi!";
}
Expand Down Expand Up @@ -44,7 +47,7 @@ export const authConfig = {
email: credentials.email,
});

if (!user) throw new InvalidUserOrPassword();
if (!user) throw new UserNotFound();

const isValidPassword = await bcrypt.compare(
credentials.password as string,
Expand All @@ -58,7 +61,7 @@ export const authConfig = {
email: user.email,
};
} catch (_) {
throw new InvalidUserOrPassword();
throw new UnexpectedLoginError();
}
},
}),
Expand All @@ -72,7 +75,10 @@ export const authConfig = {
email: session.user.email,
});

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
session.user.role = user!.role;

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
session.user.verifiedAt = user!.verifiedAt;

return session;
Expand Down
4 changes: 2 additions & 2 deletions packages/settings/src/SettingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ interface ReturnedValues {
canLogin: boolean;
}

type UpdateEventMap = {
interface UpdateEventMap {
update: ReturnedValues;
};
}

type ExtractValues<T> = T extends unknown ? T[keyof T] : never;

Expand Down
Loading

0 comments on commit 530603c

Please sign in to comment.