You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.7 KiB
JavaScript
61 lines
1.7 KiB
JavaScript
import { useEffect, useState } from 'react';
|
|
import dayjs from "dayjs";
|
|
import { useTranslation } from 'react-i18next';
|
|
import i18n from '@/i18n';
|
|
|
|
export const useDatePresets = () => {
|
|
const [presets, setPresets] = useState([]);
|
|
const { t, i18n } = useTranslation();
|
|
|
|
useEffect(() => {
|
|
const newPresets = [
|
|
{
|
|
label: t("datetime.thisWeek"),
|
|
value: [dayjs().startOf("w"), dayjs().endOf("w")],
|
|
},
|
|
{
|
|
label: t("datetime.lastWeek"),
|
|
value: [dayjs().startOf("w").subtract(7, "days"), dayjs().endOf("w").subtract(7, "days")],
|
|
},
|
|
{
|
|
label: t("datetime.thisMonth"),
|
|
value: [dayjs().startOf("M"), dayjs().endOf("M")],
|
|
},
|
|
{
|
|
label: t("datetime.lastMonth"),
|
|
value: [dayjs().subtract(1, "M").startOf("M"), dayjs().subtract(1, "M").endOf("M")],
|
|
},
|
|
{
|
|
label: t("datetime.lastThreeMonth"),
|
|
value: [dayjs().subtract(2, "M").startOf("M"), dayjs().endOf("M")],
|
|
},
|
|
{
|
|
label: t("datetime.thisYear"),
|
|
value: [dayjs().startOf("y"), dayjs().endOf("y")],
|
|
},
|
|
];
|
|
setPresets(newPresets);
|
|
}, [i18n.language]);
|
|
|
|
return presets;
|
|
}
|
|
|
|
export const useWeekdays = () => {
|
|
const [data, setData] = useState([]);
|
|
const { t, i18n } = useTranslation();
|
|
useEffect(() => {
|
|
const newData = [
|
|
{ value: '1', label: t('weekdays.1') },
|
|
{ value: '2', label: t('weekdays.2') },
|
|
{ value: '3', label: t('weekdays.3') },
|
|
{ value: '4', label: t('weekdays.4') },
|
|
{ value: '5', label: t('weekdays.5') },
|
|
{ value: '6', label: t('weekdays.6') },
|
|
{ value: '7', label: t('weekdays.7') },
|
|
];
|
|
setData(newData);
|
|
return () => {};
|
|
}, [i18n.language]);
|
|
return data;
|
|
};
|