Skip to content

Commit

Permalink
fix: redownload data on tab click for units and projects
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Dec 4, 2023
1 parent 8520652 commit 3cc44f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/pages/Projects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,16 @@ const Projects = withTheme(({ theme }) => {
[setTabValue],
);

useEffect(() => {
const fetchProject = () => {
const projectId = searchParams.get('projectId');
if (projectId) {
dispatch(getProjectData(projectId));
dispatch(getStagingData({ useMockedResponse: false }));
}
};

useEffect(() => {
fetchProject();
return () => dispatch(clearProjectData());
}, [searchParams.get('projectId')]);

Expand Down Expand Up @@ -459,30 +464,37 @@ const Projects = withTheme(({ theme }) => {
)}
<StyledSubHeaderContainer>
<Tabs value={tabValue} onChange={handleTabChange}>
<Tab label={intl.formatMessage({ id: 'committed' })} />
<Tab
onClick={fetchProject}
label={intl.formatMessage({ id: 'committed' })}
/>
{pageIsMyRegistryPage && (
<Tab
onClick={fetchProject}
label={`${intl.formatMessage({ id: 'staging' })} (${
totalNumberOfEntries && totalNumberOfEntries.projects.staging
})`}
/>
)}
{pageIsMyRegistryPage && (
<Tab
onClick={fetchProject}
label={`${intl.formatMessage({ id: 'pending' })} (${
pendingProjects.length
})`}
/>
)}
{pageIsMyRegistryPage && (
<Tab
onClick={fetchProject}
label={`${intl.formatMessage({ id: 'failed' })} (${
totalNumberOfEntries && totalNumberOfEntries.projects.failed
})`}
/>
)}
{pageIsMyRegistryPage && (
<Tab
onClick={fetchProject}
label={`${intl.formatMessage({ id: 'offers' })} (${
pendingTransferOffers.length
})`}
Expand Down
14 changes: 12 additions & 2 deletions src/pages/Units/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,15 @@ const Units = withTheme(({ theme }) => {
[setTabValue],
);

useEffect(() => {
const fetchUnits = () => {
const unitId = searchParams.get('unitId');
if (unitId) {
dispatch(getUnitData(unitId));
}
};

useEffect(() => {
fetchUnits();
return () => dispatch(clearUnitData());
}, [searchParams.get('unitId')]);

Expand Down Expand Up @@ -395,23 +399,29 @@ const Units = withTheme(({ theme }) => {
</StyledHeaderContainer>
<StyledSubHeaderContainer>
<Tabs value={tabValue} onChange={handleTabChange}>
<Tab label={intl.formatMessage({ id: 'committed' })} />
<Tab
onClick={fetchUnits}
label={intl.formatMessage({ id: 'committed' })}
/>
{pageIsMyRegistryPage && (
<Tab
onClick={fetchUnits}
label={`${intl.formatMessage({ id: 'staging' })} (${
totalNumberOfEntries && totalNumberOfEntries.units.staging
})`}
/>
)}
{pageIsMyRegistryPage && (
<Tab
onClick={fetchUnits}
label={`${intl.formatMessage({ id: 'pending' })} (${
totalNumberOfEntries && totalNumberOfEntries.units.pending
})`}
/>
)}
{pageIsMyRegistryPage && (
<Tab
onClick={fetchUnits}
label={`${intl.formatMessage({ id: 'failed' })} (${
totalNumberOfEntries && totalNumberOfEntries.units.failed
})`}
Expand Down

0 comments on commit 3cc44f8

Please sign in to comment.