generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #787 from ita-social-projects/fix-null-tox-in-daug…
…hter-component fix tox in streetcode edit window
- Loading branch information
Showing
3 changed files
with
42 additions
and
5 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
38 changes: 34 additions & 4 deletions
38
src/features/AdminPage/NewStreetcode/TextBlock/TextBlock.component.tsx
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,21 +1,51 @@ | ||
/* eslint-disable no-restricted-imports */ | ||
import React from 'react'; | ||
import React, {useEffect, useState} from 'react'; | ||
|
||
import Video from '@/models/media/video.model'; | ||
import { Text } from '@/models/streetcode/text-contents.model'; | ||
|
||
import TextForm from './TextForm/TextForm.component'; | ||
import {useAsync} from "@hooks/stateful/useAsync.hook"; | ||
import TextsApi from "@api/streetcode/text-content/texts.api"; | ||
|
||
interface Props { | ||
inputInfo: Partial<Text> | undefined; | ||
setInputInfo: React.Dispatch<React.SetStateAction<Partial<Text> | undefined>>; | ||
video: Video | undefined; | ||
setVideo: React.Dispatch<Video | undefined>; | ||
onChange: (fieldName: string, value: any) => void; | ||
parseId: number | ||
} | ||
|
||
const TextBlock = React.memo(({ inputInfo, setInputInfo, video, setVideo, onChange }: Props) => ( | ||
<TextForm inputInfo={inputInfo} setInputInfo={setInputInfo} video={video} setVideo={setVideo} onChange={onChange} /> | ||
)); | ||
const TextBlock = React.memo(({ | ||
inputInfo, setInputInfo, video, setVideo, onChange, parseId, | ||
}: Props) => { | ||
const [inputInfoAsync, setInputInfoAsync] = useState<Partial<Text>>(); | ||
useAsync(() => { | ||
if(parseId != null) { | ||
TextsApi.getByStreetcodeId(parseId).then((result) => { | ||
setInputInfoAsync(result); | ||
}); | ||
} | ||
}, [parseId]); | ||
|
||
useEffect(() => { | ||
setInputInfo(inputInfoAsync); | ||
}, [inputInfoAsync]); | ||
|
||
return ( | ||
inputInfoAsync !== null | ||
? ( | ||
<TextForm | ||
inputInfo={inputInfoAsync} | ||
setInputInfo={setInputInfoAsync} | ||
video={video} | ||
setVideo={setVideo} | ||
onChange={onChange} | ||
/> | ||
) | ||
: <></> | ||
); | ||
}); | ||
|
||
export default TextBlock; |
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