Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memperbaiki typing dan eslint #39

Merged
merged 8 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: cp .env.example .env

- name: Lint
run: yarn lint && yarn lint:ws
run: yarn pre-build && yarn lint && yarn lint:ws

format:
runs-on: ubuntu-latest
Expand All @@ -47,4 +47,4 @@ jobs:
uses: ./.github/actions/yarn-nm-install

- name: Typecheck
run: yarn typecheck
run: yarn pre-build && yarn typecheck
2 changes: 1 addition & 1 deletion apps/processor/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import baseConfig from "@sora-vp/eslint-config/base";
/** @type {import('typescript-eslint').Config} */
export default [
{
ignores: [".dist/**"],
ignores: [".dist/**", "tsup.config.ts"],
},
...baseConfig,
];
8 changes: 7 additions & 1 deletion 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,12 +83,15 @@ 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) ?? ""}
role={isLoggedIn.user.role}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
role={isLoggedIn.user.role!}
>
<TRPCReactProvider>{props.children}</TRPCReactProvider>
</ResizeableNav>
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,7 +133,8 @@ export const columns: ColumnDef<PendingUserList>[] = [
<UpdateRole
isOpen={openUpdate}
toggleOpen={toggleOpen}
currRole={user.role}
// 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
5 changes: 2 additions & 3 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 Expand Up @@ -48,7 +47,7 @@ export function LoginComponent() {
...values,
});

if (loginResult.error) {
if (loginResult?.error) {
console.log(loginResult);
toast.error("Gagal login", { description: "Email atau password salah!" });

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/candidate/candidate-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import { useMemo, useState } from "react";
import { zodResolver } from "@hookform/resolvers/zod";
import { FileText, UserPlus } from "lucide-react";
import { useForm, useWatch } from "react-hook-form";
import { z } from "zod";

import { Button } from "@sora-vp/ui/button";
import { DialogClose, DialogDescription } from "@sora-vp/ui/dialog";
Expand All @@ -30,7 +28,7 @@ interface IProps {
dialogOpen: boolean;
openSetter: React.Dispatch<React.SetStateAction<boolean>>;
name: string;
id: string;
id: number;
}

export function EditCandidate(props: IProps) {
Expand Down Expand Up @@ -82,6 +80,7 @@ export function EditCandidate(props: IProps) {
return;
}

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const file = values.image.item(0)!;
const image = await toBase64(file);

Expand Down Expand Up @@ -172,6 +171,7 @@ export function EditCandidate(props: IProps) {
<Button
type="submit"
className="md:w-fit"
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
disabled={stillTheSameValue || candidateEditMutation.isPending}
>
Edit
Expand Down
36 changes: 13 additions & 23 deletions apps/web/src/app/_components/candidate/data-table.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
"use client";

import type { RouterOutputs } from "@sora-vp/api";
import type {
ColumnDef,
ColumnFiltersState,
SortingState,
VisibilityState,
} from "@tanstack/react-table";
import {
createContext,
useCallback,
useContext,
useEffect,
useState,
} from "react";
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
import { createContext, useContext, useEffect, useState } from "react";
import {
flexRender,
getCoreRowModel,
Expand All @@ -28,7 +17,6 @@ import {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@sora-vp/ui/dropdown-menu";
import { Skeleton } from "@sora-vp/ui/skeleton";
Expand All @@ -40,13 +28,12 @@ import {
TableHeader,
TableRow,
} from "@sora-vp/ui/table";
import { toast } from "@sora-vp/ui/toast";

import { api } from "~/trpc/react";
import { DeleteCandidate, EditCandidate } from "./candidate-action";
import { NewCandidate } from "./new-candidate";

type CandidateList = RouterOutputs["candidate"]["candidateList"][number];
type CandidateList = RouterOutputs["candidate"]["candidateQuery"][number];

export const GlobalSystemAllowance = createContext(true);

Expand All @@ -59,17 +46,20 @@ const columns: ColumnDef<CandidateList>[] = [
accessorKey: "counter",
header: "Jumlah Pemilih",
cell: ({ row }) => (
<span>{row.getValue("counter").toLocaleString("id-ID")} Orang</span>
<span>{row.original.counter.toLocaleString("id-ID")} Orang</span>
),
},
{
accessorKey: "image",
header: "Gambar Kandidat",
cell: ({ row }) => (
<img
className="w-60 rounded border"
src={`/api/uploads/${row.getValue("image")}`}
/>
<>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
className="w-60 rounded border"
src={`/api/uploads/${row.original.image}`}
/>
</>
),
},
{
Expand Down Expand Up @@ -245,7 +235,7 @@ export function DataTable() {
</TableRow>
) : null}

{candidateQuery.isLoading && !candidateQuery.isError ? (
{candidateQuery.isLoading ? (
<>
{Array.from({ length: 10 }).map((_, idx) => (
<TableRow key={idx}>
Expand All @@ -257,7 +247,7 @@ export function DataTable() {
</>
) : null}

{table.getRowModel().rows?.length ? (
{table.getRowModel().rows.length > 0 ? (
table.getRowModel().rows.map((row) => (
<TableRow
key={row.id}
Expand Down
13 changes: 9 additions & 4 deletions apps/web/src/app/_components/candidate/new-candidate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@ import { GlobalSystemAllowance } from "./data-table";

export interface FormSchema {
name: string;
image: File;
image: FileList;
}

export const toBase64 = (file: File) =>
export const toBase64 = (file: File): Promise<string> =>
new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
const splitted = reader.result!.split(",");
resolve(splitted.at(1) as string);
const outputResult = reader.result as string;

const splitted = outputResult.split(",");

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
resolve(splitted.at(1)!);
};
reader.onerror = reject;
});
Expand Down Expand Up @@ -80,6 +84,7 @@ export function NewCandidate() {
}, [candidateMutation.isPending]);

async function onSubmit(values: FormSchema) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const file = values.image.item(0)!;
const image = await toBase64(file);

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/_components/nav/resizeable-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { NavItems } from "./nav-items";
import { TopNavbar } from "./top-navbar";

interface Props {
children: React.ReacNode;
children: React.ReactNode;
role: "admin" | "comittee";
defaultLayout: number[] | undefined;
defaultCollapsed?: boolean;
Expand Down
Loading