ConfirmedShiftDetailScreen.js 13.7 KB
Newer Older
1 2 3 4
/* eslint-disable prettier/prettier */
import moment from 'moment';
import React from 'react';
import {
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
5
  FlatList,
6 7 8 9 10 11
  Image,
  SafeAreaView,
  ScrollView,
  TouchableOpacity,
  View,
} from 'react-native';
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
12
import AppText from '../../../../../components/AppText';
13
import ButtonComponent from '../../../../../components/ButtonComponent';
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
14 15
import TextInputComponent from '../../../../../components/TextInputComponent';
import colors from '../../../../../values/colors';
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
import {IconTimeSheet, IMAGES} from '../../../../../values/images';
import {mainStyle} from './style';
const ConfirmedShiftDetailScreen = ({
  numberWeekOfYear,
  managerDate,
  confirmSheetDetail,
  userInfo,
  prevWeek,
  nextWeek,
  getNumberWeekOfYear,
  totalTime,
  onCollapseView,
  onExpandView,
  feedBack,
  setFeedback,
  onSubmitApproveReq,
  onRejectApproveReq,
}) => {
  const renderItem = (item, index) => {
    return (
      <View
        key={`${item.title} ${index}`}
        style={{flex: 1, flexDirection: 'row'}}>
        {index !== 7 ? (
          <TouchableOpacity
            key={index}
            style={{
              flex: 1,
              flexDirection: 'row',
              margin: 5,
              borderWidth: 0.5,
              height: 30,
            }}>
            <View style={mainStyle.viewItemDay}>
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
50
              <AppText>{item.title ? item.title : ''}</AppText>
51 52 53 54 55 56 57
            </View>
            <View
              style={{
                flex: 4,
                justifyContent: 'center',
                alignItems: 'center',
              }}>
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
58
              <AppText>
59 60 61 62 63
                {item.time && item.time.toString().includes(':')
                  ? item.time
                  : item.time !== 0 && item.time !== ''
                  ? moment(item.time).format('HH:mm')
                  : '00:00'}
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
64
              </AppText>
65 66 67 68 69 70 71 72 73 74 75 76
            </View>
          </TouchableOpacity>
        ) : (
          <View
            style={{
              flex: 1,
              justifyContent: 'center',
              alignItems: 'center',
              margin: 5,
              borderWidth: 0.5,
              height: 30,
            }}>
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
77
            <AppText style={{color: '#ffa117', fontWeight: '500'}}>{`${
78
              item.title
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
79
            } ${totalTime || 0}`}</AppText>
80 81 82 83 84 85 86 87 88 89 90 91 92
          </View>
        )}
      </View>
    );
  };
  const NEED_APPROVE = 'cae086d1-38bb-40ac-bb12-708fc3c60959';
  const APPROVED = 'cdcda9f8-a051-49bc-b14b-927c98a9d17a';
  const REJECT_APPROVE = '0455039f-fa00-4b36-928d-5055b1498121';
  return (
    <SafeAreaView>
      {/* <HeaderComponent {...props} /> */}
      <ScrollView nestedScrollEnabled={true} style={{padding: 5}}>
        <View>
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
93
          <AppText style={{marginBottom: 16, fontWeight: 'bold'}}>
94
            {userInfo?.extend_user_full_name} -{userInfo?.employee_code}
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
95
          </AppText>
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
          <View style={[mainStyle.row, {justifyContent: 'space-between'}]}>
            <ButtonComponent
              style={{
                backgroundColor: '#e9eaf9',
                padding: 5,
              }}
              iconSource={IconTimeSheet.IcLeftForward}
              styleIcon={{height: 20, width: 20}}
              onPress={() => prevWeek()}
            />
            <View
              style={{
                flexDirection: 'row',
                backgroundColor: '#e9eaf9',
                justifyContent: 'center',
                alignItems: 'center',
                paddingLeft: 10,
                paddingRight: 10,
              }}>
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
115
              <AppText style={{color: '#615f71', fontWeight: '500'}}>
116
                {`Tuần ${numberWeekOfYear} `}{' '}
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
117 118
              </AppText>
              <AppText>{`${moment(managerDate?.currentDate).format(
119 120 121
                'DD/MM/YYYY',
              )} - ${moment(managerDate?.theWeekend).format(
                'DD/MM/YYYY',
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
122
              )}`}</AppText>
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
              <Image
                source={IMAGES.IcCalendarGray}
                style={{height: 20, width: 20, marginLeft: 10}}
              />
            </View>
            <ButtonComponent
              style={{
                backgroundColor: '#e9eaf9',
                padding: 5,
              }}
              iconSource={IconTimeSheet.IcRightForward}
              styleIcon={{height: 20, width: 20}}
              onPress={() => nextWeek()}
            />
          </View>
        </View>
        <View
          style={{
            flexDirection: 'row',
            alignItems: 'center',
            justifyContent: 'space-between',
            marginTop: 16,
          }}>
          <View style={mainStyle.boxButton}>
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
147
            <AppText style={{color: '#646c9a', fontWeight: 'bold'}}>
148
              Tổng giờ tuần này:{' '}
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
149 150 151 152
              <AppText style={{color: '#f9bf5a', fontWeight: 'bold'}}>
                22:00
              </AppText>
            </AppText>
153 154 155 156
          </View>
          <TouchableOpacity
            style={mainStyle.boxButton}
            onPress={() => getNumberWeekOfYear(new Date())}>
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
157 158 159
            <AppText style={{color: '#646c9a', fontWeight: 'bold'}}>
              Tuần này
            </AppText>
160 161 162 163
          </TouchableOpacity>
        </View>
        <View style={{marginTop: 10}}>
          {confirmSheetDetail?.timesheet?.length === 0 ? (
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
164
            <AppText style={{textAlign: 'center'}}>Không có dữ liệu</AppText>
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
          ) : (
            <View>
              {confirmSheetDetail &&
                confirmSheetDetail.map((item, index_arr) => {
                  return (
                    (item.isExpand && (
                      <View
                        key={item.timesheet_id}
                        style={{
                          backgroundColor: 'white',
                          padding: 5,
                        }}>
                        <ButtonComponent
                          iconSource={IconTimeSheet.IcCollapse}
                          styleIcon={{width: 30, height: 30}}
                          onPress={() => onCollapseView(index_arr)}
                          style={{alignItems: 'flex-end'}}
                        />
                        <View style={{padding: 10}}>
                          <View style={{marginBottom: 10}}>
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
185 186
                            <AppText style={mainStyle.subtitle}>Dự án</AppText>
                            <AppText style={mainStyle.txtItem}>
187
                              {item.projectName}
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
188
                            </AppText>
189 190
                          </View>
                          <View style={{marginBottom: 10}}>
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
191
                            <AppText style={mainStyle.subtitle}>
192
                              Tên công việc
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
193 194
                            </AppText>
                            <AppText style={mainStyle.txtItem}>
195
                              {item.taskName}
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
196
                            </AppText>
197 198
                          </View>
                          <View style={{marginBottom: 10}}>
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
199
                            <AppText style={mainStyle.subtitle}>
200
                              Ghi chú trong tuần
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
201 202
                            </AppText>
                            <AppText style={mainStyle.txtItem}>
203
                              {item.description}
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
204
                            </AppText>
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
                          </View>
                        </View>
                        <View>
                          <FlatList
                            data={item.calendar}
                            renderItem={({item, index}) =>
                              renderItem(item, index, index_arr)
                            }
                            listKey={(item, index) => `_key${index.toString()}`}
                            keyExtractor={(item, index) =>
                              `_key${index.toString()}`
                            }
                            numColumns={2}
                          />
                        </View>
                      </View>
                    )) || (
                      // collapse view
                      <TouchableOpacity
                        onPress={() => onExpandView(index_arr)}
                        key={`_key${index_arr.toString()}`}
                        style={[
                          mainStyle.collapseView,
                          {
                            borderLeftColor:
                              index_arr % 2 === 0 ? '#0abb87' : '#959595',
                          },
                        ]}>
                        <View style={{flexDirection: 'row'}}>
                          <View style={{justifyContent: 'flex-start', flex: 6}}>
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
235
                            <AppText
236 237 238 239 240 241
                              style={{
                                fontSize: 14,
                                color: 'black',
                                fontWeight: 'bold',
                              }}>
                              {item.projectName}
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
242 243
                            </AppText>
                            <AppText>{item.taskName}</AppText>
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
                          </View>
                          <TouchableOpacity
                            onPress={() => onExpandView(index_arr)}
                            style={{flex: 1, justifyContent: 'center'}}>
                            <Image
                              source={IMAGES.IcArrowRight}
                              style={{height: 20, width: 20}}
                            />
                          </TouchableOpacity>
                        </View>
                      </TouchableOpacity>
                    )
                  );
                })}
              {confirmSheetDetail.length > 0 &&
                confirmSheetDetail[0]?.equalApproveId && (
                  <View>
                    {confirmSheetDetail[0]?.isApproved == APPROVED && (
                      <View style={mainStyle.viewBtn}>
                        <ButtonComponent
                          style={[
                            mainStyle.viewSaveAndSendBtn,
                            {
                              backgroundColor: colors.grayE9,
                              marginRight: 10,
                            },
                          ]}
                          text={'Timesheet đã duyệt'}
                          textStyle={[
                            mainStyle.saveAndSendBtn,
                            {color: colors.blue5c},
                          ]}
                        />
                      </View>
                    )}
                    {confirmSheetDetail[0]?.isApproved == NEED_APPROVE && (
                      <View style={{marginTop: 10}}>
                        <TextInputComponent
                          styleAreaInput={{backgroundColor: 'white'}}
                          placeholder={'Nhận xét'}
                          keyboardType={'email-address'}
                          autoCapitalize="none"
                          noBorder={true}
                          value={feedBack}
                          onChangeText={text => setFeedback(text)}
                        />
                        {feedBack.length == 0 && (
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
291
                          <AppText
292 293 294 295 296 297
                            style={{
                              marginTop: -20,
                              color: 'red',
                              marginBottom: 10,
                            }}>
                            *Vui lòng nhập nhận xét
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
298
                          </AppText>
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
                        )}
                        <View style={mainStyle.viewBtn}>
                          <ButtonComponent
                            style={[
                              mainStyle.viewSaveAndSendBtn,
                              {
                                backgroundColor: colors.white,
                                marginRight: 10,
                                borderColor: colors.green0a,
                                borderWidth: 1.5,
                              },
                            ]}
                            text={'Duyệt'}
                            textStyle={[
                              mainStyle.saveAndSendBtn,
                              {color: colors.green0a},
                            ]}
                            onPress={onSubmitApproveReq}
                          />
                          <ButtonComponent
                            style={[
                              mainStyle.viewSaveAndSendBtn,
                              {
                                backgroundColor: colors.grayE9,
                              },
                            ]}
                            text={'Từ chối'}
                            textStyle={[
                              mainStyle.saveAndSendBtn,
                              {color: colors.blue5c},
                            ]}
                            onPress={onRejectApproveReq}
                          />
                        </View>
                      </View>
                    )}
                    {confirmSheetDetail[0]?.isApproved == REJECT_APPROVE && (
                      <View style={mainStyle.viewBtn}>
                        <ButtonComponent
                          style={[
                            mainStyle.viewSaveAndSendBtn,
                            {
                              backgroundColor: '#fae1ea',
                              marginRight: 10,
                            },
                          ]}
                          text={'Timesheet đã từ chối'}
                          textStyle={[
                            mainStyle.saveAndSendBtn,
                            {color: '#de3a71'},
                          ]}
                        />
                      </View>
                    )}
                  </View>
                )}
            </View>
          )}
        </View>
      </ScrollView>
    </SafeAreaView>
  );
};

export default ConfirmedShiftDetailScreen;