-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathinfo-section.tsx
89 lines (84 loc) · 3.33 KB
/
info-section.tsx
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
import { Box, Heading } from '@chakra-ui/react';
import {
toggleStationSecondaryName,
updateStationName,
updateStationNum,
updateStationSecondaryName,
} from '../../../redux/param/action';
import { useRootDispatch, useRootSelector } from '../../../redux';
import { RmgStyle } from '../../../constants/constants';
import { RmgButtonGroup, RmgFields, RmgFieldsField } from '@railmapgen/rmg-components';
import { useTranslation } from 'react-i18next';
export default function InfoSection() {
const { t } = useTranslation();
const dispatch = useRootDispatch();
const selectedStation = useRootSelector(state => state.app.selectedStation);
console.log('InfoSection:: Rendering for', selectedStation);
const style = useRootSelector(state => state.param.style);
const { num, localisedName, localisedSecondaryName } = useRootSelector(
state => state.param.stn_list[selectedStation]
);
const fields: RmgFieldsField[] = [
{
type: 'input',
label: t('StationSidePanel.info.num'),
value: num,
placeholder: '01',
onChange: (value: string) => dispatch(updateStationNum(selectedStation, value)),
hidden: ![RmgStyle.GZMTR].includes(style),
},
{
type: 'input',
label: t('Chinese name'),
value: localisedName.zh ?? '',
onChange: (value: string) => dispatch(updateStationName(selectedStation, 'zh', value)),
},
{
type: 'input',
label: t('English name'),
value: localisedName.en ?? '',
onChange: (value: string) => dispatch(updateStationName(selectedStation, 'en', value)),
},
{
type: 'custom',
label: t('Secondary names'),
component: (
<RmgButtonGroup
selections={
[
{ label: t('Yes'), value: true },
{ label: t('No'), value: false },
] as { label: string; value: boolean }[]
}
defaultValue={!!localisedSecondaryName}
onChange={flag => dispatch(toggleStationSecondaryName(selectedStation, flag))}
/>
),
hidden: ![RmgStyle.GZMTR].includes(style),
},
{
type: 'input',
label: t('StationSidePanel.info.zhSecondary'),
value: localisedSecondaryName?.zh ?? '',
placeholder: '1号航站楼',
onChange: (value: string) => dispatch(updateStationSecondaryName(selectedStation, 'zh', value)),
hidden: !localisedSecondaryName || ![RmgStyle.GZMTR].includes(style),
},
{
type: 'input',
label: t('StationSidePanel.info.enSecondary'),
value: localisedSecondaryName?.en ?? '',
placeholder: 'Terminal 1',
onChange: (value: string) => dispatch(updateStationSecondaryName(selectedStation, 'en', value)),
hidden: !localisedSecondaryName || ![RmgStyle.GZMTR].includes(style),
},
];
return (
<Box p={1}>
<Heading as="h5" size="sm">
{t('StationSidePanel.info.title')}
</Heading>
<RmgFields fields={fields} minW={130} />
</Box>
);
}