Added checking of connection

This commit is contained in:
Patrick Alvin Alcala 2025-10-02 17:54:51 +08:00
parent 060741fcba
commit 58eb2cb472
4 changed files with 54 additions and 2 deletions

View file

@ -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 () => {
</Padding>
</Modal>
</div>
<div onClick={() => setConnected(true)}>
<Modal trigger={connected() === false} background="#562020ff" color="#ffebebe6" opacity={0.8}>
<Padding top={1} bottom={1} left={4} right={4}>
<Column>
<Row>
<Box curved thickness={3} color="#ffebebe6" padding="1rem">
<h2>Connection Error</h2>
</Box>
</Row>
<Row>
<h3>{errorMessage()}</h3>
</Row>
<Row>
<span class="close-text">Click anywhere to close</span>
</Row>
</Column>
</Padding>
</Modal>
</div>
</>
)
}

View file

@ -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<string[]>([])
const [nameList, setNameList] = createSignal<string[]>([])
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')
}
}

View file

@ -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
}
}

View file

@ -0,0 +1 @@
export { default as checkConnection } from './checkConnection'