fix schedule
This commit is contained in:
@ -43,21 +43,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
|
||||
if (req.method === 'GET') {
|
||||
const { year, month } = req.query;
|
||||
|
||||
let monthIndex = parseInt(month as string) - 1;
|
||||
const monthInfo = common.getMonthDatesInfo(new Date(year, month, 1));
|
||||
let fromDate = monthInfo.firstMonday;
|
||||
const toDate = monthInfo.lastSunday;
|
||||
|
||||
// Ensure fromDate is not in the past
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0, 0); // Set time to midnight for accurate comparison
|
||||
|
||||
if (fromDate < today) {
|
||||
fromDate = today;
|
||||
}
|
||||
// const { year, month } = req.query;
|
||||
|
||||
// let monthIndex = parseInt(month as string) - 1;
|
||||
// const monthInfo = common.getMonthDatesInfo(new Date(year, month, 1));
|
||||
// let fromDate = monthInfo.firstMonday;
|
||||
// const toDate = monthInfo.lastSunday;
|
||||
let fromDate = new Date();
|
||||
fromDate.setDate(fromDate.getDate() - 1);
|
||||
fromDate.setHours(0, 0, 0, 0);
|
||||
let toDate = new Date(fromDate);
|
||||
toDate.setDate(toDate.getDate() + 30);
|
||||
|
||||
try {
|
||||
|
||||
@ -167,11 +163,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
fs.mkdirSync(outputPath, { recursive: true });
|
||||
}
|
||||
|
||||
fs.writeFileSync(path.join(outputPath, `shifts ${year}.${month}.json`), JSON.stringify(monthlySchedule), 'utf8');
|
||||
//fs.writeFileSync(path.join(outputPath, `shifts ${year}.${month}.json`), JSON.stringify(monthlySchedule), 'utf8');
|
||||
// Load the Handlebars template from a file
|
||||
const template = fs.readFileSync("./src/templates/schedule.hbs", "utf8");
|
||||
generateTemplateFile(monthlySchedule, template).then((result) => {
|
||||
const filename = path.join(outputPath, `schedule ${year}.${month}.html`)
|
||||
const filename = path.join(outputPath, `schedule.html`)
|
||||
//fs.writeFileSync(filename, result, "utf8");
|
||||
res.end(result);
|
||||
}
|
||||
|
@ -20,10 +20,8 @@ const SchedulePage = () => {
|
||||
const [htmlContent, setHtmlContent] = useState(""); // State to hold fetched HTML content
|
||||
|
||||
useEffect(() => {
|
||||
// Define an async function to fetch the HTML content
|
||||
const fetchHtmlContent = async () => {
|
||||
try {
|
||||
// Replace '/api/schedule' with your actual API endpoint
|
||||
const response = await axiosInstance.get('/api/schedule?year=2024&month=1', { responseType: 'text' });
|
||||
setHtmlContent(response.data); // Set the fetched HTML content in state
|
||||
} catch (error) {
|
||||
|
Reference in New Issue
Block a user