@eohjsc/react-native-smart-city 0.2.47 → 0.2.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/README.md +9 -0
  2. package/package.json +24 -4
  3. package/src/commons/Dashboard/MyPinnedSharedUnit/styles.js +1 -1
  4. package/src/commons/Device/HistoryChart.js +133 -14
  5. package/src/commons/Device/HorizontalBarChart.js +30 -3
  6. package/src/commons/Device/LinearChart.js +2 -7
  7. package/src/commons/ThreeButtonHistory/CalendarHeader.js +35 -0
  8. package/src/commons/ThreeButtonHistory/CalendarHeaderStyles.js +17 -0
  9. package/src/commons/ThreeButtonHistory/SelectMonth.js +53 -0
  10. package/src/commons/ThreeButtonHistory/SelectMonthStyles.js +29 -0
  11. package/src/commons/ThreeButtonHistory/__test__/SelectMonth.test.js +37 -0
  12. package/src/commons/ThreeButtonHistory/__test__/ThreeButtonHistory.test.js +231 -0
  13. package/src/commons/ThreeButtonHistory/index.js +281 -0
  14. package/src/commons/ThreeButtonHistory/styles.js +65 -0
  15. package/src/configs/Constants.js +4 -0
  16. package/src/screens/ActivityLog/__test__/ItemLog.test.js +0 -20
  17. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +10 -1
  18. package/src/screens/AddNewOneTap/index.js +3 -3
  19. package/src/screens/ScriptDetail/index.js +18 -9
  20. package/src/screens/SetSchedule/__test__/SelectWeekday.test.js +2 -2
  21. package/src/screens/SetSchedule/components/SelectWeekday.js +13 -7
  22. package/src/screens/SubUnit/AddSubUnit.js +2 -2
  23. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +1 -0
  24. package/src/screens/Unit/SmartAccount.js +1 -1
  25. package/src/screens/UnitSummary/components/3PPowerConsumption/index.js +17 -5
  26. package/src/screens/UnitSummary/components/PowerConsumption/index.js +19 -6
  27. package/src/screens/UnitSummary/index.js +1 -5
  28. package/src/utils/I18n/translations/en.json +3 -0
  29. package/src/utils/I18n/translations/vi.json +3 -0
