| @@ -12,7 +12,7 @@ import { | |||||
| OnlinePrediction, FileDownload, SettingsEthernet | OnlinePrediction, FileDownload, SettingsEthernet | ||||
| } from "@mui/icons-material"; | } from "@mui/icons-material"; | ||||
| import dayjs from "dayjs"; | import dayjs from "dayjs"; | ||||
| import { I18nProvider } from "@/i18n"; | |||||
| import { redirect } from "next/navigation"; | |||||
| import { NEXT_PUBLIC_API_URL } from "@/config/api"; | import { NEXT_PUBLIC_API_URL } from "@/config/api"; | ||||
| export default function ProductionSchedulePage() { | export default function ProductionSchedulePage() { | ||||
| @@ -71,12 +71,22 @@ export default function ProductionSchedulePage() { | |||||
| const handleSearch = async () => { | const handleSearch = async () => { | ||||
| const token = localStorage.getItem("accessToken"); | const token = localStorage.getItem("accessToken"); | ||||
| setLoading(true); | setLoading(true); | ||||
| try { | try { | ||||
| const response = await fetch(`${NEXT_PUBLIC_API_URL}/ps/search-ps?produceAt=${searchDate}`, { | const response = await fetch(`${NEXT_PUBLIC_API_URL}/ps/search-ps?produceAt=${searchDate}`, { | ||||
| method: 'GET', | method: 'GET', | ||||
| headers: { 'Authorization': `Bearer ${token}` } | headers: { 'Authorization': `Bearer ${token}` } | ||||
| }); | }); | ||||
| if (response.status === 401 || response.status === 403) { | |||||
| console.warn(`Auth error ${response.status} → clearing token & redirecting`); | |||||
| window.location.href = "/login?session=expired"; | |||||
| return; // ← stops execution here | |||||
| } | |||||
| const data = await response.json(); | const data = await response.json(); | ||||
| setSchedules(Array.isArray(data) ? data : []); | setSchedules(Array.isArray(data) ? data : []); | ||||
| } catch (e) { | } catch (e) { | ||||
| console.error("Search Error:", e); | console.error("Search Error:", e); | ||||
| @@ -219,7 +229,7 @@ export default function ProductionSchedulePage() { | |||||
| const handleAutoGenJob = async () => { | const handleAutoGenJob = async () => { | ||||
| if (!isDateToday) return; | |||||
| //if (!isDateToday) return; | |||||
| const token = localStorage.getItem("accessToken"); | const token = localStorage.getItem("accessToken"); | ||||
| setIsGenerating(true); | setIsGenerating(true); | ||||
| try { | try { | ||||
| @@ -375,7 +385,9 @@ export default function ProductionSchedulePage() { | |||||
| {/* Footer Actions */} | {/* Footer Actions */} | ||||
| <DialogActions sx={{ p: 2, bgcolor: '#f9f9f9' }}> | <DialogActions sx={{ p: 2, bgcolor: '#f9f9f9' }}> | ||||
| <Stack direction="row" spacing={2}> | <Stack direction="row" spacing={2}> | ||||
| {/* | |||||
| <Tooltip title={!isDateToday ? "Job Orders can only be generated for the current day's schedule." : ""}> | <Tooltip title={!isDateToday ? "Job Orders can only be generated for the current day's schedule." : ""}> | ||||
| */} | |||||
| <span> | <span> | ||||
| <Button | <Button | ||||
| variant="contained" | variant="contained" | ||||
| @@ -388,7 +400,9 @@ export default function ProductionSchedulePage() { | |||||
| 自動生成工單 | 自動生成工單 | ||||
| </Button> | </Button> | ||||
| </span> | </span> | ||||
| {/* | |||||
| </Tooltip> | </Tooltip> | ||||
| */} | |||||
| <Button | <Button | ||||
| onClick={() => setIsDetailOpen(false)} | onClick={() => setIsDetailOpen(false)} | ||||
| variant="outlined" | variant="outlined" | ||||