From 57b84c078964b63cdb7ed394fb3af27d19ca8f33 Mon Sep 17 00:00:00 2001 From: amit-s19 Date: Tue, 13 Feb 2024 12:25:57 +0530 Subject: [PATCH] Fix for no entries --- package.json | 2 +- src/pages/synced-titles/index.jsx | 358 +++++++++++++----------------- 2 files changed, 159 insertions(+), 201 deletions(-) diff --git a/package.json b/package.json index 43d2f58..3cbbbe0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "my-app", - "version": "0.1.45", + "version": "0.1.46", "private": true, "scripts": { "dev": "next dev", diff --git a/src/pages/synced-titles/index.jsx b/src/pages/synced-titles/index.jsx index facc366..74fdfab 100644 --- a/src/pages/synced-titles/index.jsx +++ b/src/pages/synced-titles/index.jsx @@ -43,206 +43,164 @@ const defaultOptions = { const CompletedEntries = ({ params }) => { /* Component States and Refs*/ const userData = useSelector((state) => state?.userData); - const _currLocation = useSelector( - (state) => state?.userData?.currentLocation - ); - const [hydrated, setHydrated] = React.useState(false); - const [citizens, setCitizens] = useState(_currLocation?.citizens || []); - const [villageData, setVillageData] = useState({}); - const [currTab, setCurrTab] = React.useState(0); - const [currPage, setCurrPage] = React.useState(1); - const [totalPages, setTotalPages] = useState(1); - const [prevSubmissions, setPrevSubmissions] = useState([]); - const [prevTempSubmissions, setPrevTempSubmissions] = useState([]); - const [searchQuery, setSearchQuery] = useState(""); - const [fetching, setFetching] = useState(false); - const router = useRouter(); - const dispatch = useDispatch(); - - /* Use Effects */ - useEffect(() => { - window.scrollTo({ top: 0, behavior: "smooth" }); - setHydrated(true); - console.log(_currLocation); - setSearchQuery(userData?.searchQuery?.[_currLocation.villageCode] || ""); - getVillageData(); - }, []); - - useEffect(() => { - setCitizens(_currLocation?.citizens || []); - }, [_currLocation]); - - useEffect(() => { - getVillageSubmissionData(); - }, [currPage]); - - const debouncedSearch = debounce(async (query) => { - console.log({ query, prevTempSubmissions }) - if (query?.length) { - setFetching(true); - let res = await searchCitizen(_currLocation.villageCode, query, userData.user); - setPrevSubmissions(res?.result?.submissions || []); - setFetching(false); - } else setPrevSubmissions(prevTempSubmissions); - }, 500); - - // useEffect(() => { - // async function searchCitizens() { - // console.log("search query->", searchQuery) - // if (searchQuery?.length) { - // setFetching(true) - // let res = await searchCitizen(_currLocation.villageCode, searchQuery) - // setPrevSubmissions(res?.result?.submissions || []); - // setFetching(false); - // } else setPrevSubmissions(prevTempSubmissions) - // } - // searchCitizens(); - // }, [searchQuery]) - - const getVillageData = async () => { - try { - if (_currLocation?.villageCode) { - let data = await getVillageDetails(_currLocation.villageCode); - if (Object.keys(data?.result)?.length) setVillageData(data?.result); - } - } catch (err) { - console.log(err); - } - }; - const token = useSelector(tokenSelector); - console.log({ token, userData }) - const getVillageSubmissionData = async () => { - try { - if (_currLocation?.villageCode) { - - setFetching(true); - let data = await getVillageSubmissions( - _currLocation.villageCode, - currPage, - token - ); - console.log("PREV SUBMISSIONS -->", data); - setFetching(false); - if (Object.keys(data)?.length) { - setPrevSubmissions(data?.result?.submissions); - setPrevTempSubmissions(data?.result?.submissions); - setTotalPages(data?.result?.totalPages); - } - } - } catch (err) { - console.log(err); - setFetching(false); - } - }; - - const searchCitizenSubmission = useCallback(async (e) => { - setSearchQuery(e.target.value); - dispatch( - updateSearchQuery({ - villageId: _currLocation.villageCode, - query: e.target.value, - }) - ); - - debouncedSearch(e.target.value); - }, []); - - function padTwoDigits(num) { - return num.toString().padStart(2, "0"); - } - - const breadcrumbItems = useMemo(() => ([{ label: "Home", to: "/" }, { label: _currLocation?.villageName, to: "/survey" }, { label: "Submitted Titles" }]), [_currLocation?.villageName]) - return !hydrated ? null : ( -
- - - {/* router.back()} - text={`${_currLocation.villageName}`} - subText={`Completed Entries`} - showLogout={false} - sx={{ - justifyContent: "space-between !important", - padding: "2rem 1rem", - }} - /> */} - -
-
- {!(!fetching && !prevSubmissions?.length && !searchQuery) && - - - ), - }} - />} - {fetching && } - - {!fetching && - prevSubmissions?.length > 0 && - prevSubmissions?.map((el) => ( - { - console.log("sub btn clicked") - }} - leftImage={"/assets/citizen.svg"} - rightImage={"/assets/verified.png"} - mainText={el?.submissionData?.claimantName} - mainSubtext={moment(el?.updatedAt).utcOffset('+0530').format( - "DD MMM YYYY, hh:mm a" - )} - sx={{ background: "#fff", marginTop: '1rem', cursor: 'pointer' }} - mode={1} - imgWidth={'70%'} - onClick={() => { - dispatch(setCurrentCitizen(el)); - router.push(`/citizen-survey`); - }} - /> - ))} - - {!fetching && !prevSubmissions?.length && !searchQuery &&
-

No Records Found

-

Please submit land titles before you access them

-
} -
- {!searchQuery && ( - setCurrPage(page)} - className={styles.paginationContainer} - /> - )} -
-
- ); + const _currLocation = useSelector((state) => state?.userData?.currentLocation); + const [hydrated, setHydrated] = React.useState(false); + + const [currPage, setCurrPage] = React.useState(1); + const [totalPages, setTotalPages] = useState(1); + const [prevSubmissions, setPrevSubmissions] = useState([]); + const [prevTempSubmissions, setPrevTempSubmissions] = useState([]); + const [searchQuery, setSearchQuery] = useState(''); + const [fetching, setFetching] = useState(false); + const router = useRouter(); + const dispatch = useDispatch(); + + /* Use Effects */ + useEffect(() => { + window.scrollTo({ top: 0, behavior: 'smooth' }); + setHydrated(true); + + setSearchQuery(userData?.searchQuery?.[_currLocation.villageCode] || ''); + // getVillageData(); + }, [_currLocation, userData?.searchQuery]); + + const debouncedSearch = debounce(async (query) => { + if (query?.length) { + setFetching(true); + const res = await searchCitizen(_currLocation.villageCode, query, userData.user); + setPrevSubmissions(res?.result?.submissions || []); + setFetching(false); + } else setPrevSubmissions(prevTempSubmissions); + }, 500); + + const token = useSelector(tokenSelector); + + const getVillageSubmissionData = useCallback(async () => { + try { + if (_currLocation?.villageCode) { + setFetching(true); + const data = await getVillageSubmissions(_currLocation.villageCode, currPage, token); + + setFetching(false); + if (Object.keys(data)?.length) { + setPrevSubmissions(data?.result?.submissions); + setPrevTempSubmissions(data?.result?.submissions); + setTotalPages(data?.result?.totalPages); + } + } + } catch (err) { + setFetching(false); + } + }, [_currLocation.villageCode, currPage, token]); + + useEffect(() => { + getVillageSubmissionData(); + }, [currPage, getVillageSubmissionData]); + + const searchCitizenSubmission = useCallback( + async (e) => { + setSearchQuery(e.target.value); + dispatch( + updateSearchQuery({ + villageId: _currLocation.villageCode, + query: e.target.value + }) + ); + + debouncedSearch(e.target.value); + }, + [_currLocation.villageCode, debouncedSearch, dispatch] + ); + + const breadcrumbItems = useMemo( + () => [ + { label: 'Home', to: '/' }, + { label: _currLocation?.villageName, to: '/survey' }, + { label: 'Submitted Titles' } + ], + [_currLocation?.villageName] + ); + return !hydrated ? null : ( +
+ + + +
+
+ {!(!fetching && !prevSubmissions?.length && !searchQuery) && ( + + + + ) + }} + /> + )} + {fetching && } + + {!fetching && + prevSubmissions?.length > 0 && + prevSubmissions?.map((el) => ( + null} + leftImage={'/assets/citizen.svg'} + rightImage={'/assets/verified.png'} + mainText={el?.submissionData?.claimantName} + mainSubtext={moment(el?.updatedAt).format('DD MMM YYYY, hh:mm a')} + sx={{ background: '#fff', marginTop: '5x', cursor: 'pointer' }} + mode={1} + imgWidth={'70%'} + onClick={() => { + dispatch(setCurrentCitizen(el)); + router.push(`/citizen-survey`); + }} + /> + ))} + + {!fetching && !prevSubmissions?.length && !searchQuery && ( +
+

No Records Found

+

+ Please submit land titles before you access them +

+ +
+ )} +
+ {!searchQuery && ( +
+ setCurrPage(page)} + className={styles.paginationContainer} + /> +
+ )} +
+
+ ); }; export default CompletedEntries;