forked from medusajs/medusa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard): Refactor Users table to use the new DataTable block (m…
…edusajs#11058) **What** - Updates the Users table to use the new DataTable - Fixes an issue where initial parsing of URL filters weren't formatted correctly.
- Loading branch information
1 parent
0bef320
commit 6346836
Showing
12 changed files
with
671 additions
and
1,878 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@medusajs/dashboard": patch | ||
--- | ||
|
||
feat(dashboard): Refactor Users table to use the new DataTable block |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...s/admin/dashboard/src/components/data-table/hooks/general/use-data-table-date-filters.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { createDataTableFilterHelper } from "@medusajs/ui" | ||
import { subDays, subMonths } from "date-fns" | ||
import { useMemo } from "react" | ||
import { useTranslation } from "react-i18next" | ||
|
||
import { useDate } from "../../../../hooks/use-date" | ||
|
||
const filterHelper = createDataTableFilterHelper<any>() | ||
|
||
const useDateFilterOptions = () => { | ||
const { t } = useTranslation() | ||
|
||
const today = useMemo(() => { | ||
const date = new Date() | ||
date.setHours(0, 0, 0, 0) | ||
return date | ||
}, []) | ||
|
||
return useMemo(() => { | ||
return [ | ||
{ | ||
label: t("filters.date.today"), | ||
value: { | ||
$gte: today.toISOString(), | ||
}, | ||
}, | ||
{ | ||
label: t("filters.date.lastSevenDays"), | ||
value: { | ||
$gte: subDays(today, 7).toISOString(), // 7 days ago | ||
}, | ||
}, | ||
{ | ||
label: t("filters.date.lastThirtyDays"), | ||
value: { | ||
$gte: subDays(today, 30).toISOString(), // 30 days ago | ||
}, | ||
}, | ||
{ | ||
label: t("filters.date.lastNinetyDays"), | ||
value: { | ||
$gte: subDays(today, 90).toISOString(), // 90 days ago | ||
}, | ||
}, | ||
{ | ||
label: t("filters.date.lastTwelveMonths"), | ||
value: { | ||
$gte: subMonths(today, 12).toISOString(), // 12 months ago | ||
}, | ||
}, | ||
] | ||
}, [today, t]) | ||
} | ||
|
||
export const useDataTableDateFilters = (disableRangeOption?: boolean) => { | ||
const { t } = useTranslation() | ||
const { getFullDate } = useDate() | ||
const dateFilterOptions = useDateFilterOptions() | ||
|
||
const rangeOptions = useMemo(() => { | ||
if (disableRangeOption) { | ||
return { | ||
disableRangeOption: true, | ||
} | ||
} | ||
|
||
return { | ||
rangeOptionStartLabel: t("filters.date.starting"), | ||
rangeOptionEndLabel: t("filters.date.ending"), | ||
rangeOptionLabel: t("filters.date.custom"), | ||
options: dateFilterOptions, | ||
} | ||
}, [disableRangeOption, t, dateFilterOptions]) | ||
|
||
return useMemo(() => { | ||
return [ | ||
filterHelper.accessor("created_at", { | ||
type: "date", | ||
label: t("fields.createdAt"), | ||
format: "date", | ||
formatDateValue: (date) => getFullDate({ date }), | ||
options: dateFilterOptions, | ||
...rangeOptions, | ||
}), | ||
filterHelper.accessor("updated_at", { | ||
type: "date", | ||
label: t("fields.updatedAt"), | ||
format: "date", | ||
formatDateValue: (date) => getFullDate({ date }), | ||
options: dateFilterOptions, | ||
...rangeOptions, | ||
}), | ||
] | ||
}, [t, dateFilterOptions, getFullDate, rangeOptions]) | ||
} |
55 changes: 0 additions & 55 deletions
55
packages/admin/dashboard/src/hooks/filters/use-date-filter-options.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.