Files
frontend/src/entities/bank-card/ui/BankPeriodPicker/BankPeriodPicker.vm.ts
T
ksv741 b404c1802a
Frontend verify / commits (pull_request) Successful in 24s
Frontend verify / security (pull_request) Failing after 9s
Frontend verify / verify (pull_request) Skipped
refactor: simplify auth and instrument pages
2026-09-29 05:45:08 +03:00

31 lines
818 B
TypeScript

import { useState } from "react";
import { useTranslation } from "react-i18next";
type BankPeriodPickerProps = {
onChange: (value: [null | string, null | string]) => void;
period: { from: string; to: string };
};
function useBankPeriodPickerVm(props: BankPeriodPickerProps) {
const { onChange, period } = props;
const { t } = useTranslation();
const scope = `${period.from}-${period.to}`;
const [draft, setDraft] = useState<{
scope: string;
value: [null | string, null | string];
}>();
const value: [null | string, null | string]
= draft?.scope === scope ? draft.value : [period.from, period.to];
const onPeriodChange = (next: [null | string, null | string]) => {
setDraft({ scope, value: next });
onChange(next);
};
return { onPeriodChange, t, value };
}
export { useBankPeriodPickerVm };