Skip to content

Commit

Permalink
Merge pull request #71 from imperial/feat-filter-time
Browse files Browse the repository at this point in the history
feat: allow filtering of time related columns
  • Loading branch information
matalex412 authored Aug 23, 2024
2 parents c46ef6f + 3de0173 commit 7b9a1a7
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 76 deletions.
6 changes: 3 additions & 3 deletions app/companies/CompanyTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ const CompanyTable = ({
sortingFn: "text",
},
size: {
cell: info => info.getValue() || "N/A",
cell: info => info.getValue(),
header: "Size",
id: "size",
sortingFn: "alphanumeric",
},
hq: {
cell: info => info.getValue() || "N/A",
cell: info => info.getValue(),
header: "HQ",
id: "hq",
sortingFn: "text",
Expand All @@ -97,7 +97,7 @@ const CompanyTable = ({
columnName,
columnDefsMap[columnName] ?? {
// default column definition, so that all company values are also accessible
cell: info => info.getValue() || "N/A",
cell: info => info.getValue(),
header: columnName,
sortingFn: "alphanumeric",
id: columnName,
Expand Down
2 changes: 1 addition & 1 deletion app/companies/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const CompanyPage = async ({ params }: { params: { slug: string } }) => {
<Box p="8">
<OpportunityTable
opportunities={companyProfile.opportunities}
columns={["position", "location", "type", "createdAt"]}
columns={["position", "location", "type", "createdAt", "deadline"]}
displayColumns={
!!session && (session.user.role === Role.ADMIN || (await checkCompany(companyProfile.id)(session)))
? ["adminButtons"]
Expand Down
6 changes: 3 additions & 3 deletions app/events/EventTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { DeleteEvent } from "@/components/DeleteEvent"
import Link from "@/components/Link"
import TanstackTable from "@/components/TanstackTable"
import TanstackTable, { dateFilterFn } from "@/components/TanstackTable"
import { EditEvent } from "@/components/UpsertEvent"

import styles from "./eventTable.module.scss"
Expand Down Expand Up @@ -73,7 +73,7 @@ const EventTable = ({
header: "Start Date",
sortingFn: "datetime",
id: "dateStart",
enableColumnFilter: false,
filterFn: dateFilterFn,
},
shortDescription: {
cell: info => info.getValue(),
Expand Down Expand Up @@ -112,7 +112,7 @@ const EventTable = ({
columnName,
columnDefsMap[columnName] ?? {
// default column definition, so that all company values are also accessible
cell: info => info.getValue() || "N/A",
cell: info => info.getValue(),
header: columnName,
sortingFn: "alphanumeric",
id: columnName,
Expand Down
13 changes: 10 additions & 3 deletions app/opportunities/OpportunityTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { DeleteOpportunity } from "@/components/DeleteOpportunity"
import Link from "@/components/Link"
import TanstackTable from "@/components/TanstackTable"
import TanstackTable, { dateFilterFn } from "@/components/TanstackTable"
import { EditOpportunity } from "@/components/UpsertOpportunity"

import styles from "./opportunityTable.module.scss"
Expand All @@ -11,7 +11,7 @@ import { getCompanyLink } from "../companies/getCompanyLink"
import type { CompanyProfile, Opportunity } from "@prisma/client"
import { Flex } from "@radix-ui/themes"
import { ColumnDef, DisplayColumnDef, createColumnHelper } from "@tanstack/react-table"
import { formatDistanceToNowStrict } from "date-fns"
import { format, formatDistanceToNowStrict } from "date-fns"
import Image from "next/image"
import { useMemo } from "react"

Expand Down Expand Up @@ -87,7 +87,14 @@ const OpportunityTable = ({
header: "Posted",
sortingFn: "datetime",
id: "posted",
enableColumnFilter: false,
filterFn: dateFilterFn,
},
deadline: {
cell: info => <time suppressHydrationWarning={true}>{format(info.getValue(), "EEEE do MMMM yyyy")}</time>,
header: "Application Deadline",
sortingFn: "datetime",
id: "deadline",
filterFn: dateFilterFn,
},
}

Expand Down
2 changes: 1 addition & 1 deletion app/opportunities/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const OpportunitiesPage = async () => {
<Heading size="8">Opportunities</Heading>
<OpportunityTable
opportunities={opportunities}
columns={["company.name", "position", "location", "type", "createdAt"]}
columns={["company.name", "position", "location", "type", "createdAt", "deadline"]}
/>
</Flex>
</RestrictedArea>
Expand Down
4 changes: 2 additions & 2 deletions app/students/StudentTable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client"

import Link from "@/components/Link"
import TanstackTable from "@/components/TanstackTable"
import TanstackTable, { dateFilterFn } from "@/components/TanstackTable"
import UserAvatar from "@/components/UserAvatar"

import { StudentProfile, User } from "@prisma/client"
Expand Down Expand Up @@ -45,7 +45,7 @@ const StudentTable = ({
header: "Graduating",
sortingFn: "datetime",
id: "graduationDate",
enableColumnFilter: true,
filterFn: dateFilterFn,
},
course: {
cell: info => info.getValue(),
Expand Down
14 changes: 12 additions & 2 deletions components/DateTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,30 @@ const DateTimePicker = ({
placeholder,
required = false,
defaultDate,
onChange,
showTime = true,
value,
}: {
name: string
placeholder: string
required?: boolean
defaultDate?: Date | null
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void
showTime?: boolean
value?: string
}) => {
return (
<TextField.Root
className={styles.inputBox}
type="datetime-local"
type={showTime ? "datetime-local" : "date"}
name={name}
placeholder={placeholder}
required={required}
defaultValue={!!defaultDate ? format(toZonedTime(defaultDate, TIMEZONE), "yyyy-MM-dd'T'HH:mm") : ""}
defaultValue={
!!defaultDate ? format(toZonedTime(defaultDate, TIMEZONE), showTime ? "yyyy-MM-dd'T'HH:mm" : "yyyy-MM-dd") : ""
}
onChange={onChange}
value={value}
/>
)
}
Expand Down
Loading

0 comments on commit 7b9a1a7

Please sign in to comment.