Skip to content

Commit cc84fd9

Browse files
Merge pull request #4059 from beckn/bugfix/krushna/issue-4027/cache-issue
fix(deg-retail): fixed cache issue while logout and when user comes to home page
2 parents b36de34 + ab7b770 commit cc84fd9

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

apps/deg-rental/pages/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { setNavigationType } from '@store/navigation-slice'
2424
import { AuthRootState } from '@store/auth-slice'
2525
import { UserRootState } from '@store/user-slice'
2626
import OpenWalletBottomModal from '@components/modal/OpenWalletBottomModal'
27+
import { clearCache } from '@utils/indexedDB'
2728

2829
const MyStore = () => {
2930
const [startDate, setStartDate] = useState<string>(roundToNextHour(new Date()).toISOString())
@@ -71,6 +72,10 @@ const MyStore = () => {
7172
}
7273
}, [user, shouldShowInitialAlert])
7374

75+
useEffect(() => {
76+
clearCache().catch(console.error)
77+
}, [])
78+
7479
const navigateToSearchResults = useCallback(
7580
(searchByRentingCapacity: boolean = false) => {
7681
if (searchByRentingCapacity || searchTerm) {

apps/deg-rental/pages/profile.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ROLE, ROUTE_TYPE } from '@lib/config'
2121
import { AuthRootState } from '@store/auth-slice'
2222
import { useRouter } from 'next/router'
2323
import { InputProps } from '@beckn-ui/molecules'
24+
import { clearCache } from '@utils/indexedDB'
2425
// import { clearCache } from '@utils/indexedDB'
2526

2627
const ProfilePage = () => {
@@ -259,7 +260,7 @@ const ProfilePage = () => {
259260
handleClick={async () => {
260261
try {
261262
// Clear IndexedDB first
262-
// await clearCache()
263+
await clearCache()
263264
// Then dispatch logout action
264265
dispatch(logout())
265266
} catch (error) {

apps/deg-retail/pages/myStore.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { MdOutlineKeyboardArrowRight } from 'react-icons/md'
99
import ShadowCardButton from '@components/buttonCard/ShadowCardButton'
1010
import { useDispatch, useSelector } from 'react-redux'
1111
import { RootState } from '@store/index'
12+
import { clearCache } from '@utils/indexedDB'
1213

1314
const MyStore = () => {
1415
const router = useRouter()
@@ -46,6 +47,11 @@ const MyStore = () => {
4647
e.preventDefault()
4748
}
4849
const homeButtonName = type === 'RENT_AND_HIRE' ? 'Go Back' : 'Go Back Home'
50+
51+
useEffect(() => {
52+
clearCache().catch(console.error)
53+
}, [])
54+
4955
return (
5056
<Box
5157
className="myStore-homepage"

apps/deg-retail/pages/profile.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const ProfilePage = () => {
3535
customerId: '',
3636
address: ''
3737
})
38-
const [formErrors, setFormErrors] = useState<FormErrors>({
38+
const [formErrors, setFormErrors] = useState<FormErrors & { [key: string]: string }>({
3939
name: '',
4040
customerId: '',
4141
address: ''
@@ -62,7 +62,7 @@ const ProfilePage = () => {
6262
[name]: value
6363
}
6464

65-
const errors = profileValidateForm(updatedFormData) as any
65+
const errors = profileValidateForm(updatedFormData) as Record<string, string>
6666
setFormErrors(prevErrors => ({
6767
...prevErrors,
6868
[name]: t[`${errors[name]}`] || ''
@@ -84,7 +84,7 @@ const ProfilePage = () => {
8484
const result = response.data.agent
8585

8686
console.log(result)
87-
const { first_name, last_name, address, agent_profile } = result
87+
const { first_name, agent_profile } = result
8888
setFormData({
8989
...formData,
9090
name: `${first_name}`,
@@ -102,13 +102,16 @@ const ProfilePage = () => {
102102
if (formData.name === '' || formData.address === '') {
103103
return
104104
}
105-
const errors = profileValidateForm(formData) as any
105+
const errors = profileValidateForm(formData) as Record<string, string>
106106
setFormErrors(prevErrors => ({
107107
...prevErrors,
108-
...Object.keys(errors).reduce((acc: any, key) => {
109-
acc[key] = t[`${errors[key]}`] || ''
110-
return acc
111-
}, {} as FormErrors)
108+
...Object.keys(errors).reduce(
109+
(acc, key) => {
110+
;(acc as Record<string, string>)[key] = t[`${errors[key]}`] || ''
111+
return acc
112+
},
113+
{ ...prevErrors } as Record<string, string>
114+
)
112115
}))
113116

114117
const data = {
@@ -247,7 +250,7 @@ const ProfilePage = () => {
247250
handleClick={async () => {
248251
try {
249252
// Clear IndexedDB first
250-
// await clearCache()
253+
await clearCache()
251254
// Then dispatch logout action
252255
dispatch(logout())
253256
} catch (error) {

0 commit comments

Comments
 (0)