From b9039d9a43b50f2b32e68bae8011691a78d89d42 Mon Sep 17 00:00:00 2001 From: Krithin Jay Pakshootra Date: Wed, 18 Oct 2023 09:43:04 +0800 Subject: [PATCH 1/3] chore: finding the error --- src/api/growers.js | 2 ++ src/components/CaptureFilter.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/api/growers.js b/src/api/growers.js index d645be6fb..03a76b5aa 100644 --- a/src/api/growers.js +++ b/src/api/growers.js @@ -32,6 +32,8 @@ export default { offset: skip, }; + console.log('filter -', filter); + const query = `${QUERY_API}/v2/growers${ growerFilter ? `?${makeQueryString(growerFilter)}` : '' }`; diff --git a/src/components/CaptureFilter.js b/src/components/CaptureFilter.js index c00a88b48..2278d9110 100644 --- a/src/components/CaptureFilter.js +++ b/src/components/CaptureFilter.js @@ -125,6 +125,8 @@ function Filter(props) { organization_id: organizationId, tokenId: tokenId.trim(), }; + + console.log('filter -', test); const filter = new FilterModel(test); props.onSubmit && props.onSubmit(filter); From 45510d7507b418a20fa8c3f2ac066874f23eeff3 Mon Sep 17 00:00:00 2001 From: Krithin Jay Pakshootra Date: Thu, 19 Oct 2023 08:53:27 +0800 Subject: [PATCH 2/3] chore: added api issue, waiting for them to fix --- src/api/growers.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/api/growers.js b/src/api/growers.js index 03a76b5aa..b319b8987 100644 --- a/src/api/growers.js +++ b/src/api/growers.js @@ -32,7 +32,8 @@ export default { offset: skip, }; - console.log('filter -', filter); + console.log('filter - ', filter); + console.log(makeQueryString(growerFilter)); const query = `${QUERY_API}/v2/growers${ growerFilter ? `?${makeQueryString(growerFilter)}` : '' From 2b39fec0ca54275ec9fea8f15a0948ff940faa05 Mon Sep 17 00:00:00 2001 From: Krithin Jay Pakshootra Date: Thu, 19 Oct 2023 14:48:21 +0800 Subject: [PATCH 3/3] fix: added error handling for growers page --- src/components/Growers/Growers.js | 22 +++++++++++++-- src/components/Growers/Growers.styles.js | 7 +++++ src/context/GrowerContext.js | 36 +++++++++++++++--------- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/components/Growers/Growers.js b/src/components/Growers/Growers.js index 3c830db25..75e7e9f1f 100644 --- a/src/components/Growers/Growers.js +++ b/src/components/Growers/Growers.js @@ -1,7 +1,7 @@ /* * Grower page */ -import React, { useState, useContext } from 'react'; +import React, { useState, useContext, useEffect } from 'react'; import { TablePagination, Typography, Tooltip, Box } from '@material-ui/core'; import Grower from './Grower'; import GrowerDetail from '../GrowerDetail'; @@ -17,6 +17,13 @@ const Growers = (props) => { const growerContext = useContext(GrowerContext); const [isDetailShown, setDetailShown] = useState(false); const [growerDetail, setGrowerDetail] = useState({}); + const [isError, setIsError] = useState(false); + + useEffect(() => { + if (!growerContext.isLoading && growerContext.error) { + setIsError(true); + } + }, [growerContext.isLoading]); function handlePageChange(e, page) { growerContext.changeCurrentPage(page); @@ -98,7 +105,18 @@ const Growers = (props) => { {pagination} - {growersItems} + + {isError ? ( + + + Sorry, there has been an Internal Server Error. Please try again + later. + + + ) : ( + growersItems + )} + {pagination} diff --git a/src/components/Growers/Growers.styles.js b/src/components/Growers/Growers.styles.js index 1500b6f99..a65503d62 100644 --- a/src/components/Growers/Growers.styles.js +++ b/src/components/Growers/Growers.styles.js @@ -8,6 +8,13 @@ const useStyle = makeStyles((theme) => ({ cursor: 'pointer', margin: '0.5rem', }, + errorBox: { + width: '100%', + height: '70vh', + display: 'flex', + justifyContent: 'center', + alignItems: 'center', + }, cardContent: { padding: 0, height: `${GROWER_IMAGE_SIZE}px`, diff --git a/src/context/GrowerContext.js b/src/context/GrowerContext.js index afa8c0faa..7b22a248d 100644 --- a/src/context/GrowerContext.js +++ b/src/context/GrowerContext.js @@ -39,6 +39,7 @@ export function GrowerProvider(props) { ); const [isLoading, setIsLoading] = useState(false); const [totalGrowerCount, setTotalGrowerCount] = useState(null); + const [isError, setIsError] = useState(false); useEffect(() => { const abortController = new AbortController(); @@ -70,19 +71,27 @@ export function GrowerProvider(props) { const pageNumber = currentPage; //set correct values for organization_id, an array of uuids for ALL_ORGANIZATIONS or a uuid string if provided - const finalFilter = setOrganizationFilter(filter, orgId, orgList); - - const { total, grower_accounts } = await api.getGrowers( - { - skip: pageNumber * pageSize, - rowsPerPage: pageSize, - filter: new FilterGrower(finalFilter), - }, - abortController - ); - setCount(total); - setGrowers(grower_accounts); - setIsLoading(false); + try { + const finalFilter = setOrganizationFilter(filter, orgId, orgList); + + const { total, grower_accounts } = await api.getGrowers( + { + skip: pageNumber * pageSize, + rowsPerPage: pageSize, + filter: new FilterGrower(finalFilter), + }, + abortController + ); + + setCount(total); + setGrowers(grower_accounts); + setIsLoading(false); + } catch (err) { + console.log('error status', err.status); + + setIsError(true); + setIsLoading(false); + } }; const getWallets = async (name, pageNumber) => { @@ -156,6 +165,7 @@ export function GrowerProvider(props) { }; const value = { + error: isError, growers, pageSize, count,