mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-09 17:14:21 +02:00
connect to store ParticipationDetailsForm
This commit is contained in:
parent
4800e12d9f
commit
444582c5cc
@ -1,14 +1,14 @@
|
|||||||
import { FC, memo } from "react"
|
import { FC, memo } from "react"
|
||||||
import DayWishes from "./DayWishes/DayWishes"
|
import DayWishes from "./DayWishes/DayWishes"
|
||||||
import DayWishesFormModal from "./DayWishesForm/DayWishesFormModal"
|
import DayWishesFormModal from "./DayWishesForm/DayWishesFormModal"
|
||||||
import DDayInformations from "./DDayInformations/DDaysInformations"
|
import ParticipationDetailsForm from "./ParticipationDetailsForm/ParticipationDetailsForm"
|
||||||
import withUserConnected from "../../utils/withUserConnected"
|
import withUserConnected from "../../utils/withUserConnected"
|
||||||
|
|
||||||
const Board: FC = (): JSX.Element => (
|
const Board: FC = (): JSX.Element => (
|
||||||
<div>
|
<div>
|
||||||
<DayWishes />
|
<DayWishes />
|
||||||
<DayWishesFormModal />
|
<DayWishesFormModal />
|
||||||
<DDayInformations />
|
<ParticipationDetailsForm />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,76 +0,0 @@
|
|||||||
import { FC, memo, useCallback, useRef, useState } from "react"
|
|
||||||
import styles from "./styles.module.scss"
|
|
||||||
|
|
||||||
const sizes = ["XS", "S", "M", "L", "XL", "XXL"]
|
|
||||||
|
|
||||||
const DDayInformations: FC = (): JSX.Element | null => {
|
|
||||||
const sizeRef = useRef<HTMLSelectElement | null>(null)
|
|
||||||
const dietRef = useRef<HTMLInputElement | null>(null)
|
|
||||||
const ageRef = useRef<HTMLInputElement | null>(null)
|
|
||||||
const commentRef = useRef<HTMLTextAreaElement | null>(null)
|
|
||||||
const [has2Shirts, setHas2Shirts] = useState<boolean | null>(null)
|
|
||||||
|
|
||||||
const onSubmit = useCallback(() => {
|
|
||||||
console.log("on submit")
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const onHas2ShirtsClick = useCallback(
|
|
||||||
(value) => {
|
|
||||||
setHas2Shirts(value)
|
|
||||||
},
|
|
||||||
[setHas2Shirts]
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={styles.ddayInfo}>
|
|
||||||
<div className={styles.ddayTitle}>Informations pour le festival</div>
|
|
||||||
<div className={styles.ddayInfoShirtWrapper}>
|
|
||||||
<div className={styles.ddayShirtLabel}>J'ai déjà 2 t-shirts</div>
|
|
||||||
<label>
|
|
||||||
<input type="radio" name="hasShirt" onClick={() => onHas2ShirtsClick(true)} />{" "}
|
|
||||||
Oui
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
<input type="radio" name="hasShirt" onClick={() => onHas2ShirtsClick(false)} />{" "}
|
|
||||||
Non
|
|
||||||
</label>
|
|
||||||
{has2Shirts === false && (
|
|
||||||
<div className={styles.ddayShirtSizes}>
|
|
||||||
<label>Taille</label>
|
|
||||||
<select ref={sizeRef}>
|
|
||||||
{sizes.map((size) => (
|
|
||||||
<option key={size} value={size}>
|
|
||||||
{size}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className={styles.ddayInfoInputWrapper}>
|
|
||||||
<label htmlFor="ddday-age">Age</label>
|
|
||||||
<input type="number" id="ddday-age" ref={ageRef} />
|
|
||||||
</div>
|
|
||||||
<div className={styles.ddayInfoInputWrapper}>
|
|
||||||
<label htmlFor="dday-diet">Régime alimentaire</label>
|
|
||||||
<input
|
|
||||||
id="dday-diet"
|
|
||||||
type="text"
|
|
||||||
ref={dietRef}
|
|
||||||
placeholder="végétarien ? halal ? ..."
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className={styles.ddayInfoCommentWrapper}>
|
|
||||||
<label htmlFor="dday-comment">Des commentaires ?</label>
|
|
||||||
<textarea id="dday-comment" ref={commentRef} />
|
|
||||||
</div>
|
|
||||||
<div className={styles.ddayButtonWrapper}>
|
|
||||||
<button type="submit" onClick={onSubmit}>
|
|
||||||
Enregistrer
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default memo(DDayInformations)
|
|
@ -1,7 +1,7 @@
|
|||||||
import { FC, memo, useCallback } from "react"
|
import { FC, memo, useCallback } from "react"
|
||||||
import get from "lodash/get"
|
import get from "lodash/get"
|
||||||
import styles from "./styles.module.scss"
|
import styles from "./styles.module.scss"
|
||||||
import { getDayLabel, useUserDayWishes } from "../days.utils"
|
import { getDayLabel, useUserDayWishes } from "../daysWishes.utils"
|
||||||
import useAction from "../../../utils/useAction"
|
import useAction from "../../../utils/useAction"
|
||||||
import { displayModal, MODAL_IDS } from "../../../store/ui"
|
import { displayModal, MODAL_IDS } from "../../../store/ui"
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
daysChoiceSelectionDefaultState,
|
daysChoiceSelectionDefaultState,
|
||||||
selectionChoices,
|
selectionChoices,
|
||||||
useUserDayWishes,
|
useUserDayWishes,
|
||||||
} from "../days.utils"
|
} from "../daysWishes.utils"
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
afterSubmit?: () => void | undefined
|
afterSubmit?: () => void | undefined
|
||||||
|
@ -0,0 +1,99 @@
|
|||||||
|
import { FC, memo, useCallback, useEffect, useRef, useState } from "react"
|
||||||
|
import get from "lodash/get"
|
||||||
|
import set from "lodash/set"
|
||||||
|
import styles from "./styles.module.scss"
|
||||||
|
import { tShirtSizes, useUserParticipationDetails } from "../participationDetails.utils"
|
||||||
|
|
||||||
|
const ParticipationDetailsForm: FC = (): JSX.Element | null => {
|
||||||
|
const sizeRef = useRef<HTMLSelectElement | null>(null)
|
||||||
|
const dietRef = useRef<HTMLInputElement | null>(null)
|
||||||
|
const ageRef = useRef<HTMLInputElement | null>(null)
|
||||||
|
const [has2Shirts, setHas2Shirts] = useState<boolean>(true)
|
||||||
|
|
||||||
|
const [participationDetails, saveParticipationDetails] = useUserParticipationDetails()
|
||||||
|
|
||||||
|
const onSubmit = useCallback(() => {
|
||||||
|
const age = get(ageRef, "current.value", "")
|
||||||
|
const teeshirtSize = has2Shirts ? "" : get(sizeRef, "current.value", "")
|
||||||
|
const food = get(dietRef, "current.value", "")
|
||||||
|
saveParticipationDetails({ age, teeshirtSize, food })
|
||||||
|
}, [has2Shirts, saveParticipationDetails])
|
||||||
|
|
||||||
|
const onHas2ShirtsClick = useCallback(
|
||||||
|
(value) => {
|
||||||
|
setHas2Shirts(value)
|
||||||
|
},
|
||||||
|
[setHas2Shirts]
|
||||||
|
)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log("participationDetails", participationDetails)
|
||||||
|
const age = get(participationDetails, "age", "")
|
||||||
|
const teeshirtSize = get(participationDetails, "teeshirtSize", "")
|
||||||
|
const food = get(participationDetails, "food", "")
|
||||||
|
|
||||||
|
if (age) set(ageRef, "current.value", age)
|
||||||
|
if (teeshirtSize) set(sizeRef, "current.value", teeshirtSize)
|
||||||
|
setHas2Shirts(!teeshirtSize)
|
||||||
|
if (food) set(dietRef, "current.value", food)
|
||||||
|
}, [setHas2Shirts, participationDetails])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.root}>
|
||||||
|
<div className={styles.title}>Informations pour le festival</div>
|
||||||
|
<div className={styles.tShirtWrapper}>
|
||||||
|
<div className={styles.tShirtLabel}>J'ai déjà 2 t-shirts</div>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="hasShirt"
|
||||||
|
onClick={() => onHas2ShirtsClick(true)}
|
||||||
|
checked={has2Shirts}
|
||||||
|
/>{" "}
|
||||||
|
Oui
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="hasShirt"
|
||||||
|
onClick={() => onHas2ShirtsClick(false)}
|
||||||
|
checked={!has2Shirts}
|
||||||
|
/>{" "}
|
||||||
|
Non
|
||||||
|
</label>
|
||||||
|
{has2Shirts === false && (
|
||||||
|
<div className={styles.tShirtSizes}>
|
||||||
|
<label>Taille</label>
|
||||||
|
<select ref={sizeRef}>
|
||||||
|
{tShirtSizes.map((size) => (
|
||||||
|
<option key={size} value={size}>
|
||||||
|
{size}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className={styles.inputWrapper}>
|
||||||
|
<label htmlFor="ddday-age">Age</label>
|
||||||
|
<input type="number" id="ddday-age" ref={ageRef} />
|
||||||
|
</div>
|
||||||
|
<div className={styles.inputWrapper}>
|
||||||
|
<label htmlFor="dday-diet">Préférence alimentaire</label>
|
||||||
|
<input
|
||||||
|
id="dday-diet"
|
||||||
|
type="text"
|
||||||
|
ref={dietRef}
|
||||||
|
placeholder="végétarien ? halal ? ..."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className={styles.buttonWrapper}>
|
||||||
|
<button type="submit" onClick={onSubmit}>
|
||||||
|
Enregistrer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default memo(ParticipationDetailsForm)
|
@ -1,78 +1,62 @@
|
|||||||
@import "../../../theme/variables";
|
@import "../../../theme/variables";
|
||||||
@import "../../../theme/mixins";
|
@import "../../../theme/mixins";
|
||||||
|
|
||||||
.ddayInfo {
|
.root {
|
||||||
width: 470px;
|
width: 470px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ddayTitle {
|
.title {
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ddayInfoInputWrapper {
|
.inputWrapper {
|
||||||
margin: 10px 0;
|
margin: 10px 0;
|
||||||
|
|
||||||
label {
|
label {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 150px;
|
width: 170px;
|
||||||
}
|
}
|
||||||
input {
|
input {
|
||||||
width: 320px;
|
width: 300px;
|
||||||
border: 1px solid $color-grey-medium;
|
border: 1px solid $color-grey-medium;
|
||||||
outline: 0;
|
outline: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ddayInfoShirtWrapper {
|
.tShirtWrapper {
|
||||||
margin: 10px 0;
|
margin: 10px 0;
|
||||||
height: 22px;
|
height: 28px;
|
||||||
|
|
||||||
label {
|
label {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 60px;
|
width: 55px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ddayShirtLabel {
|
.tShirtLabel {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-top: 2px;
|
margin-top: 6px;
|
||||||
width: 150px;
|
width: 170px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ddayShirtSizes {
|
.tShirtSizes {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 200px;
|
width: 190px;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
|
||||||
select {
|
select {
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
width: 60px;
|
width: 120px;
|
||||||
border: 1px solid $color-grey-medium;
|
border: 1px solid $color-grey-medium;
|
||||||
|
border-radius: 4px;
|
||||||
background-color: $color-white;
|
background-color: $color-white;
|
||||||
outline: 0;
|
outline: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ddayInfoCommentWrapper {
|
.buttonWrapper {
|
||||||
margin: 6px 0;
|
|
||||||
|
|
||||||
label {
|
|
||||||
display: block;
|
|
||||||
padding-left: 4px;
|
|
||||||
}
|
|
||||||
textarea {
|
|
||||||
width: 100%;
|
|
||||||
height: 50px;
|
|
||||||
padding: 5px;
|
|
||||||
border: 1px solid $color-grey-light;
|
|
||||||
background-color: $color-grey-lighter;
|
|
||||||
outline: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.ddayButtonWrapper {
|
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
@ -5,9 +5,9 @@ import { AppState } from "../../store"
|
|||||||
import { fetchVolunteerDayWishesSet } from "../../store/volunteerDayWishesSet"
|
import { fetchVolunteerDayWishesSet } from "../../store/volunteerDayWishesSet"
|
||||||
import useAction from "../../utils/useAction"
|
import useAction from "../../utils/useAction"
|
||||||
|
|
||||||
const daysUtils = ["Jeudi", "Vendredi", "Samedi", "Dimanche", "Lundi"]
|
const daysWishesUtils = ["Jeudi", "Vendredi", "Samedi", "Dimanche", "Lundi"]
|
||||||
|
|
||||||
export const daysChoice = daysUtils.map((label) => ({
|
export const daysChoice = daysWishesUtils.map((label) => ({
|
||||||
id: label[0],
|
id: label[0],
|
||||||
label,
|
label,
|
||||||
}))
|
}))
|
43
src/components/VolunteerBoard/participationDetails.utils.ts
Normal file
43
src/components/VolunteerBoard/participationDetails.utils.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import { useCallback } from "react"
|
||||||
|
import { shallowEqual, useSelector } from "react-redux"
|
||||||
|
import useAction from "../../utils/useAction"
|
||||||
|
import { selectUserJwtToken } from "../../store/auth"
|
||||||
|
import { AppState } from "../../store"
|
||||||
|
import { fetchVolunteerParticipationDetailsSet } from "../../store/volunteerParticipationDetailsSet"
|
||||||
|
|
||||||
|
export const tShirtSizes = [
|
||||||
|
"XS",
|
||||||
|
"S",
|
||||||
|
"M",
|
||||||
|
"L",
|
||||||
|
"XL",
|
||||||
|
"XXL",
|
||||||
|
"Femme S",
|
||||||
|
"Femme M",
|
||||||
|
"Femme L",
|
||||||
|
"Femme XL",
|
||||||
|
]
|
||||||
|
|
||||||
|
export const useUserParticipationDetails = (): [any, any] => {
|
||||||
|
const save = useAction(fetchVolunteerParticipationDetailsSet)
|
||||||
|
const jwtToken = useSelector(selectUserJwtToken)
|
||||||
|
const userParticipationDetails = useSelector(
|
||||||
|
(state: AppState) => state.volunteerParticipationDetailsSet?.entity,
|
||||||
|
shallowEqual
|
||||||
|
)
|
||||||
|
|
||||||
|
const saveParticipationDetails = useCallback(
|
||||||
|
({ age, teeshirtSize, food }) => {
|
||||||
|
if (!userParticipationDetails) return
|
||||||
|
save(jwtToken, 0, {
|
||||||
|
id: userParticipationDetails.id,
|
||||||
|
age,
|
||||||
|
teeshirtSize,
|
||||||
|
food,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
[userParticipationDetails, save, jwtToken]
|
||||||
|
)
|
||||||
|
|
||||||
|
return [userParticipationDetails, saveParticipationDetails]
|
||||||
|
}
|
@ -7,6 +7,7 @@ import { fetchVolunteerDayWishesSetIfNeed } from "../../store/volunteerDayWishes
|
|||||||
import { selectUserJwtToken } from "../../store/auth"
|
import { selectUserJwtToken } from "../../store/auth"
|
||||||
import Page from "../../components/Page/Page"
|
import Page from "../../components/Page/Page"
|
||||||
import Board from "../../components/VolunteerBoard/Board"
|
import Board from "../../components/VolunteerBoard/Board"
|
||||||
|
import { fetchVolunteerParticipationDetailsSetIfNeed } from "../../store/volunteerParticipationDetailsSet"
|
||||||
|
|
||||||
export type Props = RouteComponentProps
|
export type Props = RouteComponentProps
|
||||||
|
|
||||||
@ -25,6 +26,9 @@ const BoardPage: FC<Props> = (): JSX.Element => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch server-side data here
|
// Fetch server-side data here
|
||||||
export const loadData = (): AppThunk[] => [fetchVolunteerDayWishesSetIfNeed()]
|
export const loadData = (): AppThunk[] => [
|
||||||
|
fetchVolunteerDayWishesSetIfNeed(),
|
||||||
|
fetchVolunteerParticipationDetailsSetIfNeed(),
|
||||||
|
]
|
||||||
|
|
||||||
export default memo(BoardPage)
|
export default memo(BoardPage)
|
||||||
|
@ -6,7 +6,7 @@ import { AppThunk } from "../../store"
|
|||||||
import { fetchVolunteerDayWishesSetIfNeed } from "../../store/volunteerDayWishesSet"
|
import { fetchVolunteerDayWishesSetIfNeed } from "../../store/volunteerDayWishesSet"
|
||||||
import { selectUserJwtToken } from "../../store/auth"
|
import { selectUserJwtToken } from "../../store/auth"
|
||||||
import DayWishesForm from "../../components/VolunteerBoard/DayWishesForm/DayWishesForm"
|
import DayWishesForm from "../../components/VolunteerBoard/DayWishesForm/DayWishesForm"
|
||||||
import DDayInformations from "../../components/VolunteerBoard/DDayInformations/DDaysInformations"
|
import DDayInformations from "../../components/VolunteerBoard/ParticipationDetailsForm/ParticipationDetailsForm"
|
||||||
import styles from "./styles.module.scss"
|
import styles from "./styles.module.scss"
|
||||||
|
|
||||||
export type Props = RouteComponentProps
|
export type Props = RouteComponentProps
|
||||||
|
@ -13,8 +13,9 @@ button {
|
|||||||
input[type="text"],
|
input[type="text"],
|
||||||
input[type="password"],
|
input[type="password"],
|
||||||
input[type="number"],
|
input[type="number"],
|
||||||
input[type="email"] {
|
input[type="email"],
|
||||||
|
select {
|
||||||
padding: 4px 6px;
|
padding: 4px 6px;
|
||||||
border: 1px solid #333;
|
border: 1px solid $color-grey-medium;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user