From 45edecef6eafbe81527f574cefe1fb2893005ca2 Mon Sep 17 00:00:00 2001 From: Rushikesh-Sonawane99 Date: Tue, 23 Jul 2024 11:35:29 +0530 Subject: [PATCH 1/2] Issue #PS-1254 chore: Stored stateCode and districtCode in zustand --- src/pages/centers/[cohortId].tsx | 10 ++++++++++ src/store/manageUserStore.js | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/src/pages/centers/[cohortId].tsx b/src/pages/centers/[cohortId].tsx index 9ba11eb6..e6d80e8a 100644 --- a/src/pages/centers/[cohortId].tsx +++ b/src/pages/centers/[cohortId].tsx @@ -39,6 +39,7 @@ import { useRouter } from 'next/router'; import { useTheme } from '@mui/material/styles'; import { useTranslation } from 'next-i18next'; import CohortFacilitatorList from '@/components/CohortFacilitatorList'; +import manageUserStore from '@/store/manageUserStore'; const TeachingCenterDetails = () => { const [value, setValue] = React.useState(1); @@ -47,6 +48,11 @@ const TeachingCenterDetails = () => { const router = useRouter(); const { cohortId }: any = router.query; const { t } = useTranslation(); + const store = manageUserStore(); + const setDistrictCode = manageUserStore( + (state: { setDistrictCode: any }) => state.setDistrictCode + ); + const setStateCode = manageUserStore((state: { setStateCode: any }) => state.setStateCode); const [open, setOpen] = React.useState(false); const theme = useTheme(); const [selectedDate, setSelectedDate] = @@ -89,9 +95,13 @@ const TeachingCenterDetails = () => { const district = cohortData.customField.find( (item: CustomField) => item.label === 'District' ); + const districtCode = district?.code || ''; + setDistrictCode(districtCode); const state = cohortData.customField.find( (item: CustomField) => item.label === 'State' ); + const stateCode = state?.code || ''; + setStateCode(stateCode) cohortData.address = `${toPascalCase(district?.value)}, ${toPascalCase(state?.value)}` || diff --git a/src/store/manageUserStore.js b/src/store/manageUserStore.js index d500dac2..b4566592 100644 --- a/src/store/manageUserStore.js +++ b/src/store/manageUserStore.js @@ -6,8 +6,14 @@ const manageUserStore = create( (set) => ({ deleteId: '', learnerDeleteId: '', + blockCode: '', + districtCode: '', + stateCode: '', setCohortDeleteId: (newCohortDeleteId) => set((state) => ({ deleteId: newCohortDeleteId })), setCohortLearnerDeleteId: (newCohortLearnerDeleteId) => set((state) => ({ learnerDeleteId: newCohortLearnerDeleteId })), + setBlockCode: (newBlockCode) => set(() => ({ blockCode: newBlockCode })), + setDistrictCode: (newDistrictCode) => set(() => ({ districtCode: newDistrictCode })), + setStateCode: (newStateCode) => set(() => ({ stateCode: newStateCode })) }), { name: 'teacherApp', From 95c085f1b9b6da6d89ee3360f48a0c5706b72d24 Mon Sep 17 00:00:00 2001 From: Rushikesh-Sonawane99 Date: Tue, 23 Jul 2024 12:37:54 +0530 Subject: [PATCH 2/2] Issue #PS-1254 chore: Stored stateId and districtId in zustand --- src/pages/centers/[cohortId].tsx | 9 +++++++++ src/store/manageUserStore.js | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/pages/centers/[cohortId].tsx b/src/pages/centers/[cohortId].tsx index e6d80e8a..507c6955 100644 --- a/src/pages/centers/[cohortId].tsx +++ b/src/pages/centers/[cohortId].tsx @@ -52,7 +52,12 @@ const TeachingCenterDetails = () => { const setDistrictCode = manageUserStore( (state: { setDistrictCode: any }) => state.setDistrictCode ); + const setDistrictId = manageUserStore( + (state: { setDistrictId: any }) => state.setDistrictId + ); const setStateCode = manageUserStore((state: { setStateCode: any }) => state.setStateCode); + const setStateId = manageUserStore((state: { setStateId: any }) => state.setStateId); + const [open, setOpen] = React.useState(false); const theme = useTheme(); const [selectedDate, setSelectedDate] = @@ -97,11 +102,15 @@ const TeachingCenterDetails = () => { ); const districtCode = district?.code || ''; setDistrictCode(districtCode); + const districtId = district?.fieldId || ''; + setDistrictId(districtId); const state = cohortData.customField.find( (item: CustomField) => item.label === 'State' ); const stateCode = state?.code || ''; setStateCode(stateCode) + const stateId = state?.fieldId || ''; + setStateId(stateId); cohortData.address = `${toPascalCase(district?.value)}, ${toPascalCase(state?.value)}` || diff --git a/src/store/manageUserStore.js b/src/store/manageUserStore.js index b4566592..524c4179 100644 --- a/src/store/manageUserStore.js +++ b/src/store/manageUserStore.js @@ -9,11 +9,17 @@ const manageUserStore = create( blockCode: '', districtCode: '', stateCode: '', + blockId: '', + districtId: '', + stateId: '', setCohortDeleteId: (newCohortDeleteId) => set((state) => ({ deleteId: newCohortDeleteId })), setCohortLearnerDeleteId: (newCohortLearnerDeleteId) => set((state) => ({ learnerDeleteId: newCohortLearnerDeleteId })), setBlockCode: (newBlockCode) => set(() => ({ blockCode: newBlockCode })), setDistrictCode: (newDistrictCode) => set(() => ({ districtCode: newDistrictCode })), - setStateCode: (newStateCode) => set(() => ({ stateCode: newStateCode })) + setStateCode: (newStateCode) => set(() => ({ stateCode: newStateCode })), + setBlockId: (newBlockId) => set(() => ({ blockId: newBlockId })), + setDistrictId: (newDistrictId) => set(() => ({ districtId: newDistrictId })), + setStateId: (newStateId) => set(() => ({ stateId: newStateId })) }), { name: 'teacherApp',