Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
Opeyem1a committed Sep 6, 2024
1 parent dfb7d85 commit 7be4c57
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/app/(app)/course/[courseId]/(hooks)/useCourse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const CourseProvider: React.FC<PropsWithChildren> = ({ children }) => {
return <main className="container flex-col min-h-screen pb-8" />
}

if (!("id" in course)) {
if (!course || course && !("id" in course)) {
return <Custom404 errorMessage="Course not found" />
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Input } from "@/components/ui/input"
import { DataTableViewOptions } from "@/components/ui/data-table-view-options"
import { useStudents } from "../(hooks)/useStudents"
import { StudentTableSectionsFilter } from "./student-table-sections-filter"
import {DataTableFacetedFilterProps} from "@/components/ui/data-table-faceted-filter"

type DataTableToolbarProps<TData> = {
table: Table<TData>;
Expand All @@ -14,7 +15,7 @@ export function DataTableToolbar<TData>({
table,
}: DataTableToolbarProps<TData>) {
// todo: fix
const allSections = []
const allSections = [] as DataTableFacetedFilterProps<any, any>['options']
const { filters } = useStudents()
return (
<div className="flex items-center justify-between mt-2">
Expand Down
24 changes: 14 additions & 10 deletions src/app/(app)/course/[courseId]/students/(table)/student-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getPaginationRowModel,
getSortedRowModel,
useReactTable,
PaginationState,
} from "@tanstack/react-table"

import {
Expand All @@ -29,7 +30,8 @@ import { DataTablePagination } from "@/components/ui/data-table-pagination"
import { DataTableToolbar } from "../(table)/student-table-toolbar"
import { useStudents } from "../(hooks)/useStudents"
import { columns } from "../(table)/columns"
import {Student} from "@/_temp_types/student"
import { Student } from "@/_temp_types/student"
import { Updater } from "@tanstack/table-core"

type DataTableProps<TData, TValue> = {
columns: ColumnDef<TData, TValue>[];
Expand Down Expand Up @@ -66,10 +68,8 @@ const DataTable = <TData, TValue>({
onSortingChange: setSorting,
onColumnFiltersChange: setColumnFilters,
onColumnVisibilityChange: setColumnVisibility,
onPaginationChange: (pagination: {
pageIndex: number;
pageSize: number
}) => {
onPaginationChange: (pagination: Updater<PaginationState>) => {
if (typeof pagination === "function") return
filters.pageIndex.set(pagination.pageIndex)
filters.pageSize.set(pagination.pageSize)
},
Expand All @@ -93,8 +93,10 @@ const DataTable = <TData, TValue>({
<TableHead key={header.id} colSpan={header.colSpan}>
{header.isPlaceholder
? null
: flexRender(header.column.columnDef.header,
header.getContext(),)}
: flexRender(
header.column.columnDef.header,
header.getContext(),
)}
</TableHead>
)
})}
Expand All @@ -110,8 +112,10 @@ const DataTable = <TData, TValue>({
>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
{flexRender(cell.column.columnDef.cell,
cell.getContext(),)}
{flexRender(
cell.column.columnDef.cell,
cell.getContext(),
)}
</TableCell>
))}
</TableRow>
Expand All @@ -136,5 +140,5 @@ const DataTable = <TData, TValue>({

export const StudentTable = () => {
const { studentsToDisplay } = useStudents()
return <DataTable<Student> data={studentsToDisplay} columns={columns} />
return <DataTable<Student, any> data={studentsToDisplay} columns={columns} />
}
2 changes: 1 addition & 1 deletion src/app/(providers)/query-client-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "@tanstack/react-query"
import { getTokenAuthHeader } from "../../../utils/auth"

function appendTrailingSlashIfNeeded(path: string) {
function appendTrailingSlashIfNeeded(path: string): string {
if (path.includes("?")) {
const [p, ...rest] = path.split("?")
return `${appendTrailingSlashIfNeeded(p)}?${rest.join()}`
Expand Down

0 comments on commit 7be4c57

Please sign in to comment.