Skip to content

Commit 0d974cc

Browse files
barshathakurifrozenhelium
authored andcommitted
feat(eap): update simplified eap form schema
1 parent f2e555c commit 0d974cc

38 files changed

Lines changed: 1087 additions & 1110 deletions

File tree

app/src/App/routes/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,6 @@ const simplifiedEapExport = customWrapRoute({
12401240
},
12411241
});
12421242

1243-
12441243
type DefaultPerProcessChild = 'new';
12451244
const perProcessLayout = customWrapRoute({
12461245
parent: rootLayout,
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { useCallback } from 'react';
2+
import {
3+
type CheckboxProps,
4+
InputError,
5+
} from '@ifrc-go/ui';
6+
import { _cs } from '@togglecorp/fujs';
7+
8+
import styles from './styles.module.css';
9+
10+
function TimeSpanCheck<const NAME>(props: CheckboxProps<NAME>) {
11+
const {
12+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
13+
checkmarkClassName,
14+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
15+
checkmarkContainerClassName,
16+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
17+
inputClassName,
18+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
19+
labelContainerClassName,
20+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
21+
description,
22+
23+
className: classNameFromProps,
24+
disabled,
25+
error,
26+
indeterminate,
27+
invertedLogic = false,
28+
label,
29+
name,
30+
onChange,
31+
readOnly,
32+
tooltip,
33+
value,
34+
withBackground,
35+
withDarkBackground,
36+
...otherProps
37+
} = props;
38+
39+
const handleChange = useCallback(
40+
(e: React.FormEvent<HTMLInputElement>) => {
41+
const v = e.currentTarget.checked;
42+
onChange(
43+
invertedLogic ? !v : v,
44+
name,
45+
);
46+
},
47+
[name, onChange, invertedLogic],
48+
);
49+
50+
const checked = invertedLogic ? !value : value;
51+
52+
const className = _cs(
53+
styles.checkbox,
54+
classNameFromProps,
55+
!indeterminate && checked && styles.checked,
56+
withBackground && styles.withBackground,
57+
withDarkBackground && styles.withDarkBackground,
58+
disabled && styles.disabledCheckbox,
59+
readOnly && styles.readOnly,
60+
);
61+
62+
return (
63+
<label // eslint-disable-line jsx-a11y/label-has-associated-control
64+
className={_cs(
65+
styles.timeSpanCheck,
66+
value && styles.checked,
67+
className,
68+
)}
69+
title={tooltip}
70+
>
71+
<input
72+
onChange={handleChange}
73+
className={styles.input}
74+
type="checkbox"
75+
checked={checked ?? false}
76+
disabled={disabled || readOnly}
77+
readOnly={readOnly}
78+
{...otherProps} // eslint-disable-line react/jsx-props-no-spreading
79+
/>
80+
{label}
81+
{error && (
82+
<InputError floating>
83+
{error}
84+
</InputError>
85+
)}
86+
</label>
87+
);
88+
}
89+
90+
export default TimeSpanCheck;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.time-span-check {
2+
display: flex;
3+
align-items: center;
4+
justify-content: center;
5+
border: var(--go-ui-width-separator-thin) solid var(--go-ui-color-gray-50);
6+
border-radius: var(--go-ui-border-radius-md);
7+
cursor: pointer;
8+
padding: 0 var(--go-ui-spacing-3xs);
9+
min-width: 1.5rem;
10+
height: 1.5rem;
11+
text-align: center;
12+
font-size: var(--go-ui-font-size-sm);
13+
14+
&.checked {
15+
border-color: var(--go-ui-color-primary-red);
16+
background-color: var(--go-ui-color-primary-red);
17+
color: var(--go-ui-color-text-on-dark);
18+
}
19+
20+
.input {
21+
position: absolute;
22+
opacity: 0;
23+
margin: 0;
24+
padding: 0;
25+
width: 0;
26+
height: 0;
27+
pointer-events: none;
28+
}
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"namespace": "operationActivityInput",
3+
"strings": {
4+
"operationPriorityActionLabel": "Priority action",
5+
"operationTimeFrameLabel": "Time Frame",
6+
"operationTimeValueLabel": "Time Value"
7+
}
8+
}

app/src/views/SimplifiedEapForm/EnablingApproaches/ApproachesInput/ActivityInput/index.tsx renamed to app/src/components/domain/OperationActivityInput/index.tsx

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DeleteBinTwoLineIcon } from '@ifrc-go/icons';
33
import {
44
Button,
55
Checklist,
6-
Container,
6+
InlineLayout,
77
ListView,
88
SelectInput,
99
TextInput,
@@ -17,23 +17,20 @@ import {
1717
useFormObject,
1818
} from '@togglecorp/toggle-form';
1919

20+
import { type components } from '#generated/types';
2021
import useGlobalEnums from '#hooks/domain/useGlobalEnums';
21-
import { type GoApiResponse } from '#utils/restRequest';
2222

23-
import { type PartialSimplifiedEapType } from '../../../schema';
23+
import { type OperationActivityFormFields } from './schema';
24+
import TimeSpanCheck from './TimeSpanCheck';
2425

2526
import i18n from './i18n.json';
2627

27-
type ApproachesFormFields = NonNullable<PartialSimplifiedEapType['enable_approaches']>[number];
28-
type ActivityFormField = NonNullable<ApproachesFormFields['early_action_activities']>[number];
29-
30-
type GlobalEnumsResponse = GoApiResponse<'/api/v2/global-enums/'>;
31-
type TimeframeOption = NonNullable<GlobalEnumsResponse['eap_timeframe']>[number];
32-
33-
const defaultActivityValue: ActivityFormField = {
28+
const defaultActivityValue: OperationActivityFormFields = {
3429
client_id: '-1',
3530
};
3631

32+
type TimeframeOption = components['schemas']['EapTimeframeEnum'];
33+
3734
function timeframeKeySelector(option: TimeframeOption) {
3835
return option.key;
3936
}
@@ -43,15 +40,15 @@ const timeValueKeySelector = (
4340
) => option.key;
4441

4542
interface Props {
46-
value: ActivityFormField;
47-
error: ArrayError<ActivityFormField> | undefined;
48-
onChange: (value: SetValueArg<ActivityFormField>, index: number) => void;
43+
value: OperationActivityFormFields;
44+
error: ArrayError<OperationActivityFormFields> | undefined;
45+
onChange: (value: SetValueArg<OperationActivityFormFields>, index: number) => void;
4946
onRemove: (index: number) => void;
5047
index: number;
5148
disabled?: boolean;
5249
}
5350

54-
function ActivityInput(props: Props) {
51+
function OperationActivityInput(props: Props) {
5552
const {
5653
error: errorFromProps,
5754
onChange,
@@ -110,31 +107,31 @@ function ActivityInput(props: Props) {
110107
);
111108

112109
return (
113-
<Container
114-
headerActions={(
110+
<InlineLayout
111+
after={(
115112
<Button
116113
name={index}
117114
onClick={onRemove}
118-
styleVariant="outline"
115+
styleVariant="action"
119116
title="Remove"
120117
disabled={disabled}
121118
>
122119
<DeleteBinTwoLineIcon />
123120
</Button>
124121
)}
125122
>
126-
<ListView layout="block">
127-
<ListView layout="grid" numPreferredGridColumns={3}>
128-
<TextInput
129-
label={strings.approachReadiness}
130-
name="activity"
131-
value={value.activity}
132-
onChange={onFieldChange}
133-
disabled={disabled}
134-
withAsterisk
135-
/>
123+
<ListView layout="grid">
124+
<TextInput
125+
label={strings.operationPriorityActionLabel}
126+
name="activity"
127+
value={value.activity}
128+
onChange={onFieldChange}
129+
disabled={disabled}
130+
withAsterisk
131+
/>
132+
<ListView layout="grid">
136133
<SelectInput
137-
label={strings.approachTimeFrame}
134+
label={strings.operationTimeFrameLabel}
138135
name="timeframe"
139136
value={value.timeframe}
140137
onChange={handleTimeframeChange}
@@ -144,23 +141,25 @@ function ActivityInput(props: Props) {
144141
disabled={disabled}
145142
error={error?.timeframe}
146143
/>
147-
148144
{value?.timeframe && (
149145
<Checklist
150-
label={strings.approachTimeValue}
146+
label={strings.operationTimeValueLabel}
151147
name="time_value"
152148
value={value?.time_value}
149+
spacing="xs"
153150
onChange={onFieldChange}
154151
keySelector={timeValueKeySelector}
155152
labelSelector={stringValueSelector}
156153
options={timeValueOptions}
157154
disabled={disabled}
155+
renderer={TimeSpanCheck}
156+
withoutOpticalSpacingCorrection
158157
/>
159158
)}
160159
</ListView>
161160
</ListView>
162-
</Container>
161+
</InlineLayout>
163162
);
164163
}
165164

166-
export default ActivityInput;
165+
export default OperationActivityInput;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {
2+
type ObjectSchema,
3+
type PartialForm,
4+
undefinedValue,
5+
} from '@togglecorp/toggle-form';
6+
7+
import { type components } from '#generated/types';
8+
9+
type OperationActivity = components['schemas']['OperationActivity'];
10+
11+
export type OperationActivityFormFields = PartialForm<Omit<OperationActivity, 'timeframe_display'>> & {
12+
client_id: string;
13+
}
14+
15+
type OperationActivitySchema = ObjectSchema<OperationActivityFormFields>;
16+
17+
const schema: OperationActivitySchema = {
18+
fields: (): ReturnType<OperationActivitySchema['fields']> => ({
19+
client_id: {},
20+
id: { defaultValue: undefinedValue },
21+
activity: {},
22+
time_value: {},
23+
timeframe: {},
24+
}),
25+
};
26+
27+
export default schema;

app/src/components/printable/PrintableDescription/index.tsx

Whitespace-only changes.

app/src/components/printable/PrintableDescription/styles.module.css

Whitespace-only changes.

app/src/components/printable/PrintableLabel/index.tsx

Whitespace-only changes.

app/src/components/printable/PrintableLabel/styles.module.css

Whitespace-only changes.

0 commit comments

Comments
 (0)