@@ -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' ;
@@ -54,10 +58,6 @@ interface Props {
5458 setDistrictOptions : React . Dispatch < React . SetStateAction < DistrictItem [ ] | null | undefined > > ;
5559 setEventOptions : React . Dispatch < React . SetStateAction < EventItem [ ] | null | undefined > > ;
5660 disabled ?: boolean ;
57-
58- fieldReportId : string | undefined ;
59- titlePrefix : string | undefined ;
60- titleSuffix : string | undefined ;
6161}
6262
6363function ContextFields ( props : Props ) {
@@ -71,12 +71,10 @@ function ContextFields(props: Props) {
7171 setDistrictOptions,
7272 setEventOptions,
7373 disabled,
74- titlePrefix,
75- titleSuffix,
76- fieldReportId,
7774 } = props ;
7875
7976 const strings = useTranslation ( i18n ) ;
77+ const { fieldReportId } = useParams < { fieldReportId : string } > ( ) ;
8078
8179 const {
8280 api_field_report_status,
@@ -171,16 +169,7 @@ function ContextFields(props: Props) {
171169 [ onValueChange , value . dtype ] ,
172170 ) ;
173171
174- const prefixVisible = ! fieldReportId && isTruthyString ( titlePrefix ) ;
175172 const summaryVisible = ! value . is_covid_report ;
176- const suffixVisible = ! fieldReportId && isTruthyString ( titleSuffix ) ;
177-
178- const preferredColumnNoForSummary = Math . max (
179- ( prefixVisible ? 1 : 0 )
180- + ( summaryVisible ? 1 : 0 )
181- + ( suffixVisible ? 1 : 0 ) ,
182- 1 ,
183- ) as 1 | 2 | 3 ;
184173
185174 return (
186175 < Container
@@ -299,37 +288,43 @@ function ContextFields(props: Props) {
299288 title = { strings . summaryLabel }
300289 description = { strings . summaryDescription }
301290 withAsteriskOnTitle
302- numPreferredColumns = { preferredColumnNoForSummary }
291+ numPreferredColumns = { 1 }
303292 >
304- { prefixVisible && (
305- < TextInput
306- label = { summaryVisible ? strings . fieldPrefix : strings . titleSecondaryLabel }
307- name = { undefined }
308- value = { titlePrefix }
309- onChange = { ( ) => { } }
310- />
311- ) }
312293 { summaryVisible && (
313- < TextInput
314- label = { strings . titleSecondaryLabel }
315- placeholder = { strings . titleInputPlaceholder }
316- name = "summary"
317- value = { value . summary }
318- maxLength = { 256 }
319- onChange = { onValueChange }
320- error = { error ?. summary }
321- disabled = { disabled }
322- withAsterisk
323- />
324- ) }
325- { suffixVisible && (
326- < TextInput
327- label = { strings . fieldReportFormSuffix }
328- name = { undefined }
329- value = { titleSuffix }
330- onChange = { ( ) => { } }
331- // readOnly
332- />
294+ < >
295+ < TextInput
296+ label = { strings . titleSecondaryLabel }
297+ placeholder = { strings . titleInputPlaceholder }
298+ name = "title"
299+ value = { value . title }
300+ maxLength = { 256 }
301+ onChange = { onValueChange }
302+ error = { error ?. title }
303+ disabled = { disabled }
304+ withAsterisk
305+ />
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+ ) }
327+ </ >
333328 ) }
334329 </ InputSection >
335330 < InputSection
0 commit comments