Skip to content

Commit

Permalink
date deselect fix
Browse files Browse the repository at this point in the history
  • Loading branch information
s-iloo committed May 26, 2024
1 parent db8b008 commit ee4ff86
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
14 changes: 10 additions & 4 deletions src/components/admin-table/admin-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,16 @@ export default function AdminTable() {
return Array.from(values) as string[];
};

const handleDateRangeChange = (range: DateRange) => {
table.getColumn("transactionDate")?.setFilterValue(() => {
return [range.from, range.to];
});
const handleDateRangeChange = (range?: DateRange) => {
if (range) {
table.getColumn("transactionDate")?.setFilterValue(() => {
return [range.from, range.to];
});
} else {
table.getColumn("transactionDate")?.setFilterValue(() => {
return undefined;
});
}
};

if (isLoading) {
Expand Down
15 changes: 11 additions & 4 deletions src/components/sponsored-org-table/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { dateFilterFn } from "@/lib/utils";
import { DateRange } from "react-day-picker";
import { rankItem } from "@tanstack/match-sorter-utils";
import React from "react";
import { setDate } from "date-fns";

interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[];
Expand Down Expand Up @@ -136,10 +137,16 @@ export function DataTable<TData, TValue>({
return pages;
};

const handleDateRangeChange = (range: DateRange) => {
table.getColumn("transactionDate")?.setFilterValue(() => {
return [range.from, range.to];
});
const handleDateRangeChange = (range?: DateRange) => {
if (range) {
table.getColumn("transactionDate")?.setFilterValue(() => {
return [range.from, range.to];
});
} else {
table.getColumn("transactionDate")?.setFilterValue(() => {
return undefined;
});
}
};
return (
<>
Expand Down
9 changes: 4 additions & 5 deletions src/components/ui/custom/date-range-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useState } from "react";

type DatePickerWithRangeType = {
className: string;
handleChange: (dateRange: DateRange) => void;
handleChange: (dateRange?: DateRange) => void;
};

export function DatePickerWithRange({
Expand Down Expand Up @@ -59,11 +59,10 @@ export function DatePickerWithRange({
mode="range"
defaultMonth={date?.from}
selected={date}
// onSelect={setDate}
onSelect={(value) => {
if (value) {
setDate(value);
handleChange(value);
}
setDate(value);
handleChange(value);
}}
numberOfMonths={2}
/>
Expand Down

0 comments on commit ee4ff86

Please sign in to comment.