generated from kubefirst/react-app-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7de1c4b
commit e2d1b07
Showing
5 changed files
with
61 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,26 @@ | ||
import React, { FunctionComponent } from 'react'; | ||
import React, { FunctionComponent, useEffect } from 'react'; | ||
|
||
import { setSelectedCluster } from '../../redux/slices/cluster.slice'; | ||
import { getClusters } from '../../redux/thunks/api.thunk'; | ||
import { useAppDispatch, useAppSelector } from '../../redux/store'; | ||
|
||
import { Container } from './header.styled'; | ||
|
||
const Header: FunctionComponent = () => <Container />; | ||
const Header: FunctionComponent = () => { | ||
const dispatch = useAppDispatch(); | ||
const { managementCluster } = useAppSelector(({ api }) => api); | ||
|
||
useEffect(() => { | ||
dispatch(getClusters()); | ||
}, [dispatch]); | ||
|
||
useEffect(() => { | ||
if (managementCluster && managementCluster.id) { | ||
dispatch(setSelectedCluster(managementCluster)); | ||
} | ||
}, [dispatch, managementCluster]); | ||
|
||
return <Container />; | ||
}; | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,36 @@ | ||
import Provision from './provision'; | ||
import React, { FunctionComponent, useEffect } from 'react'; | ||
import { useRouter } from 'next/router'; | ||
|
||
import { useAppDispatch, useAppSelector } from '../redux/store'; | ||
import { getClusters } from '../redux/thunks/api.thunk'; | ||
import withConfig from '../hoc/withConfig'; | ||
import { setSelectedCluster } from '../redux/slices/cluster.slice'; | ||
export { getServerSideProps } from '../hoc/withConfig'; | ||
|
||
export default Provision; | ||
const MainPage: FunctionComponent = () => { | ||
const dispatch = useAppDispatch(); | ||
const { push } = useRouter(); | ||
|
||
const { managementCluster } = useAppSelector(({ api }) => api); | ||
|
||
useEffect(() => { | ||
dispatch(getClusters()) | ||
.unwrap() | ||
.then(() => { | ||
push('/services'); | ||
}) | ||
.catch(() => { | ||
push('/provision'); | ||
}); | ||
}, [dispatch, push]); | ||
|
||
useEffect(() => { | ||
if (managementCluster && managementCluster.id) { | ||
dispatch(setSelectedCluster(managementCluster)); | ||
} | ||
}, [dispatch, managementCluster]); | ||
|
||
return null; | ||
}; | ||
|
||
export default withConfig(MainPage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters