mirror of
https://github.com/gethomepage/homepage.git
synced 2026-01-15 05:42:08 +08:00
Fix: correct month handling for Wallos widget (#6150)
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
@@ -6,8 +6,17 @@ import useWidgetAPI from "utils/proxy/use-widget-api";
|
|||||||
|
|
||||||
const MAX_ALLOWED_FIELDS = 4;
|
const MAX_ALLOWED_FIELDS = 4;
|
||||||
|
|
||||||
|
const todayDate = new Date();
|
||||||
|
function toApiMonthYear(offset = 0) {
|
||||||
|
// API expects 1-indexed months, wrap around if needed
|
||||||
|
const m = todayDate.getMonth() + 1 + offset;
|
||||||
|
return {
|
||||||
|
month: ((m + 11) % 12) + 1,
|
||||||
|
year: todayDate.getFullYear() + Math.floor((m - 1) / 12),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export default function Component({ service }) {
|
export default function Component({ service }) {
|
||||||
const todayDate = new Date();
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { widget } = service;
|
const { widget } = service;
|
||||||
|
|
||||||
@@ -29,28 +38,19 @@ export default function Component({ service }) {
|
|||||||
const { data: subscriptionsThisMonthlyCostData, error: subscriptionsThisMonthlyCostError } = useWidgetAPI(
|
const { data: subscriptionsThisMonthlyCostData, error: subscriptionsThisMonthlyCostError } = useWidgetAPI(
|
||||||
widget,
|
widget,
|
||||||
subscriptionsThisMonthlyEndpoint,
|
subscriptionsThisMonthlyEndpoint,
|
||||||
{
|
toApiMonthYear(), // this month
|
||||||
month: todayDate.getMonth(),
|
|
||||||
year: todayDate.getFullYear(),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
const subscriptionsNextMonthlyEndpoint = widget.fields.includes("nextMonthlyCost") ? "get_monthly_cost" : "";
|
const subscriptionsNextMonthlyEndpoint = widget.fields.includes("nextMonthlyCost") ? "get_monthly_cost" : "";
|
||||||
const { data: subscriptionsNextMonthlyCostData, error: subscriptionsNextMonthlyCostError } = useWidgetAPI(
|
const { data: subscriptionsNextMonthlyCostData, error: subscriptionsNextMonthlyCostError } = useWidgetAPI(
|
||||||
widget,
|
widget,
|
||||||
subscriptionsNextMonthlyEndpoint,
|
subscriptionsNextMonthlyEndpoint,
|
||||||
{
|
toApiMonthYear(1), // next month
|
||||||
month: todayDate.getMonth() + 1,
|
|
||||||
year: todayDate.getFullYear(),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
const subscriptionsPreviousMonthlyEndpoint = widget.fields.includes("previousMonthlyCost") ? "get_monthly_cost" : "";
|
const subscriptionsPreviousMonthlyEndpoint = widget.fields.includes("previousMonthlyCost") ? "get_monthly_cost" : "";
|
||||||
const { data: subscriptionsPreviousMonthlyCostData, error: subscriptionsPreviousMonthlyCostError } = useWidgetAPI(
|
const { data: subscriptionsPreviousMonthlyCostData, error: subscriptionsPreviousMonthlyCostError } = useWidgetAPI(
|
||||||
widget,
|
widget,
|
||||||
subscriptionsPreviousMonthlyEndpoint,
|
subscriptionsPreviousMonthlyEndpoint,
|
||||||
{
|
toApiMonthYear(-1), // previous month
|
||||||
month: todayDate.getMonth() - 1,
|
|
||||||
year: todayDate.getFullYear(),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user