diff --git a/src/pages/MainPage/Main.tsx b/src/pages/MainPage/Main.tsx index 6bb37cd..69e161e 100644 --- a/src/pages/MainPage/Main.tsx +++ b/src/pages/MainPage/Main.tsx @@ -37,8 +37,10 @@ export default () => { // const [amountList, setAmountList] = createSignal([]) // const [dateOpList, setDateOpList] = createSignal([]) - const [applicationList, setApplicationList] = createSignal([]) - const [nameList, setNameList] = createSignal([]) + const [applicationListElectrical, setApplicationListElectrical] = createSignal([]) + const [nameListElectrical, setNameListElectrical] = createSignal([]) + const [applicationListOccupancy, setApplicationListOccupancy] = createSignal([]) + const [nameListOccupancy, setNameListOccupancy] = createSignal([]) const [errorMessage, setErrorMessage] = createSignal('') const [connected, setConnected] = createSignal(true) @@ -50,38 +52,73 @@ export default () => { const getListForApproval = async () => { try { - const response = await ofetch(API + 'get-listopapproval-electrical', { parseResponse: JSON.parse }) - setApplicationList(response.result) - setNameList(response.result2) + const responseE = await ofetch(API + 'get-listopapproval-electrical', { parseResponse: JSON.parse }) + setApplicationListElectrical(responseE.result) + setNameListElectrical(responseE.result2) + + const responseO = await ofetch(API + 'get-listopapproval-occupancy', { parseResponse: JSON.parse }) + setApplicationListOccupancy(responseO.result) + setNameListOccupancy(responseO.result2) } catch (error) { console.error(error) } } - const load = async () => { + const getListForApprovalElectrical = async () => { + try { + const responseE = await ofetch(API + 'get-listopapproval-electrical', { parseResponse: JSON.parse }) + setApplicationListElectrical(responseE.result) + setNameListElectrical(responseE.result2) + } catch (error) { + console.error(error) + } + } + + const getListForApprovalOccupancy = async () => { + try { + const responseO = await ofetch(API + 'get-listopapproval-occupancy', { parseResponse: JSON.parse }) + setApplicationListOccupancy(responseO.result) + setNameListOccupancy(responseO.result2) + } catch (error) { + console.error(error) + } + } + + const load = async (division: string) => { setConnected(await checkConnection()) if (connected() === false) { setErrorMessage('Could not gather list of applicaitons') return } - await getListForApproval() + if (division === 'electrical') { + await getListForApprovalElectrical() + } + if (division === 'occupancy') { + await getListForApprovalOccupancy() + } else { + await getListForApproval() + } } - const getopdetails = async (applicationNo: string) => { - const op = await ofetch(API + 'get-opdetails-electrical/' + applicationNo, { parseResponse: JSON.parse }) - setAssessor(op.result7[0]) - setLocation(op.result5[0]) - setType(op.result6[0]) - setDateOp(dayjs(op.result10[0]).format('MMMM DD, YYYY')) - setApplicationId(op.result11[0]) - // setAssessorId(op.result12[0]) - setTotalOp(calculateTotal(op.result9)) - - // setDescriptionList(op.result8) - // setAmountList(op.result9) - // setDateOpList(op.result10) - // calculateAmounts() + const getopdetails = async (division: string, applicationNo: string) => { + if (division === 'electrical') { + const op = await ofetch(API + 'get-opdetails-electrical/' + applicationNo, { parseResponse: JSON.parse }) + setAssessor(op.result7[0]) + setLocation(op.result5[0]) + setType(op.result6[0]) + setDateOp(dayjs(op.result10[0]).format('MMMM DD, YYYY')) + setApplicationId(op.result11[0]) + setTotalOp(calculateTotal(op.result9)) + } else if (division === 'occupancy') { + const op = await ofetch(API + 'get-opdetails-occupancy/' + applicationNo, { parseResponse: JSON.parse }) + setAssessor(op.result7[0]) + setLocation(op.result5[0]) + setType(op.result6[0]) + setDateOp(dayjs(op.result10[0]).format('MMMM DD, YYYY')) + setApplicationId(op.result11[0]) + setTotalOp(calculateTotal(op.result9)) + } } const calculateTotal = (list: number[]) => { @@ -217,11 +254,7 @@ export default () => { const closeNotification = async () => { setApproved(false) - await load() - } - - const openPDF = () => { - createPdf() + await load('all') } const removeEmployee = () => { @@ -280,8 +313,14 @@ export default () => { } } - const refresh = async () => { - await load() + const refresh = async (division: string) => { + if (division === 'electrical') { + await load('electrical') + } else if (division === 'occupancy') { + await load('occupancy') + } else { + await load('all') + } } const logout = async () => { @@ -293,7 +332,7 @@ export default () => { const logged = await checkLogged() if (logged) { - await load() + await load('all') } }) @@ -361,33 +400,12 @@ export default () => { - {/*

List of Ready to Approve and Sign Occupancy Order of Payments

*/} - -

Under Development

-
-
- - - - - {/* - - - - */} - - -
Application NumberNameShow Details
-
-
- - -

List of Ready to Approve and Sign in Electrical Order of Payments

+

List of Ready to Approve and Sign Occupancy Order of Payments

- + @@ -401,10 +419,10 @@ export default () => { - {applicationList().map((item, index) => ( + {applicationListOccupancy().map((item, index) => ( {item} - {nameList()[index]} + {nameListOccupancy()[index]} { background="#121e2acc" color="#ffffffec" function={async () => { - await getopdetails(item) + await getopdetails('occupancy', item) }} > @@ -423,7 +441,94 @@ export default () => { + + + + + + + + + + + + + + + Click anywhere to cancel + + + + + + ))} + + + +
+ + +

List of Ready to Approve and Sign in Electrical Order of Payments

+
+ + + + + + + + + + + + + + + + + + {applicationListElectrical().map((item, index) => ( + + + + +
Application NumberNameShow Details
{item}{nameListElectrical()[index]} + { + await getopdetails('electrical', item) + }} + > + + {item} + + +