inject saved comment in form

This commit is contained in:
memeriau 2022-01-24 20:16:29 +01:00
parent f890ab505b
commit 7a7935c500

View File

@ -1,6 +1,7 @@
import { FC, memo, useCallback, useEffect, useRef, useState } from "react" import { FC, memo, useCallback, useEffect, useRef, useState } from "react"
import classnames from "classnames" import classnames from "classnames"
import get from "lodash/get" import get from "lodash/get"
import set from "lodash/set"
import styles from "./styles.module.scss" import styles from "./styles.module.scss"
import { import {
daysChoice, daysChoice,
@ -16,6 +17,7 @@ const DayWishes: FC = (): JSX.Element | null => {
useEffect(() => { useEffect(() => {
if (!userWishes) return if (!userWishes) return
console.log("userWishes", userWishes)
const newSelection = get(userWishes, "dayWishes", []).reduce( const newSelection = get(userWishes, "dayWishes", []).reduce(
(acc: selectionChoices, day: string) => ({ (acc: selectionChoices, day: string) => ({
...acc, ...acc,
@ -24,7 +26,8 @@ const DayWishes: FC = (): JSX.Element | null => {
daysChoice daysChoice
) )
setSelection(newSelection) setSelection(newSelection)
}, [setSelection, userWishes]) set(commentRef, "current.value", get(userWishes, "dayWishesComment", ""))
}, [setSelection, commentRef, userWishes])
const onChoiceClick = useCallback( const onChoiceClick = useCallback(
(id) => { (id) => {