refactor: migrate from ESLint to Biome and extract SQL queries to data.ts
- Replace ESLint with Biome for linting and formatting - Configure Biome with tabs, double quotes, and organized imports - Move all SQL/Drizzle queries from page.tsx files to data.ts files - Create new data.ts files for: ajustes, dashboard, relatorios/categorias - Update existing data.ts files: extrato, fatura (add lancamentos queries) - Remove all drizzle-orm imports from page.tsx files - Update README.md with new tooling info Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,76 +10,76 @@ const PERIOD_PARAM = "periodo";
|
||||
const normalizeMonth = (value: string) => value.trim().toLowerCase();
|
||||
|
||||
export function useMonthPeriod() {
|
||||
const searchParams = useSearchParams();
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
|
||||
// Get current date info
|
||||
const now = new Date();
|
||||
const currentYear = now.getFullYear();
|
||||
const currentMonthName = MONTH_NAMES[now.getMonth()];
|
||||
const optionsMeses = [...MONTH_NAMES];
|
||||
// Get current date info
|
||||
const now = new Date();
|
||||
const currentYear = now.getFullYear();
|
||||
const currentMonthName = MONTH_NAMES[now.getMonth()];
|
||||
const optionsMeses = [...MONTH_NAMES];
|
||||
|
||||
const defaultMonth = currentMonthName;
|
||||
const defaultYear = currentYear.toString();
|
||||
const defaultMonth = currentMonthName;
|
||||
const defaultYear = currentYear.toString();
|
||||
|
||||
const periodFromParams = searchParams.get(PERIOD_PARAM);
|
||||
const periodFromParams = searchParams.get(PERIOD_PARAM);
|
||||
|
||||
const { month: currentMonth, year: currentYearValue } = useMemo(() => {
|
||||
if (!periodFromParams) {
|
||||
return { month: defaultMonth, year: defaultYear };
|
||||
}
|
||||
const { month: currentMonth, year: currentYearValue } = useMemo(() => {
|
||||
if (!periodFromParams) {
|
||||
return { month: defaultMonth, year: defaultYear };
|
||||
}
|
||||
|
||||
const [rawMonth, rawYear] = periodFromParams.split("-");
|
||||
const normalizedMonth = normalizeMonth(rawMonth ?? "");
|
||||
const normalizedYear = (rawYear ?? "").trim();
|
||||
const monthExists = optionsMeses.includes(normalizedMonth);
|
||||
const parsedYear = Number.parseInt(normalizedYear, 10);
|
||||
const [rawMonth, rawYear] = periodFromParams.split("-");
|
||||
const normalizedMonth = normalizeMonth(rawMonth ?? "");
|
||||
const normalizedYear = (rawYear ?? "").trim();
|
||||
const monthExists = optionsMeses.includes(normalizedMonth);
|
||||
const parsedYear = Number.parseInt(normalizedYear, 10);
|
||||
|
||||
if (!monthExists || Number.isNaN(parsedYear)) {
|
||||
return { month: defaultMonth, year: defaultYear };
|
||||
}
|
||||
if (!monthExists || Number.isNaN(parsedYear)) {
|
||||
return { month: defaultMonth, year: defaultYear };
|
||||
}
|
||||
|
||||
return {
|
||||
month: normalizedMonth,
|
||||
year: parsedYear.toString(),
|
||||
};
|
||||
}, [periodFromParams, defaultMonth, defaultYear, optionsMeses]);
|
||||
return {
|
||||
month: normalizedMonth,
|
||||
year: parsedYear.toString(),
|
||||
};
|
||||
}, [periodFromParams, defaultMonth, defaultYear, optionsMeses]);
|
||||
|
||||
const buildHref = useCallback(
|
||||
(month: string, year: string | number) => {
|
||||
const normalizedMonth = normalizeMonth(month);
|
||||
const normalizedYear = String(year).trim();
|
||||
const buildHref = useCallback(
|
||||
(month: string, year: string | number) => {
|
||||
const normalizedMonth = normalizeMonth(month);
|
||||
const normalizedYear = String(year).trim();
|
||||
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
params.set(PERIOD_PARAM, `${normalizedMonth}-${normalizedYear}`);
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
params.set(PERIOD_PARAM, `${normalizedMonth}-${normalizedYear}`);
|
||||
|
||||
return `${pathname}?${params.toString()}`;
|
||||
},
|
||||
[pathname, searchParams]
|
||||
);
|
||||
return `${pathname}?${params.toString()}`;
|
||||
},
|
||||
[pathname, searchParams],
|
||||
);
|
||||
|
||||
const replacePeriod = useCallback(
|
||||
(target: string) => {
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
const replacePeriod = useCallback(
|
||||
(target: string) => {
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
|
||||
router.replace(target, { scroll: false });
|
||||
},
|
||||
[router]
|
||||
);
|
||||
router.replace(target, { scroll: false });
|
||||
},
|
||||
[router],
|
||||
);
|
||||
|
||||
return {
|
||||
monthNames: optionsMeses,
|
||||
pathname,
|
||||
currentMonth,
|
||||
currentYear: currentYearValue,
|
||||
defaultMonth,
|
||||
defaultYear,
|
||||
buildHref,
|
||||
replacePeriod,
|
||||
};
|
||||
return {
|
||||
monthNames: optionsMeses,
|
||||
pathname,
|
||||
currentMonth,
|
||||
currentYear: currentYearValue,
|
||||
defaultMonth,
|
||||
defaultYear,
|
||||
buildHref,
|
||||
replacePeriod,
|
||||
};
|
||||
}
|
||||
|
||||
export { PERIOD_PARAM as MONTH_PERIOD_PARAM };
|
||||
|
||||
Reference in New Issue
Block a user