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

feat: allow filtering of time related columns #71

Merged
merged 15 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
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
15 changes: 13 additions & 2 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 Down Expand Up @@ -87,7 +87,18 @@ const OpportunityTable = ({
header: "Posted",
sortingFn: "datetime",
id: "posted",
enableColumnFilter: false,
filterFn: dateFilterFn,
},
deadline: {
cell: info => (
<time suppressHydrationWarning={true}>
{formatDistanceToNowStrict(info.getValue(), { addSuffix: true })}{" "}
matalex412 marked this conversation as resolved.
Show resolved Hide resolved
</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
Loading