Skip to content

Commit 672ce14

Browse files
authored
Merge pull request #477 from IFRCGo/project/dref-super-ticket-fixes
DREF super ticket fixes
2 parents 678c995 + cf00541 commit 672ce14

File tree

41 files changed

+371
-346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+371
-346
lines changed

src/App/routes/index.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,7 @@ import type {
1717
MyOutputIndexRouteObject,
1818
MyOutputNonIndexRouteObject,
1919
} from '#utils/routes';
20-
import {
21-
COUNTRY_AFRICA_REGION,
22-
COUNTRY_AMERICAS_REGION,
23-
COUNTRY_ASIA_REGION,
24-
COUNTRY_EUROPE_REGION,
25-
COUNTRY_MENA_REGION,
26-
REGION_AFRICA,
27-
REGION_AMERICAS,
28-
REGION_ASIA,
29-
REGION_EUROPE,
30-
REGION_MENA,
31-
} from '#utils/constants';
20+
import { countryIdToRegionIdMap } from '#utils/domain/country';
3221

3322
import Auth from '../Auth';
3423
import PageError from '../PageError';
@@ -361,14 +350,6 @@ const countriesLayout = customWrapRoute({
361350
// eslint-disable-next-line react-refresh/only-export-components
362351
function CountryNavigate() {
363352
const params = useParams<{ countryId: string }>();
364-
const countryIdToRegionIdMap: Record<number, number> = {
365-
[COUNTRY_AFRICA_REGION]: REGION_AFRICA,
366-
[COUNTRY_AMERICAS_REGION]: REGION_AMERICAS,
367-
[COUNTRY_ASIA_REGION]: REGION_ASIA,
368-
[COUNTRY_EUROPE_REGION]: REGION_EUROPE,
369-
[COUNTRY_MENA_REGION]: REGION_MENA,
370-
};
371-
372353
const countryId = isTruthyString(params.countryId) ? parseInt(params.countryId, 10) : undefined;
373354
const regionId = isDefined(countryId) ? countryIdToRegionIdMap[countryId] : undefined;
374355

src/components/Link/index.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ export function useLink(props: {
9494
};
9595
}
9696

97-
export type Props<OMISSION extends string = never> = Omit<RouterLinkProps, 'to' | OMISSION> & Omit<{
97+
export type CommonLinkProps<OMISSION extends string = never> = Omit<RouterLinkProps, 'to' | OMISSION> &
98+
Omit<{
9899
actions?: React.ReactNode;
99100
actionsContainerClassName?: string;
100101
disabled?: boolean;
@@ -107,21 +108,28 @@ export type Props<OMISSION extends string = never> = Omit<RouterLinkProps, 'to'
107108
withUnderline?: boolean;
108109
ellipsize?: boolean;
109110
spacing?: ButtonFeatureProps['spacing'];
110-
}, OMISSION> & ({
111+
}, OMISSION>
112+
113+
export type InternalLinkProps = {
111114
external?: never;
112115
to: keyof WrappedRoutes | undefined | null;
113116
urlParams?: UrlParams;
114117
urlSearch?: string;
115118
urlHash?: string;
116119
href?: never;
117-
} | {
120+
}
121+
122+
export type ExternalLinkProps = {
118123
external: true;
119124
href: string | undefined | null;
120125
urlParams?: never;
121126
urlSearch?: never;
122127
urlHash?: never;
123128
to?: never;
124-
})
129+
}
130+
131+
export type Props<OMISSION extends string = never> = CommonLinkProps<OMISSION>
132+
& (InternalLinkProps | ExternalLinkProps)
125133

126134
function Link(props: Props) {
127135
const {

src/components/domain/GoSingleFileInput/i18n.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"namespace": "common",
33
"strings": {
44
"failedUploadMessage": "Failed to upload the file!",
5-
"oneFileSelected": "1 file selected",
65
"removeFileButtonTitle": "Remove",
76
"noFileSelected": "No file Selected"
87
}

src/components/domain/GoSingleFileInput/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function GoSingleFileInput<T extends NameType>(props: Props<T>) {
158158
href={selectedFileUrl}
159159
external
160160
>
161-
{strings.oneFileSelected}
161+
{selectedFileUrl.split('/').pop()}
162162
</Link>
163163
) : (
164164
<div className={styles.emptyMessage}>

src/components/printable/Image/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import styles from './styles.module.css';
1010

1111
interface Props {
12-
src?: string;
12+
src: string | null | undefined;
1313
alt?: string;
1414
caption?: React.ReactNode;
1515
imgElementClassName?: string;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { _cs } from '@togglecorp/fujs';
2+
3+
import GoLink, {
4+
type CommonLinkProps,
5+
type ExternalLinkProps,
6+
} from '#components/Link';
7+
8+
import styles from './styles.module.css';
9+
10+
type Props = CommonLinkProps<'withUnderline'> & Omit<ExternalLinkProps, 'external'>;
11+
12+
function Link(props: Props) {
13+
const {
14+
className,
15+
...otherProps
16+
} = props;
17+
18+
return (
19+
<GoLink
20+
// eslint-disable-next-line react/jsx-props-no-spreading
21+
{...otherProps}
22+
external
23+
withUnderline
24+
className={_cs(styles.link, className)}
25+
/>
26+
);
27+
}
28+
29+
export default Link;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.link {
2+
color: var(--go-ui-color-blue);
3+
font-size: var(--go-ui-font-size-md);
4+
}

src/utils/constants.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,13 @@ export const COUNTRY_ASIA_REGION = 283;
151151
export const COUNTRY_AFRICA_REGION = 285;
152152
export const COUNTRY_EUROPE_REGION = 286;
153153
export const COUNTRY_MENA_REGION = 287;
154-
export type Region = components<'read'>['schemas']['ApiRegionNameEnum'];
155-
export const REGION_AFRICA = 0;
156-
export const REGION_AMERICAS = 1;
157-
export const REGION_ASIA = 2;
158-
export const REGION_EUROPE = 3;
159-
export const REGION_MENA = 4;
154+
155+
export type Region = components<'read'>['schemas']['Key86cEnum'];
156+
export const REGION_AFRICA = 0 satisfies Region;
157+
export const REGION_AMERICAS = 1 satisfies Region;
158+
export const REGION_ASIA = 2 satisfies Region;
159+
export const REGION_EUROPE = 3 satisfies Region;
160+
export const REGION_MENA = 4 satisfies Region;
160161

161162
type CountryRecordTypeEnum = components<'read'>['schemas']['RecordTypeEnum'];
162163
export const COUNTRY_RECORD_TYPE_COUNTRY = 1 satisfies CountryRecordTypeEnum;

src/utils/domain/country.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {
2+
COUNTRY_AFRICA_REGION,
3+
COUNTRY_AMERICAS_REGION,
4+
COUNTRY_ASIA_REGION,
5+
COUNTRY_EUROPE_REGION,
6+
COUNTRY_MENA_REGION,
7+
REGION_AFRICA,
8+
REGION_AMERICAS,
9+
REGION_ASIA,
10+
REGION_EUROPE,
11+
REGION_MENA,
12+
type Region,
13+
} from '#utils/constants';
14+
import { isNotDefined } from '@togglecorp/fujs';
15+
16+
// eslint-disable-next-line import/prefer-default-export
17+
export const countryIdToRegionIdMap: Record<number, Region> = {
18+
[COUNTRY_AFRICA_REGION]: REGION_AFRICA,
19+
[COUNTRY_AMERICAS_REGION]: REGION_AMERICAS,
20+
[COUNTRY_ASIA_REGION]: REGION_ASIA,
21+
[COUNTRY_EUROPE_REGION]: REGION_EUROPE,
22+
[COUNTRY_MENA_REGION]: REGION_MENA,
23+
};
24+
25+
export function isCountryIdRegion(countryId: number | null | undefined) {
26+
if (isNotDefined(countryId)) {
27+
return false;
28+
}
29+
30+
return countryId === COUNTRY_ASIA_REGION
31+
|| countryId === COUNTRY_AFRICA_REGION
32+
|| countryId === COUNTRY_AMERICAS_REGION
33+
|| countryId === COUNTRY_EUROPE_REGION
34+
|| countryId === COUNTRY_MENA_REGION;
35+
}

src/views/AllDeployedPersonnel/index.tsx

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,32 @@ import {
44
} from 'react';
55
import Papa from 'papaparse';
66
import { saveAs } from 'file-saver';
7+
import { isDefined, isNotDefined } from '@togglecorp/fujs';
78

8-
import { toDateTimeString } from '#utils/common';
9-
import useTranslation from '#hooks/useTranslation';
10-
import {
11-
type GoApiResponse,
12-
useRequest,
13-
} from '#utils/restRequest';
14-
import { resolveToComponent } from '#utils/translation';
159
import Container from '#components/Container';
1610
import Pager from '#components/Pager';
1711
import Page from '#components/Page';
18-
import useAlert from '#hooks/useAlert';
12+
import { SortContext } from '#components/Table/useSorting';
1913
import ExportButton from '#components/domain/ExportButton';
20-
import {
21-
SortContext,
22-
} from '#components/Table/useSorting';
14+
import Table from '#components/Table';
15+
import DateInput from '#components/DateInput';
2316
import {
2417
createStringColumn,
2518
createDateColumn,
2619
createLinkColumn,
2720
} from '#components/Table/ColumnShortcuts';
21+
import useAlert from '#hooks/useAlert';
22+
import useTranslation from '#hooks/useTranslation';
2823
import useRecursiveCsvExport from '#hooks/useRecursiveCsvRequest';
29-
import Table from '#components/Table';
30-
import DateInput from '#components/DateInput';
3124
import useFilterState from '#hooks/useFilterState';
25+
import { toDateTimeString } from '#utils/common';
26+
import {
27+
type GoApiResponse,
28+
useRequest,
29+
} from '#utils/restRequest';
30+
import { resolveToComponent } from '#utils/translation';
31+
import { COUNTRY_RECORD_TYPE_REGION } from '#utils/constants';
32+
import { countryIdToRegionIdMap } from '#utils/domain/country';
3233

3334
import i18n from './i18n.json';
3435

@@ -122,17 +123,37 @@ export function Component() {
122123
(item) => getTypeName(item.type),
123124
{ sortable: true },
124125
),
126+
// NOTE:We don't have proper mapping for region
125127
createLinkColumn<PersonnelTableItem, number>(
126128
'country_from',
127129
strings.personnelTableDeployingParty,
128130
(item) => (
129131
item.country_from?.society_name
130132
|| item.country_from?.name
131133
),
132-
(item) => ({
133-
to: 'countriesLayout',
134-
urlParams: { countryId: item.country_from?.id },
135-
}),
134+
(item) => {
135+
if (isNotDefined(item.country_from)) {
136+
return { to: undefined };
137+
}
138+
139+
const countryId = item.country_from.id;
140+
141+
if (item.country_from.record_type === COUNTRY_RECORD_TYPE_REGION) {
142+
const regionId = isDefined(countryId)
143+
? countryIdToRegionIdMap[countryId]
144+
: undefined;
145+
146+
return {
147+
to: 'regionsLayout',
148+
urlParams: { regionId },
149+
};
150+
}
151+
152+
return {
153+
to: 'countriesLayout',
154+
urlParams: { countryId },
155+
};
156+
},
136157
{ sortable: true },
137158
),
138159
createLinkColumn<PersonnelTableItem, number>(

0 commit comments

Comments
 (0)