|
1 | | -import React from 'react'; |
2 | | -import { observer } from 'mobx-react-lite'; |
3 | | -import SelectInput from '../../components/generalInputs/SelectInput'; |
| 1 | +import React from "react"; |
| 2 | +import { observer } from "mobx-react-lite"; |
| 3 | +import SelectInput from "../../components/generalInputs/SelectInput"; |
4 | 4 | import { Alert } from "react-bootstrap"; |
5 | | -import TextInput from '../../components/generalInputs/TextInput'; |
6 | | -import CoordinatesInput from '../../components/generalInputs/CoordinatesInput'; |
| 5 | +import TextInput from "../../components/generalInputs/TextInput"; |
| 6 | +import CoordinatesInput from "../../components/generalInputs/CoordinatesInput"; |
7 | 7 | import { Suspense, lazy } from "react"; |
8 | 8 | import convertToTreeData from "../../utils/converToTreeData"; |
9 | | -import { FormattedMessage } from 'react-intl'; |
10 | | - |
| 9 | +import { FormattedMessage } from "react-intl"; |
11 | 10 |
|
12 | 11 | const TreeSelect = lazy(() => import("antd/es/tree-select")); |
13 | 12 | export const LocationSectionEdit = observer(({ store }) => { |
14 | | - const locationOptions = convertToTreeData(store.siteSettingsData?.locationData?.locationID, "value", "label"); |
| 13 | + const locationOptions = convertToTreeData( |
| 14 | + store.siteSettingsData?.locationData?.locationID, |
| 15 | + "value", |
| 16 | + "label", |
| 17 | + ); |
15 | 18 |
|
16 | | - return <div> |
17 | | - <TextInput |
18 | | - label="LOCATION" |
19 | | - value={ |
20 | | - store.getFieldValue("location", "verbatimLocality") ?? |
21 | | - "" |
22 | | - } |
23 | | - onChange={(v) => |
24 | | - store.setFieldValue("location", "verbatimLocality", v) |
25 | | - } |
26 | | - /> |
27 | | - <label><FormattedMessage id="LOCATION_ID"/></label> |
28 | | - <Suspense fallback={<div>Loading location picker...</div>}> |
29 | | - <TreeSelect |
30 | | - id="location-tree-select" |
31 | | - treeData={locationOptions} |
32 | | - value={store.getFieldValue("location", "locationId") ?? ""} |
33 | | - treeNodeFilterProp="value" |
34 | | - treeLine |
35 | | - showSearch |
36 | | - size="large" |
37 | | - allowClear |
38 | | - style={{ width: "100%" }} |
39 | | - placeholder="Select locations" |
40 | | - dropdownStyle={{ maxHeight: "500px", zIndex: 9999 }} |
41 | | - onChange={(val) => |
42 | | - store.setFieldValue("location", "locationId", val) |
43 | | - } |
44 | | - /> |
45 | | - </Suspense> |
46 | | - <SelectInput |
47 | | - label="COUNTRY" |
48 | | - value={store.getFieldValue("location", "country") ?? ""} |
49 | | - onChange={(v) => |
50 | | - store.setFieldValue("location", "country", v) |
51 | | - } |
52 | | - options={ |
53 | | - store.siteSettingsData?.country?.map((item) => { |
54 | | - return { |
55 | | - value: item, |
56 | | - label: item, |
57 | | - }; |
58 | | - }) || [] |
59 | | - } |
60 | | - className="mb-3" |
| 19 | + return ( |
| 20 | + <div> |
| 21 | + <TextInput |
| 22 | + label="LOCATION" |
| 23 | + value={store.getFieldValue("location", "verbatimLocality") ?? ""} |
| 24 | + onChange={(v) => store.setFieldValue("location", "verbatimLocality", v)} |
| 25 | + /> |
| 26 | + <h6 className="mt-1"> |
| 27 | + <FormattedMessage id="LOCATION_ID" /> |
| 28 | + </h6> |
| 29 | + <Suspense fallback={<div>Loading location picker...</div>}> |
| 30 | + <TreeSelect |
| 31 | + id="location-tree-select" |
| 32 | + treeData={locationOptions} |
| 33 | + value={store.getFieldValue("location", "locationId") ?? ""} |
| 34 | + treeNodeFilterProp="value" |
| 35 | + treeLine |
| 36 | + showSearch |
| 37 | + size="large" |
| 38 | + allowClear |
| 39 | + style={{ width: "100%" }} |
| 40 | + placeholder="Select locations" |
| 41 | + dropdownStyle={{ maxHeight: "500px", zIndex: 9999 }} |
| 42 | + onChange={(val) => store.setFieldValue("location", "locationId", val)} |
61 | 43 | /> |
62 | | - <CoordinatesInput store={store} /> |
63 | | - {store.errors.hasSectionError("location") && ( |
64 | | - <Alert variant="danger"> |
65 | | - {store.errors.getSectionErrors("location").join(";")} |
66 | | - </Alert> |
67 | | - )} |
| 44 | + </Suspense> |
| 45 | + <SelectInput |
| 46 | + label="COUNTRY" |
| 47 | + value={store.getFieldValue("location", "country") ?? ""} |
| 48 | + onChange={(v) => store.setFieldValue("location", "country", v)} |
| 49 | + options={ |
| 50 | + store.siteSettingsData?.country?.map((item) => { |
| 51 | + return { |
| 52 | + value: item, |
| 53 | + label: item, |
| 54 | + }; |
| 55 | + }) || [] |
| 56 | + } |
| 57 | + className="mb-3" |
| 58 | + /> |
| 59 | + <CoordinatesInput store={store} /> |
| 60 | + {store.errors.hasSectionError("location") && ( |
| 61 | + <Alert variant="danger"> |
| 62 | + {store.errors.getSectionErrors("location").join(";")} |
| 63 | + </Alert> |
| 64 | + )} |
68 | 65 | </div> |
69 | | -}) |
| 66 | + ); |
| 67 | +}); |
0 commit comments