-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathDynamicInput.tsx
More file actions
193 lines (186 loc) · 7.12 KB
/
DynamicInput.tsx
File metadata and controls
193 lines (186 loc) · 7.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import React, { Suspense, lazy, useContext } from "react";
import ClaimReviewSelect from "./ClaimReviewSelect";
import InputTextList from "../InputTextList";
import Loading from "../Loading";
import TextArea from "../TextArea";
import FetchInput from "./FetchInput";
import { useTranslation } from "next-i18next";
import { VisualEditorContext } from "../Collaborative/VisualEditorProvider";
import AletheiaInput from "../AletheiaInput";
import DatePickerInput from "./DatePickerInput";
import { Checkbox, FormControlLabel } from "@mui/material";
import colors from "../../styles/colors";
import ReportTypeSelect from "../VerificationRequest/verificationRequestForms/formInputs/ReportTypeSelect";
import ImpactAreaSelect from "../VerificationRequest/verificationRequestForms/formInputs/ImpactAreaSelect";
import InputExtraSourcesList from "../VerificationRequest/verificationRequestForms/formInputs/InputExtraSourcesList";
import { Topic } from "../../types/Topic";
import { SourceType } from "../../types/Source";
import ImageUpload, { UploadFile } from "../ImageUpload";
const VisualEditor = lazy(() => import("../Collaborative/VisualEditor"));
export type UnifiedDefaultValue = Topic | SourceType[] | UploadFile[] | string
interface DynamicInputProps {
fieldName: string;
type: string;
placeholder: string;
value: UnifiedDefaultValue;
onChange: any;
addInputLabel: string;
defaultValue: UnifiedDefaultValue;
"data-cy": string;
extraProps: any;
disabledDate?: any;
disabled?: boolean;
}
const DynamicInput = (props: DynamicInputProps) => {
const { isFetchingEditor } = useContext(VisualEditorContext);
const { t } = useTranslation();
switch (props.type) {
case "textArea":
return (
<TextArea
multiline
placeholder={t(props.placeholder)}
onChange={(value) => props.onChange(value)}
defaultValue={props.defaultValue}
data-cy={props["data-cy"]}
white="true"
/>
);
case "inputSearch":
return (
<FetchInput
fieldName={props.fieldName}
placeholder={t(props.placeholder)}
onChange={props.onChange}
dataCy={props["data-cy"]}
dataLoader={props.extraProps.dataLoader}
value={props.value}
isMultiple={props.extraProps.mode}
preloadedOptions={props.extraProps.preloadedOptions}
/>
);
case "text":
return (
<AletheiaInput
placeholder={t(props.placeholder)}
onChange={(value) => props.onChange(value)}
defaultValue={props.defaultValue}
data-cy={props["data-cy"]}
white="true"
disabled={props.disabled}
style={{ backgroundColor: props.disabled ? colors.lightNeutral : colors.white }}
/>
);
case "textList":
return (
<InputTextList
fieldName={props.fieldName}
placeholder={t(props.placeholder)}
onChange={(value) => props.onChange(value)}
addInputLabel={t(props.addInputLabel)}
defaultValue={props.defaultValue}
dataCy={props["data-cy"]}
white="true"
/>
);
case "sourceList":
return (
<InputExtraSourcesList
sources={props.value}
onChange={props.onChange}
disabled={props.disabled}
placeholder={props.placeholder}
/>
);
case "select":
return (
<ClaimReviewSelect
type="select"
onChange={(value) => props.onChange(value)}
defaultValue={props.defaultValue}
placeholder={t(props.placeholder)}
/>
);
case "selectReportType":
return (
<ReportTypeSelect
defaultValue={props.defaultValue}
onChange={(value) => props.onChange(value)}
placeholder={t(props.placeholder)}
isDisabled={props.disabled}
/>
);
case "selectImpactArea":
return (
<ImpactAreaSelect
defaultValue={props.defaultValue}
onChange={(value) => props.onChange(value)}
placeholder={t(props.placeholder)}
isDisabled={props.disabled}
/>
);
case "imageUpload":
return (
<ImageUpload
onChange={(value) => props.onChange(value)}
defaultFileList={props.defaultValue}
/>
);
case "textbox":
return (
<FormControlLabel
control={
<Checkbox
data-cy={props["data-cy"]}
defaultChecked={!!props.defaultValue}
onChange={(value) => props.onChange(value)}
checked={!!props.value}
/>
}
label=
{t(`claimReviewForm:${props.fieldName}`)}
/>
);
case "visualEditor":
if (isFetchingEditor) {
return <Loading />;
} else {
return (
<Suspense fallback={<Loading />}>
<VisualEditor
onContentChange={({ doc }, reviewTaskType) => {
doc.attrs = { reviewTaskType };
props.onChange(doc);
}}
/>
</Suspense>
);
}
case "date":
return (
<DatePickerInput
defaultValue={props.defaultValue}
placeholder={t(props.placeholder)}
onChange={(value) => props.onChange(value)}
data-cy={"testSelectDate"}
disabledDate={props.disabledDate}
disabled={props.disabled}
style={{ backgroundColor: props.disabled ? colors.lightNeutral : colors.white }}
/>
);
case "email":
return (
<AletheiaInput
placeholder={t(props.placeholder)}
type={props.type}
onChange={(value) => props.onChange(value)}
defaultValue={props.defaultValue}
data-cy={props["data-cy"]}
white="true"
/>
);
default:
return null;
}
};
export default DynamicInput;