forked from primeroIMS/primero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent.jsx
92 lines (81 loc) · 2.54 KB
/
component.jsx
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
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved.
import PropTypes from "prop-types";
import { Draggable } from "react-beautiful-dnd";
import css from "../styles.css";
import { DragIndicator } from "../../../forms-list/components";
import FormSectionField from "../../../../../form/components/form-section-field";
import { FieldRecord, TEXT_FIELD } from "../../../../../form";
import SwitchInput from "../../../../../form/fields/switch-input";
import { LOCALE_KEYS } from "../../../../../../config";
import { NAME } from "./constants";
const Component = ({
firstLocaleOption,
index,
isDragDisabled,
isLockedLookup,
localesKeys,
selectedOption,
uniqueId,
formMode,
formMethods
}) => {
const renderTranslationValues = () => {
return localesKeys.map(localeKey => {
const name = `values.${localeKey}.${uniqueId}`;
const show = firstLocaleOption === localeKey || selectedOption === localeKey;
if (!show) return null;
return (
<div key={name}>
<FormSectionField
field={FieldRecord({ name, type: TEXT_FIELD, disabled: localeKey === LOCALE_KEYS.en && isLockedLookup })}
formMode={formMode}
formMethods={formMethods}
/>
</div>
);
});
};
const renderDisabledCheckbox = (
<div className={css.dragIndicatorContainer}>
<SwitchInput
commonInputProps={{ name: `disabled.${uniqueId}`, disabled: isDragDisabled || isLockedLookup }}
metaInputProps={{ selectedValue: true }}
formMethods={formMethods}
/>
</div>
);
return (
<Draggable
data-testid="draggable"
key={uniqueId}
draggableId={uniqueId}
index={index}
isDragDisabled={isDragDisabled}
>
{provider => {
return (
<div ref={provider.innerRef} {...provider.draggableProps} {...provider.dragHandleProps} className={css.row}>
<div className={css.dragIndicatorContainer}>
<DragIndicator {...provider.dragHandleProps} />
</div>
{renderTranslationValues()}
{renderDisabledCheckbox}
</div>
);
}}
</Draggable>
);
};
Component.displayName = NAME;
Component.propTypes = {
firstLocaleOption: PropTypes.string,
formMethods: PropTypes.object.isRequired,
formMode: PropTypes.object.isRequired,
index: PropTypes.number,
isDragDisabled: PropTypes.bool,
isLockedLookup: PropTypes.bool,
localesKeys: PropTypes.array,
selectedOption: PropTypes.string,
uniqueId: PropTypes.string
};
export default Component;