Skip to content

Commit

Permalink
feat(web): enable daypicker component i18n (#1515)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkangert authored Sep 4, 2023
1 parent 969f50d commit 71ec0ca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions web/src/components/DateRangePicker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChangeEventHandler, useMemo, useState } from "react";
import { DateRange, DayPicker, SelectRangeEventHandler } from "react-day-picker";
import { useTranslation } from "react-i18next";
import { CalendarIcon } from "@chakra-ui/icons";
import {
Box,
Expand All @@ -12,6 +13,7 @@ import {
} from "@chakra-ui/react";
import clsx from "clsx";
import { format, isAfter, isBefore, isValid, parse } from "date-fns";
import { es, zhCN } from "date-fns/locale";

import "./index.css";
import "react-day-picker/dist/style.css";
Expand All @@ -28,6 +30,7 @@ export default function DateRangePicker(props: {
const [fromValue, setFromValue] = useState<string>(format(initState.from, "y-MM-dd"));
const [toValue, setToValue] = useState<string>(format(initState.to, "y-MM-dd"));
const darkMode = useColorMode().colorMode === "dark";
const { i18n } = useTranslation();
const onClose = () => {
selectedRange.from && setStartTime(selectedRange.from);
selectedRange.to && setEndTime(selectedRange.to);
Expand Down Expand Up @@ -103,6 +106,7 @@ export default function DateRangePicker(props: {
<PopoverContent zIndex={99}>
<DayPicker
mode="range"
locale={i18n.language === "en" ? es : zhCN}
selected={selectedRange}
onSelect={handleRangeSelect}
styles={{
Expand Down
4 changes: 3 additions & 1 deletion web/src/pages/app/setting/BillingDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import { useQuery } from "@tanstack/react-query";
import { useQueryClient } from "@tanstack/react-query";
import clsx from "clsx";
import { es, zhCN } from "date-fns/locale";

import { BillingIcon, CalendarIcon, FilterIcon } from "@/components/CommonIcon";
import EmptyBox from "@/components/EmptyBox";
Expand All @@ -45,7 +46,7 @@ const DEFAULT_QUERY_DATA = {
const STATE_LIST = ["Pending", "Done"];

export default function BillingDetails() {
const { t } = useTranslation();
const { i18n, t } = useTranslation();
const { colorMode } = useColorMode();
const darkMode = colorMode === "dark";

Expand Down Expand Up @@ -148,6 +149,7 @@ export default function BillingDetails() {
<PopoverBody>
<DayPicker
mode="range"
locale={i18n.language === "en" ? es : zhCN}
selected={selectedRange}
onSelect={handleRangeSelect}
styles={{
Expand Down
4 changes: 3 additions & 1 deletion web/src/pages/app/setting/RechargeHistory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from "@chakra-ui/react";
import { useQuery } from "@tanstack/react-query";
import clsx from "clsx";
import { es, zhCN } from "date-fns/locale";

import { CalendarIcon, ChargeIcon, FilterIcon } from "@/components/CommonIcon";
import EmptyBox from "@/components/EmptyBox";
Expand All @@ -42,7 +43,7 @@ const DEFAULT_QUERY_DATA = {
const STATE_LIST = ["Pending", "Paid", "Failed"];

export default function RechargeHistory() {
const { t } = useTranslation();
const { i18n, t } = useTranslation();
const { colorMode } = useColorMode();
const darkMode = colorMode === "dark";

Expand Down Expand Up @@ -96,6 +97,7 @@ export default function RechargeHistory() {
<PopoverBody>
<DayPicker
mode="range"
locale={i18n.language === "en" ? es : zhCN}
selected={selectedRange}
onSelect={handleRangeSelect}
styles={{
Expand Down

0 comments on commit 71ec0ca

Please sign in to comment.