diff --git a/src/pages/LoginPage/Login.tsx b/src/pages/LoginPage/Login.tsx index d135520..3cfb38c 100644 --- a/src/pages/LoginPage/Login.tsx +++ b/src/pages/LoginPage/Login.tsx @@ -5,6 +5,7 @@ import { createSignal, Show, createEffect } from 'solid-js' import { ofetch } from 'ofetch' import { SHA1, SHA3 } from 'crypto-js' import { useNavigate } from '@solidjs/router' +import { checkConnection } from '../../utils/functions' export default () => { const API = import.meta.env.VITE_BACKEND @@ -18,8 +19,15 @@ export default () => { const [password, setPassword] = createSignal('') const [loggedin, setLoggedin] = createSignal(0) const [errorMessage, setErrorMessage] = createSignal('') + const [connected, setConnected] = createSignal(true) const login = async () => { + setConnected(await checkConnection()) + if (connected() === false) { + setErrorMessage('No Connection on Server') + return + } + const employeeid = await ofetch(API + 'get-employeeid/' + name(), { parseResponse: JSON.parse }) const dbpassword = await ofetch(API + 'get-password/' + employeeid.result, { parseResponse: JSON.parse }) const hashPassword = await securePassword() @@ -166,6 +174,28 @@ export default () => { + +
setConnected(true)}> + + + + + +

Connection Error

+
+
+ + +

{errorMessage()}

+
+ + + Click anywhere to close + +
+
+
+
) } diff --git a/src/pages/MainPage/Main.tsx b/src/pages/MainPage/Main.tsx index db627da..b037982 100644 --- a/src/pages/MainPage/Main.tsx +++ b/src/pages/MainPage/Main.tsx @@ -5,6 +5,7 @@ import { Tabs } from '@kobalte/core/tabs' import { ofetch } from 'ofetch' import { onMount, createSignal } from 'solid-js' import dayjs from 'dayjs' +import { checkConnection } from '../../utils/functions' const API = import.meta.env.VITE_BACKEND const PESO = import.meta.env.VITE_PESO @@ -30,6 +31,9 @@ export default () => { const [applicationList, setApplicationList] = createSignal([]) const [nameList, setNameList] = createSignal([]) + const [errorMessage, setErrorMessage] = createSignal('') + const [connected, setConnected] = createSignal(true) + const getListForApproval = async () => { try { const response = await ofetch(API + 'get-listopapproval-electrical', { parseResponse: JSON.parse }) @@ -41,6 +45,12 @@ export default () => { } const load = async () => { + setConnected(await checkConnection()) + if (connected() === false) { + setErrorMessage('Could not gather list of applicaitons') + return + } + await getListForApproval() } @@ -86,11 +96,9 @@ export default () => { signed = await setNewStatus('ELECTRICAL ORDER OF PAYMENT APPROVED AND SIGNED', '170', 'ELECOPAPPROVEDSIGNED') if (signed) { - console.log('Signed') forprinting = await setNewStatus('FOR ELECTRICAL ORDER OF PAYMENT PRINTING', '95', 'ELECOPPRINT') } if (forprinting) { - console.log('For Printing') } } diff --git a/src/utils/functions/checkConnection.ts b/src/utils/functions/checkConnection.ts new file mode 100644 index 0000000..87e8311 --- /dev/null +++ b/src/utils/functions/checkConnection.ts @@ -0,0 +1,13 @@ +import { ofetch } from 'ofetch' + +const API = import.meta.env.VITE_BACKEND + +export default async () => { + try { + const check = await ofetch(API + 'check-connection') + const result = check.result + return result + } catch { + return false + } +} diff --git a/src/utils/functions/index.ts b/src/utils/functions/index.ts new file mode 100644 index 0000000..33c1f54 --- /dev/null +++ b/src/utils/functions/index.ts @@ -0,0 +1 @@ +export { default as checkConnection } from './checkConnection'