@@ -2,16 +2,19 @@ import {
22 useCallback ,
33 useMemo ,
44} from 'react' ;
5+ import { useParams } from 'react-router-dom' ;
56import {
67 BooleanInput ,
78 Container ,
89 DateInput ,
910 InputSection ,
1011 RadioInput ,
1112 TextInput ,
13+ TextOutput ,
1214} from '@ifrc-go/ui' ;
1315import { useTranslation } from '@ifrc-go/ui/hooks' ;
1416import {
17+ isDefined ,
1518 isNotDefined ,
1619 isTruthyString ,
1720} from '@togglecorp/fujs' ;
@@ -36,6 +39,7 @@ import {
3639} from '#utils/constants' ;
3740
3841import { type PartialFormValue } from '../common' ;
42+ import TitlePreview from './TitlePreview' ;
3943
4044import i18n from './i18n.json' ;
4145import styles from './styles.module.css' ;
@@ -70,6 +74,7 @@ function ContextFields(props: Props) {
7074 } = props ;
7175
7276 const strings = useTranslation ( i18n ) ;
77+ const { fieldReportId } = useParams < { fieldReportId : string } > ( ) ;
7378
7479 const {
7580 api_field_report_status,
@@ -298,16 +303,27 @@ function ContextFields(props: Props) {
298303 disabled = { disabled }
299304 withAsterisk
300305 />
301- { isTruthyString ( value . summary ) && (
302- < TextInput
303- label = { strings . originalTitleSecondaryLabel }
304- name = "summary"
305- value = { value . summary }
306- onChange = { onValueChange }
307- error = { error ?. summary }
308- disabled
309- />
310- ) }
306+ { isDefined ( value . country )
307+ && isDefined ( value . dtype )
308+ && isDefined ( value . title )
309+ && isTruthyString ( value . title . trim ( ) )
310+ ? (
311+ < TitlePreview
312+ country = { value . country }
313+ disasterType = { value . dtype }
314+ event = { value . event }
315+ isCovidReport = { value . is_covid_report }
316+ startDate = { value . start_date }
317+ title = { value . title }
318+ />
319+ ) : (
320+ < TextOutput
321+ value = { value . summary }
322+ label = { isDefined ( fieldReportId )
323+ ? strings . originalTitle : strings . generatedTitlePreview }
324+ strongLabel
325+ />
326+ ) }
311327 </ >
312328 ) }
313329 </ InputSection >
0 commit comments