Skip to content

Commit f96e177

Browse files
committed
fix: move field report title generation logic to server
1 parent 89e6ace commit f96e177

File tree

4 files changed

+29
-253
lines changed

4 files changed

+29
-253
lines changed

.changeset/itchy-dryers-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"go-web-app": patch
3+
---
4+
5+
Move field report / emergency title generation logic from client to server

app/src/views/FieldReportForm/ContextFields/index.tsx

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ import {
1111
TextInput,
1212
} from '@ifrc-go/ui';
1313
import { useTranslation } from '@ifrc-go/ui/hooks';
14-
import {
15-
isNotDefined,
16-
isTruthyString,
17-
} from '@togglecorp/fujs';
14+
import { isNotDefined } from '@togglecorp/fujs';
1815
import {
1916
type EntriesAsList,
2017
type Error,
@@ -54,10 +51,6 @@ interface Props {
5451
setDistrictOptions: React.Dispatch<React.SetStateAction<DistrictItem[] | null | undefined>>;
5552
setEventOptions: React.Dispatch<React.SetStateAction<EventItem[] | null | undefined>>;
5653
disabled?: boolean;
57-
58-
fieldReportId: string | undefined;
59-
titlePrefix: string | undefined;
60-
titleSuffix: string | undefined;
6154
}
6255

6356
function ContextFields(props: Props) {
@@ -71,9 +64,6 @@ function ContextFields(props: Props) {
7164
setDistrictOptions,
7265
setEventOptions,
7366
disabled,
74-
titlePrefix,
75-
titleSuffix,
76-
fieldReportId,
7767
} = props;
7868

7969
const strings = useTranslation(i18n);
@@ -171,14 +161,10 @@ function ContextFields(props: Props) {
171161
[onValueChange, value.dtype],
172162
);
173163

174-
const prefixVisible = !fieldReportId && isTruthyString(titlePrefix);
175164
const summaryVisible = !value.is_covid_report;
176-
const suffixVisible = !fieldReportId && isTruthyString(titleSuffix);
177165

178166
const preferredColumnNoForSummary = Math.max(
179-
(prefixVisible ? 1 : 0)
180-
+ (summaryVisible ? 1 : 0)
181-
+ (suffixVisible ? 1 : 0),
167+
summaryVisible ? 1 : 0,
182168
1,
183169
) as 1 | 2 | 3;
184170

@@ -301,36 +287,19 @@ function ContextFields(props: Props) {
301287
withAsteriskOnTitle
302288
numPreferredColumns={preferredColumnNoForSummary}
303289
>
304-
{prefixVisible && (
305-
<TextInput
306-
label={summaryVisible ? strings.fieldPrefix : strings.titleSecondaryLabel}
307-
name={undefined}
308-
value={titlePrefix}
309-
onChange={() => { }}
310-
/>
311-
)}
312290
{summaryVisible && (
313291
<TextInput
314292
label={strings.titleSecondaryLabel}
315293
placeholder={strings.titleInputPlaceholder}
316-
name="summary"
317-
value={value.summary}
294+
name="title"
295+
value={value.title}
318296
maxLength={256}
319297
onChange={onValueChange}
320-
error={error?.summary}
298+
error={error?.title}
321299
disabled={disabled}
322300
withAsterisk
323301
/>
324302
)}
325-
{suffixVisible && (
326-
<TextInput
327-
label={strings.fieldReportFormSuffix}
328-
name={undefined}
329-
value={titleSuffix}
330-
onChange={() => { }}
331-
// readOnly
332-
/>
333-
)}
334303
</InputSection>
335304
<InputSection
336305
title={strings.assistanceLabel}

app/src/views/FieldReportForm/common.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ const fieldsInContext = [
152152
'summary',
153153
'request_assistance',
154154
'ns_request_assistance',
155+
'title',
155156
] satisfies (keyof PartialFormValue)[];
156157
const fieldsInSituation = [
157158
'affected_pop_centres',
@@ -274,6 +275,7 @@ export const reportSchema: FormSchema = {
274275
country: { required: true },
275276
districts: { defaultValue: [] },
276277
dtype: { required: true },
278+
title: { required: true },
277279
start_date: { required: true },
278280
request_assistance: {},
279281
ns_request_assistance: {},
@@ -309,23 +311,23 @@ export const reportSchema: FormSchema = {
309311
});
310312

311313
// CONTEXT
312-
baseSchema = addCondition(
313-
baseSchema,
314-
value,
315-
['status', 'is_covid_report', 'dtype'],
316-
['summary'],
317-
(val): Pick<FormSchemaFields, 'summary'> => {
318-
const reportType = getReportType(val?.status, val?.is_covid_report, val?.dtype);
319-
if (reportType === 'COVID') {
320-
return {
321-
summary: { forceValue: nullValue },
322-
};
323-
}
324-
return {
325-
summary: { required: true, requiredValidation: requiredStringCondition },
326-
};
327-
},
328-
);
314+
// baseSchema = addCondition(
315+
// baseSchema,
316+
// value,
317+
// ['status', 'is_covid_report', 'dtype'],
318+
// ['summary'],
319+
// (val): Pick<FormSchemaFields, 'summary'> => {
320+
// const reportType = getReportType(val?.status, val?.is_covid_report, val?.dtype);
321+
// if (reportType === 'COVID') {
322+
// return {
323+
// summary: { forceValue: nullValue },
324+
// };
325+
// }
326+
// return {
327+
// summary: { required: true, requiredValidation: requiredStringCondition },
328+
// };
329+
// },
330+
// );
329331

330332
// SITUATION / RISK ANALYSIS
331333

0 commit comments

Comments
 (0)