mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-08 08:34:20 +02:00
create user Board component and withUserConnected hoc
This commit is contained in:
parent
b842174ebe
commit
4800e12d9f
15
src/components/VolunteerBoard/Board.tsx
Normal file
15
src/components/VolunteerBoard/Board.tsx
Normal file
@ -0,0 +1,15 @@
|
||||
import { FC, memo } from "react"
|
||||
import DayWishes from "./DayWishes/DayWishes"
|
||||
import DayWishesFormModal from "./DayWishesForm/DayWishesFormModal"
|
||||
import DDayInformations from "./DDayInformations/DDaysInformations"
|
||||
import withUserConnected from "../../utils/withUserConnected"
|
||||
|
||||
const Board: FC = (): JSX.Element => (
|
||||
<div>
|
||||
<DayWishes />
|
||||
<DayWishesFormModal />
|
||||
<DDayInformations />
|
||||
</div>
|
||||
)
|
||||
|
||||
export default memo(withUserConnected(Board))
|
@ -5,10 +5,8 @@ import { useSelector } from "react-redux"
|
||||
import { AppThunk } from "../../store"
|
||||
import { fetchVolunteerDayWishesSetIfNeed } from "../../store/volunteerDayWishesSet"
|
||||
import { selectUserJwtToken } from "../../store/auth"
|
||||
import DDayInformations from "../../components/VolunteerBoard/DDayInformations/DDaysInformations"
|
||||
import DayWishes from "../../components/VolunteerBoard/DayWishes/DayWishes"
|
||||
import DayWishesFormModal from "../../components/VolunteerBoard/DayWishesForm/DayWishesFormModal"
|
||||
import Page from "../../components/Page/Page"
|
||||
import Board from "../../components/VolunteerBoard/Board"
|
||||
|
||||
export type Props = RouteComponentProps
|
||||
|
||||
@ -19,9 +17,7 @@ const BoardPage: FC<Props> = (): JSX.Element => {
|
||||
if (jwtToken) {
|
||||
return (
|
||||
<Page>
|
||||
<DayWishes />
|
||||
<DayWishesFormModal />
|
||||
<DDayInformations />
|
||||
<Board />
|
||||
</Page>
|
||||
)
|
||||
}
|
||||
|
12
src/utils/withUserConnected.tsx
Normal file
12
src/utils/withUserConnected.tsx
Normal file
@ -0,0 +1,12 @@
|
||||
import React from "react"
|
||||
import { useSelector } from "react-redux"
|
||||
import { isUserConnected } from "../store/auth"
|
||||
|
||||
function withUserConnected<T>(Component: React.ComponentType<T>) {
|
||||
return (props: T): JSX.Element | null => {
|
||||
const connected = useSelector(isUserConnected)
|
||||
return connected ? <Component {...props} /> : null
|
||||
}
|
||||
}
|
||||
|
||||
export default withUserConnected
|
Loading…
x
Reference in New Issue
Block a user