-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(report): preview generated title for field report
- Loading branch information
Showing
6 changed files
with
105 additions
and
13 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
8 changes: 8 additions & 0 deletions
8
app/src/views/FieldReportForm/ContextFields/TitlePreview/i18n.json
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"namespace": "fieldReportForm", | ||
"strings": { | ||
"titlePreview": "Title Preview", | ||
"failedToGenerateTitle": "Failed To Generate the Field Report Title" | ||
} | ||
} | ||
|
67 changes: 67 additions & 0 deletions
67
app/src/views/FieldReportForm/ContextFields/TitlePreview/index.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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { useMemo } from 'react'; | ||
import { TextOutput } from '@ifrc-go/ui'; | ||
import { useTranslation } from '@ifrc-go/ui/hooks'; | ||
|
||
import useAlert from '#hooks/useAlert'; | ||
import { useRequest } from '#utils/restRequest'; | ||
|
||
import i18n from './i18n.json'; | ||
|
||
interface Props { | ||
country: number; | ||
disasterType: number; | ||
event?: number; | ||
isCovidReport?: boolean; | ||
startDate?: string; | ||
title: string; | ||
} | ||
|
||
function TitlePreview(props: Props) { | ||
const { | ||
country, | ||
disasterType, | ||
event, | ||
isCovidReport, | ||
startDate, | ||
title, | ||
} = props; | ||
|
||
const strings = useTranslation(i18n); | ||
const alert = useAlert(); | ||
|
||
const variables = useMemo(() => ({ | ||
countries: [country], | ||
is_covid_report: isCovidReport, | ||
start_date: startDate, | ||
dtype: disasterType, | ||
event, | ||
title, | ||
}), [country, isCovidReport, startDate, disasterType, event, title]); | ||
|
||
const { | ||
response: genereateTitleResponse, | ||
} = useRequest({ | ||
url: '/api/v2/field-report/generate-title/', | ||
method: 'POST', | ||
body: variables, | ||
preserveResponse: true, | ||
onFailure: () => { | ||
alert.show( | ||
strings.failedToGenerateTitle, | ||
{ | ||
variant: 'danger', | ||
}, | ||
); | ||
}, | ||
}); | ||
|
||
return ( | ||
<TextOutput | ||
value={genereateTitleResponse?.title} | ||
label={strings.titlePreview} | ||
strongLabel | ||
/> | ||
); | ||
} | ||
|
||
export default TitlePreview; |
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
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
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