From 30e22d5ef875096bff1f1fc7011514c53af3e3a8 Mon Sep 17 00:00:00 2001 From: "vluk@2fi-solutions.com.hk" Date: Tue, 23 Jun 2026 00:17:14 +0800 Subject: [PATCH] no message --- src/app/(main)/testing/page.tsx | 140 ++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/src/app/(main)/testing/page.tsx b/src/app/(main)/testing/page.tsx index 21214ff..93a3fe3 100644 --- a/src/app/(main)/testing/page.tsx +++ b/src/app/(main)/testing/page.tsx @@ -112,6 +112,22 @@ export default function TestingPage() { const [bomByItemCodeResult, setBomByItemCodeResult] = useState( null, ); + const whatsAppTestInFlightRef = useRef(false); + const [whatsAppVar1, setWhatsAppVar1] = useState("12/1"); + const [whatsAppVar2, setWhatsAppVar2] = useState("3pm"); + const [whatsAppTestLoading, setWhatsAppTestLoading] = useState(false); + const [whatsAppTestResult, setWhatsAppTestResult] = useState( + null, + ); + const emailTestInFlightRef = useRef(false); + const [emailTestSubject, setEmailTestSubject] = useState( + "FPSMS M18 sync alert [TEST]", + ); + const [emailTestMessage, setEmailTestMessage] = useState( + "FPSMS sync alert test message from /testing page.", + ); + const [emailTestLoading, setEmailTestLoading] = useState(false); + const [emailTestResult, setEmailTestResult] = useState(null); const onpackPayload = useMemo( () => buildOnPackJobOrdersPayload(onpackJobOrders), @@ -353,6 +369,70 @@ export default function TestingPage() { } }; + const handleWhatsAppSyncAlertTest = async () => { + if (whatsAppTestInFlightRef.current) return; + whatsAppTestInFlightRef.current = true; + setWhatsAppTestLoading(true); + setWhatsAppTestResult(null); + try { + const params = new URLSearchParams(); + const v1 = whatsAppVar1.trim(); + const v2 = whatsAppVar2.trim(); + if (v1) params.set("var1", v1); + if (v2) params.set("var2", v2); + const qs = params.toString(); + const response = await clientAuthFetch( + `${NEXT_PUBLIC_API_URL}/scheduler/trigger/sync-alert-test-whatsapp${qs ? `?${qs}` : ""}`, + { method: "GET" }, + ); + if (response.status === 401 || response.status === 403) return; + const text = await response.text(); + if (!response.ok) { + setWhatsAppTestResult(`HTTP ${response.status}\n\n${text}`); + return; + } + setWhatsAppTestResult(text); + } catch (e) { + const msg = e instanceof Error ? e.message : String(e); + setWhatsAppTestResult(`Error: ${msg}`); + } finally { + setWhatsAppTestLoading(false); + whatsAppTestInFlightRef.current = false; + } + }; + + const handleSyncAlertTestEmail = async () => { + if (emailTestInFlightRef.current) return; + emailTestInFlightRef.current = true; + setEmailTestLoading(true); + setEmailTestResult(null); + try { + const params = new URLSearchParams(); + const subj = emailTestSubject.trim(); + const msg = emailTestMessage.trim(); + if (subj) params.set("subject", subj); + if (msg) params.set("message", msg); + const qs = params.toString(); + const response = await clientAuthFetch( + `${NEXT_PUBLIC_API_URL}/scheduler/trigger/sync-alert-test-email${qs ? `?${qs}` : ""}`, + { method: "GET" }, + ); + if (response.status === 401 || response.status === 403) return; + const text = await response.text(); + if (!response.ok) { + setEmailTestResult(`HTTP ${response.status}\n\n${text}`); + return; + } + setEmailTestResult(text); + } catch (e) { + const msg = e instanceof Error ? e.message : String(e); + setEmailTestResult(`Error: ${msg}`); + } finally { + setEmailTestLoading(false); + emailTestInFlightRef.current = false; + } + }; + const handleBomLookupByItemCode = async () => { if (bomByItemCodeInFlightRef.current) return; const code = bomByItemCodeInput.trim(); @@ -440,6 +520,7 @@ export default function TestingPage() { + @@ -888,6 +969,65 @@ export default function TestingPage() { ) : null} + + +
+ + Production sync errors email{" "} + vluk@2fi-solutions.com.hk and{" "} + kelvin.yau@2fi-solutions.com.hk (see{" "} + scheduler.sync-alert.email.to-addresses). WhatsApp/Twilio + is disabled. SMTP from DB MAIL.smtp.* (e.g. Gmail{" "} + vinluk95@gmail.com + app password). + + + setEmailTestSubject(e.target.value)} + fullWidth + /> + setEmailTestMessage(e.target.value)} + multiline + minRows={3} + fullWidth + /> + + + + + {emailTestResult ? ( + + ) : null} + + + GET /scheduler/trigger/sync-alert-test-email?subject=…&message=… + +
+ GET /scheduler/trigger/sync-alert-check — run alert rules + now (empty = OK) +
+
+
); }