Skip to content

Commit

Permalink
feat: added topicGroupId to RegistrationProvider
Browse files Browse the repository at this point in the history
- corrected bug where it would open unselected accordions if the topicIds matched
- added topicGroup to onOverlayOpen
  • Loading branch information
pnboliveira committed Mar 4, 2024
1 parent fc1e3ce commit 492a222
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/components/registration/topicSelection/TopicSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ export const TopicSelection: VFC<{
const [topics, setTopics] = useState<TopicsDataInterface[]>([]);
const [isLoading, setIsLoading] = useState<boolean>(false);
const [listView, setListView] = useState<boolean>(false);
const [topicGroupId, setTopicGroupId] = useState<number>(0);
const [topicGroupId, setTopicGroupId] = useState<number>(
sessionStorageRegistrationData.topicGroupId || undefined
);

const getTopic = (mainTopicId: number) => {
return topics?.filter((topic) => topic?.id === mainTopicId)?.[0];
};

const getTopicInteraction = (topicGroupId: number) => {
setTopicGroupId(topicGroupId);
};

useEffect(() => {
if (
REGISTRATION_DATA_VALIDATION.mainTopicId.validation(
Expand Down Expand Up @@ -260,9 +258,11 @@ export const TopicSelection: VFC<{
))
: topicGroups.map((topicGroup) => (
<Accordion
defaultExpanded={topicGroup.topicIds.includes(
value
)}
defaultExpanded={
topicGroup.topicIds.includes(
value
) && topicGroup.id === topicGroupId
}
sx={{
'boxShadow': 'none',
'borderBottom': '1px solid #dddddd',
Expand Down Expand Up @@ -346,15 +346,17 @@ export const TopicSelection: VFC<{
setValue(
topic.id
);
setTopicGroupId(
topicGroup.id
);
setDataForSessionStorage(
{
mainTopicId:
topic?.id
topic?.id,
topicGroupId:
topicGroup?.id
}
);
getTopicInteraction(
topicGroup.id
);
}}
checked={
value ===
Expand Down Expand Up @@ -408,20 +410,25 @@ export const TopicSelection: VFC<{
setDataForSessionStorage(
{
mainTopicId:
topic.id
topic.id,
topicGroupId:
topicGroup.id
}
);
setValue(
topic.id
);
setTopicGroupId(
topicGroup.id
);
}}
/>
)}
</Box>
))}
</AccordionDetails>
</Accordion>
))}
))}
</RadioGroup>
</FormControl>
)}
Expand Down
1 change: 1 addition & 0 deletions src/globalState/provider/RegistrationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface RegistrationSessionStorageData {
password: string;
agencyId: number;
mainTopicId: number;
topicGroupId?: number;
topicId?: number;
zipcode: string;
}
Expand Down

0 comments on commit 492a222

Please sign in to comment.