Skip to content

Commit d9efcae

Browse files
committed
fixup! feat(eap): create timespan component
1 parent ba9353a commit d9efcae

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"namespace": "common",
3+
"strings": {
4+
"timeframeLabel": "Timeframe",
5+
"timespanLabel": "Time Span"
6+
}
7+
}

app/src/components/TimespanInput/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import {
33
Checklist,
44
SelectInput,
55
} from '@ifrc-go/ui';
6+
import { useTranslation } from '@ifrc-go/ui/hooks';
67
import { stringValueSelector } from '@ifrc-go/ui/utils';
78
import { isNotDefined } from '@togglecorp/fujs';
89

10+
import i18n from './i18n.json';
11+
912
type Timeframe = 'hours' | 'days' | 'months' | 'years';
1013

1114
type TimeframeOptions = {
@@ -75,6 +78,8 @@ function TimespanInput(props: Props) {
7578
onChange,
7679
} = props;
7780

81+
const strings = useTranslation(i18n);
82+
7883
const timespanOptions = useMemo(() => {
7984
if (isNotDefined(value?.timeframe)) {
8085
return undefined;
@@ -100,7 +105,7 @@ function TimespanInput(props: Props) {
100105
<>
101106
<SelectInput
102107
name="timeframe"
103-
label="Timeframe"
108+
label={strings.timeframeLabel}
104109
value={value?.timeframe}
105110
onChange={handleTimeframeChange}
106111
options={timeframeOptions}
@@ -109,7 +114,7 @@ function TimespanInput(props: Props) {
109114
/>
110115
<Checklist
111116
name="timespan"
112-
label="Time span"
117+
label={strings.timespanLabel}
113118
value={value?.timespan}
114119
options={timespanOptions}
115120
keySelector={timeSpanKeySelector}

app/src/views/EapRegistration/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
type ElementRef,
33
useCallback,
44
useRef,
5+
useState,
56
} from 'react';
67
import {
78
useLocation,
@@ -39,6 +40,7 @@ import NationalSocietyMultiSelectInput from '#components/domain/NationalSocietyM
3940
import NationalSocietySelectInput from '#components/domain/NationalSocietySelectInput';
4041
import Link from '#components/Link';
4142
import Page from '#components/Page';
43+
import TimespanInput, { type TimespanInputValue } from '#components/TimespanInput';
4244
import useGlobalEnums from '#hooks/domain/useGlobalEnums';
4345
import useAlert from '#hooks/useAlert';
4446
import useRouting from '#hooks/useRouting';
@@ -74,6 +76,8 @@ export function Component() {
7476
const { navigate } = useRouting();
7577
const { eapId: eapIdFromParams } = useParams<{ eapId: string }>();
7678

79+
const [timespanValue, setTimespanValue] = useState<TimespanInputValue>();
80+
7781
const { state } = useLocation();
7882
const eapId = eapIdFromParams ?? state?.eapId as string | undefined;
7983
const isReadOnly = state?.mode === 'view';
@@ -520,6 +524,11 @@ export function Component() {
520524
disabled={disabled}
521525
readOnly={isReadOnly}
522526
/>
527+
{/* NOTE: Just for testing purpose */}
528+
<TimespanInput
529+
value={timespanValue}
530+
onChange={setTimespanValue}
531+
/>
523532
</InputSection>
524533
</Container>
525534
</div>

0 commit comments

Comments
 (0)