Skip to content

Commit a939eba

Browse files
committed
chore(typings): fix risk server related typings
1 parent 679c8da commit a939eba

File tree

6 files changed

+28
-17
lines changed

6 files changed

+28
-17
lines changed

app/src/components/domain/ActivityEventSearchSelectInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313

1414
type GetEventParams = GoApiUrlQuery<'/api/v2/event/response-activity/'>;
1515
type GetEventResponse = GoApiResponse<'/api/v2/event/response-activity/'>;
16-
export type EventItem = Pick<NonNullable<GetEventResponse['results']>[number], 'id' | 'name' | 'dtype' | 'emergency_response_contact_email'>;
16+
export type EventItem = Pick<NonNullable<GetEventResponse['results']>[number], 'id' | 'name' | 'dtype'>;
1717

1818
const keySelector = (d: EventItem) => d.id;
1919
const labelSelector = (d: EventItem) => d.name ?? '???';

app/src/components/domain/RiskImminentEvents/Gdacs/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { numericIdSelector } from '@ifrc-go/ui/utils';
33
import {
44
isDefined,
55
isNotDefined,
6+
isObject,
67
} from '@togglecorp/fujs';
78
import { type LngLatBoundsLike } from 'mapbox-gl';
89

@@ -229,7 +230,13 @@ function Gdacs(props: Props) {
229230
? footprint_geojson
230231
: undefined;
231232

232-
const hazardDate = (footprint?.metadata as ({ todate?: string } | undefined))?.todate;
233+
const hazardDate = (isDefined(footprint)
234+
&& 'metadata' in footprint
235+
&& isObject(footprint.metadata)
236+
&& 'todate' in footprint.metadata
237+
)
238+
? String(footprint.metadata.todate)
239+
: undefined;
233240

234241
const geoJson: GeoJSON.FeatureCollection<GeoJSON.Geometry, RiskLayerProperties> = {
235242
type: 'FeatureCollection' as const,

app/src/components/domain/RiskImminentEvents/MeteoSwiss/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { numericIdSelector } from '@ifrc-go/ui/utils';
33
import {
44
isDefined,
55
isNotDefined,
6+
isObject,
67
} from '@togglecorp/fujs';
78
import type { LngLatBoundsLike } from 'mapbox-gl';
89

@@ -155,7 +156,11 @@ function MeteoSwiss(props: Props) {
155156
}
156157

157158
// FIXME: fix typing in server (low priority)
158-
const footprint_geojson = exposure?.footprint_geojson?.footprint_geojson;
159+
const footprint_geojson = 'footprint_geojson' in exposure
160+
&& isObject(exposure.footprint_geojson)
161+
&& 'footprint_geojson' in exposure.footprint_geojson
162+
? exposure.footprint_geojson?.footprint_geojson
163+
: undefined;
159164

160165
if (isNotDefined(footprint_geojson)) {
161166
return undefined;

app/src/components/domain/RiskImminentEvents/Pdc/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ function Pdc(props: Props) {
138138
} = exposure;
139139

140140
// FIXME: showing five days cou when three days cou is not available
141-
const cyclone_cou = cyclone_three_days_cou?.[0] ?? cyclone_five_days_cou?.[0];
141+
const cyclone_cou = (cyclone_three_days_cou as unknown[] | null)?.[0]
142+
?? (cyclone_five_days_cou as unknown[])?.[0];
142143

143144
if (isNotDefined(footprint_geojson) && isNotDefined(storm_position_geojson)) {
144145
return undefined;

app/src/views/AllDeployedPersonnel/index.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import { saveAs } from 'file-saver';
2626
import Papa from 'papaparse';
2727

28+
import { type EventItem } from '#components/domain/ActivityEventSearchSelectInput';
2829
import CountrySelectInput from '#components/domain/CountrySelectInput';
2930
import EventSearchSelectInput from '#components/domain/EventSearchSelectInput';
3031
import ExportButton from '#components/domain/ExportButton';
@@ -135,7 +136,7 @@ export function Component() {
135136
(country) => country,
136137
);
137138

138-
const [positionFilter, setPositionFilter] = useUrlSearchState<string>(
139+
const [positionFilter, setPositionFilter] = useUrlSearchState<string | undefined>(
139140
'role',
140141
(searchValue) => searchValue ?? '',
141142
(value) => value,
@@ -176,7 +177,7 @@ export function Component() {
176177
summary: undefined,
177178
},
178179
name,
179-
};
180+
} satisfies EventItem;
180181

181182
setEventOptions((prevOptions) => ([
182183
...prevOptions ?? [],
@@ -395,26 +396,22 @@ export function Component() {
395396
name="role"
396397
value={positionFilter}
397398
onChange={setPositionFilter}
398-
placeholder={strings.defaultPlaceholder}
399399
/>
400400
<NationalSocietySelectInput
401401
label={strings.personnelTableDeployingParty}
402402
name="deploying_party"
403-
placeholder={strings.defaultPlaceholder}
404403
value={nationalSocietyFilter}
405404
onChange={setNationalSocietyFilter}
406405
/>
407406
<CountrySelectInput
408407
label={strings.personnelTableDeployedTo}
409408
name="deployed_to"
410-
placeholder={strings.defaultPlaceholder}
411409
value={countryToFilter}
412410
onChange={setCountryToFilter}
413411
/>
414412
<EventSearchSelectInput
415413
name="event"
416414
label={strings.personnelTableEmergency}
417-
placeholder={strings.defaultPlaceholder}
418415
value={eventFilter}
419416
onChange={setEventFilter}
420417
options={eventOptions}

app/src/views/ThreeWActivityForm/index.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ export function Component() {
173173
DistrictItem[] | undefined | null
174174
>([]);
175175

176+
const { response: selectedEventDetail } = useRequest({
177+
skip: isNotDefined(value.event),
178+
url: '/api/v2/event/{id}/',
179+
pathVariables: isDefined(value.event) ? {
180+
id: value.event,
181+
} : undefined,
182+
});
183+
176184
const {
177185
pending: fetchingActivity,
178186
response: activityResponse,
@@ -543,13 +551,6 @@ export function Component() {
543551
createActivity,
544552
]);
545553

546-
const selectedEventDetail = useMemo(() => (
547-
eventOptions?.find((event) => event.id === value?.event)
548-
), [
549-
eventOptions,
550-
value?.event,
551-
]);
552-
553554
const countries = useCountry();
554555
const nationalSocieties = useNationalSociety();
555556

0 commit comments

Comments
 (0)