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(web): enable daypicker component i18n #1515

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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