@@ -28,7 +28,7 @@ test('test select', async () => {
28
28
  await act(async () => {
29
29
  await items[0].props.onPress();
30
30
  });
31
- expect(mockSetWeekday).toBeCalledWith(['0']);
31
+ expect(mockSetWeekday).toBeCalledWith(['1']);
32
32
 
33
33
  mockSetWeekday.mockClear();
34
34
  props = {
@@ -44,5 +44,5 @@ test('test select', async () => {
44
44
  await act(async () => {
45
45
  await items[0].props.onPress();
46
46
  });
47
- expect(mockSetWeekday).toBeCalledWith([]);
47
+ expect(mockSetWeekday).toBeCalledWith(['0', '1']);
48
48
  });
@@ -5,7 +5,15 @@ import { Colors } from '../../../configs';
5
5
  import styles from '../styles/SelectWeekdayStyles';
6
6
  import { useTranslations } from '../../../hooks/Common/useTranslations';
7
7
 
8
- const WEEKDAY_ITEMS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
8
+ const WEEKDAY_ITEMS = [
9
+ { day: 'Mon', value: 1 },
10
+ { day: 'Tue', value: 2 },
11
+ { day: 'Wed', value: 3 },
12
+ { day: 'Thu', value: 4 },
13
+ { day: 'Fri', value: 5 },
14
+ { day: 'Sat', value: 6 },
15
+ { day: 'Sun', value: 0 },
16
+ ];
9
17
 
10
18
  const SelectWeekday = ({ weekday, setWeekday }) => {
11
19
  const t = useTranslations();
@@ -23,11 +31,10 @@ const SelectWeekday = ({ weekday, setWeekday }) => {
23
31
  );
24
32
 
25
33
  const WeekdayItem = useCallback(
26
- ({ item, index, isSelected }) => {
34
+ ({ item, isSelected }) => {
27
35
  return (
28
36
  <TouchableOpacity
29
- key={index}
30
- onPress={() => onSetWeekday(`${index}`)}
37
+ onPress={() => onSetWeekday(`${item?.value}`)}
31
38
  style={[styles.item, isSelected && styles.selected]}
32
39
  >
33
40
  <Text
@@ -36,7 +43,7 @@ const SelectWeekday = ({ weekday, setWeekday }) => {
36
43
  style={styles.text}
37
44
  semibold
38
45
  >
39
- {item}
46
+ {item?.day}
40
47
  </Text>
41
48
  </TouchableOpacity>
42
49
  );
@@ -54,8 +61,7 @@ const SelectWeekday = ({ weekday, setWeekday }) => {
54
61
  <WeekdayItem
55
62
  key={index}
56
63
  item={item}
57
- index={index}
58
- isSelected={weekday.includes(`${index}`)}
64
+ isSelected={weekday.includes(`${item?.value}`)}
59
65
  />
60
66
  ))}
61
67
  </View>
@@ -34,9 +34,9 @@ const prepareImageToUpload = async (image) => {
34
34
  70
35
35
  );
36
36
  return {
37
- fileName: result.name,
37
+ fileName: result?.name,
38
38
  type: 'image/jpeg',
39
- uri: result.uri,
39
+ uri: result?.uri,
40
40
  };
41
41
  };
42
42
 
@@ -24,6 +24,7 @@ const mockedGoBack = jest.fn();
24
24
 
25
25
  jest.mock('axios');
26
26
  jest.mock('react-native-toast-message');
27
+ jest.mock('react-native-image-resizer');
27
28
 
28
29
  jest.mock('react-redux', () => {
29
30
  return {
@@ -20,7 +20,7 @@ import { useTranslations } from '../../hooks/Common/useTranslations';
20
20
  import { useStateAlertRemove } from '../Unit/hook/useStateAlertRemove';
21
21
 
22
22
  const ListSmartAccount = ({ route }) => {
23
- const { unitId } = route.params;
23
+ const { unitId } = route?.params || {};
24
24
  const t = useTranslations();
25
25
  const [data, setData] = useState([]);
26
26
  const smartAccountRef = useRef(null);
@@ -141,13 +141,20 @@ const ThreePhasePowerConsumption = memo(({ unit, summary, summaryDetail }) => {
141
141
  moment().subtract(7, 'days').valueOf()
142
142
  );
143
143
  const [endDate, setEndDate] = useState(moment().valueOf());
144
+ const [groupBy, setGroupBy] = useState('date');
144
145
  const [getData, setData] = useState({});
146
+ const [chartConfig, setChartConfig] = useState({
147
+ unit: 'kWh',
148
+ price: '',
149
+ });
150
+
145
151
  useEffect(() => {
146
152
  const fetchData = async () => {
147
153
  let params = new URLSearchParams();
148
154
  params.append('config', listConfigs.total_power);
149
- params.append('date_from', new Date(startDate).setHours(0, 0) / 1000);
150
- params.append('date_to', new Date(endDate).setHours(23, 59) / 1000);
155
+ params.append('group_by', groupBy);
156
+ params.append('date_from', moment(startDate).format('YYYY-MM-DD'));
157
+ params.append('date_to', moment(endDate).format('YYYY-MM-DD'));
151
158
  const { success, data } = await axiosGet(
152
159
  API.POWER_CONSUME.DISPLAY_HISTORY,
153
160
  {
@@ -161,7 +168,7 @@ const ThreePhasePowerConsumption = memo(({ unit, summary, summaryDetail }) => {
161
168
  if (listConfigs?.total_power) {
162
169
  fetchData();
163
170
  }
164
- }, [startDate, endDate, listConfigs]);
171
+ }, [startDate, endDate, listConfigs, groupBy]);
165
172
  return (
166
173
  <>
167
174
  <Section type={'border'}>
@@ -239,13 +246,18 @@ const ThreePhasePowerConsumption = memo(({ unit, summary, summaryDetail }) => {
239
246
  <PMSensorIndicatior data={dataTotal} style={styles.styleTotalPower} />
240
247
  {!!getData?.length && (
241
248
  <HistoryChart
242
- unit={'kWh'}
243
249
  datas={getData}
250
+ chartConfig={chartConfig}
251
+ setChartConfig={setChartConfig}
244
252
  formatType={'date'}
245
253
  startDate={startDate}
246
254
  setEndDate={setEndDate}
247
255
  setStartDate={setStartDate}
248
- configuration={{ type: 'horizontal_bar_chart' }}
256
+ setGroupBy={setGroupBy}
257
+ configuration={{
258
+ type: 'horizontal_bar_chart',
259
+ config: 'power_consumption',
260
+ }}
249
261
  />
250
262
  )}
251
263
  </Section>
@@ -81,13 +81,20 @@ const PowerConsumption = memo(({ summaryDetail }) => {
81
81
  moment().subtract(7, 'days').valueOf()
82
82
  );
83
83
  const [endDate, setEndDate] = useState(moment().valueOf());
84
- const [getData, setData] = useState({});
84
+ const [groupBy, setGroupBy] = useState('date');
85
+ const [getData, setData] = useState([]);
86
+ const [chartConfig, setChartConfig] = useState({
87
+ unit: 'kWh',
88
+ price: '',
89
+ });
90
+
85
91
  useEffect(() => {
86
92
  const fetchData = async () => {
87
93
  let params = new URLSearchParams();
88
94
  params.append('config', listConfigs.total_power);
89
- params.append('date_from', new Date(startDate).setHours(0, 0) / 1000);
90
- params.append('date_to', new Date(endDate).setHours(23, 59) / 1000);
95
+ params.append('group_by', groupBy);
96
+ params.append('date_from', moment(startDate).format('YYYY-MM-DD'));
97
+ params.append('date_to', moment(endDate).format('YYYY-MM-DD'));
91
98
  const { success, data } = await axiosGet(
92
99
  API.POWER_CONSUME.DISPLAY_HISTORY(),
93
100
  {
@@ -101,7 +108,7 @@ const PowerConsumption = memo(({ summaryDetail }) => {
101
108
  if (listConfigs?.total_power) {
102
109
  fetchData();
103
110
  }
104
- }, [startDate, endDate, listConfigs]);
111
+ }, [startDate, endDate, listConfigs, groupBy]);
105
112
  return (
106
113
  <>
107
114
  <Section type={'border'}>
@@ -145,13 +152,19 @@ const PowerConsumption = memo(({ summaryDetail }) => {
145
152
  <PMSensorIndicatior data={dataTotal} style={styles.styleTotalPower} />
146
153
  {!!getData?.length && (
147
154
  <HistoryChart
148
- unit={'kWh'}
149
155
  datas={getData}
156
+ chartConfig={chartConfig}
157
+ setChartConfig={setChartConfig}
150
158
  formatType={'date'}
151
159
  startDate={startDate}
160
+ endDate={endDate}
152
161
  setEndDate={setEndDate}
153
162
  setStartDate={setStartDate}
154
- configuration={{ type: 'horizontal_bar_chart' }}
163
+ setGroupBy={setGroupBy}
164
+ configuration={{
165
+ type: 'horizontal_bar_chart',
166
+ config: 'power_consumption',
167
+ }}
155
168
  />
156
169
  )}
157
170
  </Section>
@@ -133,14 +133,10 @@ const UnitSummary = memo(({ route }) => {
133
133
  export default UnitSummary;
134
134
 
135
135
  const styles = StyleSheet.create({
136
- scrollView: {
137
- flex: 1,
138
- backgroundColor: Colors.Gray2,
139
- paddingTop: 50,
140
- },
141
136
  container: {
142
137
  flex: 1,
143
138
  backgroundColor: Colors.Gray2,
139
+ paddingBottom: 60,
144
140
  },
145
141
  textHeader: {
146
142
  color: Colors.Gray9,
@@ -379,6 +379,9 @@
379
379
  "saved_vehicle": "Saved Vehicle",
380
380
  "set_a_number": "Set a number",
381
381
  "text_total_power_consumption": "Total Power Consumption",
382
+ "input_price_to_calculate_electricity_cost": "Input price to calculate electricity cost",
383
+ "calculate_cost": "Calculate cost",
384
+ "total_power_price": "Total power price:",
382
385
  "smart_parking": "Smart Parking",
383
386
  "smart_parking_add_destination": "I would like to park near...",
384
387
  "see_nearby_parking": "See nearby parking areas",
@@ -412,6 +412,9 @@
412
412
  "save_this_vehicle": "Lưu và đặt phương tiện mặc định",
413
413
  "saved_vehicle": "Phương tiện đã lưu",
414
414
  "text_total_power_consumption": "Tổng điện năng tiêu thụ",
415
+ "input_price_to_calculate_electricity_cost": "Nhập số tiền để tính giá tiền điện đã sử dụng",
416
+ "calculate_cost": "Tính giá điện",
417
+ "total_power_price": "Tổng giá điện:",
415
418
  "smart_parking": "Smart Parking",
416
419
  "smart_parking_add_destination": "Tôi muốn đỗ xe gần...",
417
420
  "add_card": "Thêm thẻ",