refactor: centralize week calculation logic and standardize schedule boundary date normalization across client and server
This commit is contained in:
@@ -12,14 +12,12 @@ import { disableSchedule, enableSchedule, loadSchedulesEnabled } from "../Org.Se
|
||||
import WeekInput from "@core/app/components/WeekInput/WeekInput";
|
||||
import dayjs from "dayjs";
|
||||
import "dayjs/locale/es";
|
||||
import weekday from "dayjs/plugin/weekday";
|
||||
import "dayjs/locale/es";
|
||||
import { SchedulesEnabledView } from "@models/SchedulesEnabled.type";
|
||||
import Avatar from "@components/Avatar/Avatar";
|
||||
import Button from "@core/app/components/Button/Button";
|
||||
import { useConfirmStore } from "@core/Store/Confirm.Store";
|
||||
import { getMondayWeekStart } from "@core/helpers/week";
|
||||
|
||||
dayjs.extend(weekday);
|
||||
dayjs.locale("es");
|
||||
|
||||
type UrlData = {
|
||||
@@ -34,7 +32,7 @@ export default function Schedules() {
|
||||
const SessionInfo = useSessionStore();
|
||||
const alert = useAlert();
|
||||
const confirm = useConfirmStore();
|
||||
const [startDate, setStartDate] = useState<dayjs.Dayjs>(dayjs().weekday(0));
|
||||
const [startDate, setStartDate] = useState<dayjs.Dayjs>(getMondayWeekStart());
|
||||
const [collaborators, setCollaborators] = useState<SchedulesEnabledView[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -12,9 +12,8 @@ import ReactAvatar from "react-avatar";
|
||||
import API from "@services/Api.Service";
|
||||
import dayjs from "dayjs";
|
||||
import "dayjs/locale/es";
|
||||
import weekday from "dayjs/plugin/weekday";
|
||||
import { getMondayWeekStart, getSundayWeekEnd } from "@core/helpers/week";
|
||||
|
||||
dayjs.extend(weekday);
|
||||
dayjs.locale("es");
|
||||
|
||||
import categories from "@models/Categories.type";
|
||||
@@ -2002,8 +2001,9 @@ export default function StepEngine({ flowId, action, initialCompanyId, initialEm
|
||||
try {
|
||||
// Hacemos un loop de 8 semanas, habilitando bloques exactos de lunes a domingo
|
||||
for (let i = 0; i < 8; i++) {
|
||||
const weekStart = dayjs().weekday(i * 7).format("YYYY-MM-DD");
|
||||
const weekEnd = dayjs().weekday(i * 7 + 6).format("YYYY-MM-DD");
|
||||
const weekStartDate = getMondayWeekStart().add(i, "week");
|
||||
const weekStart = weekStartDate.format("YYYY-MM-DD");
|
||||
const weekEnd = getSundayWeekEnd(weekStartDate).format("YYYY-MM-DD");
|
||||
|
||||
await API.post<any>("schedules-enabled/enable", {
|
||||
companyId: createdCompanyId,
|
||||
|
||||
Reference in New Issue
Block a user