DocumentManagement.js 17.2 KB
Newer Older
Deni Rinaldi's avatar
Deni Rinaldi committed
1
import React, { Component } from 'react'
Deni Rinaldi's avatar
Deni Rinaldi committed
2
import { Tabs, Tab, Typography, Paper, withStyles, Snackbar } from '@material-ui/core'
Deni Rinaldi's avatar
Deni Rinaldi committed
3 4 5 6 7
import ReactTooltip from 'react-tooltip'
import Images from '../../assets/Images'
import ManualBookTia from './ManualBookTia'
import api from '../../api'
import AuditTahunan from './AuditTahunan'
Deni Rinaldi's avatar
Deni Rinaldi committed
8
import CreateManagementDoc from './CreateManagementDoc'
9
import AllDocument from './AllDocument'
10
import QReview from './QReview'
11 12
import BOD from './BOD'
import ManualBookETMS from './ManualBookETMS'
Deni Rinaldi's avatar
Deni Rinaldi committed
13 14 15
import PopUpKonfirmasi from "./PopUpKonfirmasi";
import Constant from '../../library/Constant'
import MuiAlert from '@material-ui/lab/Alert';
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
16
import PropagateLoader from "react-spinners/PropagateLoader"
Deni Rinaldi's avatar
Deni Rinaldi committed
17 18 19

const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);
Deni Rinaldi's avatar
Deni Rinaldi committed
20 21 22 23 24 25 26

export default class DocumentManagement extends Component {
    constructor(props) {
        super(props)
        this.state = {
            tab: 0,
            listData: [],
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
27 28 29 30 31
            id: 0,
            btncreate: false,
            btnedit: false,
            btndelete: false,
            load: false,
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
32 33
            name: '',
            userCompActive: []
Deni Rinaldi's avatar
Deni Rinaldi committed
34 35 36
        }
    }

Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
37 38 39 40 41
    getPermission() {
        let payload = {
            menu: "document management"
        }
        api.create().getPermission(payload).then(response => {
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
42
            // console.log(response)
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({
                        btncreate: response.data.data.create,
                        btnedit: response.data.data.edit,
                        btndelete: response.data.data.delete,
                        load: true
                    })
                } else {
                    this.setState({
                        load: true
                    })
                }
            } else {
                this.setState({ load: true })
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
62 63
    selectTab = (event, newEvent) => {
        this.setState({ tab: newEvent })
64
        // console.log(this.state.tab)
Deni Rinaldi's avatar
Deni Rinaldi committed
65 66 67 68
    }

    componentDidMount() {
        this.getDataDocument()
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
69
        this.getPermission()
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
70
        this.getDetailUser()
Deni Rinaldi's avatar
Deni Rinaldi committed
71 72
    }

Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
73
    getDataDocument(id, name) {
74
        api.create().getDocumentCategory().then(response => {
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
75
            // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
76 77 78 79 80
            if (response) {
                if (response.data.status === "success") {
                    this.setState({
                        listData: response.data.data,
                        id: id === undefined ? response.data.data[0].setting_id : id,
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
81
                        name: name === undefined ? response.data.data[0].value : name,
Deni Rinaldi's avatar
Deni Rinaldi committed
82 83 84 85 86
                        loadTable: true,
                        refresh: id === undefined ? '' : 'create'
                    })
                }
            } else {
r.kurnia's avatar
r.kurnia committed
87
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
88
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
89 90 91
        })
    }

Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
92
    createDocument(payload, settingID, menuName) {
93
        this.setState({ loading: true })
Deni Rinaldi's avatar
Deni Rinaldi committed
94
        api.create().uploadDocument(payload).then(response => {
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
95
            // console.log(response)
Deni Rinaldi's avatar
Deni Rinaldi committed
96 97 98
            if (response.data) {
                if (response.ok) {
                    if (response.data.message === "The Document Already Exists in The System, Do You Want to Overwrite It?") {
99
                        this.setState({ konfirmasi: true, formData: payload, docId: response.data.data.document_id, settingID, menuName, loading: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
100
                    }
101
                    else if (response.data.message === "Data was Saved Successfully") {
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
102
                        this.getDataDocument(settingID, menuName)
103
                        this.setState({ visibleCreate: false,  loading: false, alert: true, messageAlert: response.data.message, tipeAlert: 'success', settingID, menuName})
Deni Rinaldi's avatar
Deni Rinaldi committed
104 105
                    }
                    else {
106
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
107 108 109 110 111 112 113 114 115
                            if (response.data.message.includes("Someone Logged In")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
                } else {
116
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
117 118
                }
            } else {
119
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
120 121 122 123 124
            }
        })
    }

    createUploadDocument() {
125
        this.setState({ visibleCreate: false, konfirmasi: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
126 127
        const formData = this.state.formData
        formData.append("documentId", this.state.docId)
128
        formData.append("updated", 1)
129
        this.setState({ loading: true })
Deni Rinaldi's avatar
Deni Rinaldi committed
130
        api.create().updateDocument(formData).then(response => {
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
131
            // console.log(response)
Deni Rinaldi's avatar
Deni Rinaldi committed
132 133 134
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === "success") {
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
135
                        this.getDataDocument(this.state.settingID, this.state.menuName)
136
                        this.setState({ konfirmasi: false, alert: true, messageAlert: response.data.message, tipeAlert: 'success', visibleCreate: false, loading: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
137
                    } else {
138
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
139 140 141 142 143 144 145 146 147
                            if (response.data.message.includes("Someone Logged In")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
                } else {
148
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
149 150
                }
            } else {
151
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
152 153 154 155
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
156
    getID(id) {
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
157
        // console.log(id);
Deni Rinaldi's avatar
Deni Rinaldi committed
158 159 160
        this.setState({ id })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
161 162 163 164
    closeAlert() {
        this.setState({ alert: false })
    }

Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
    handleLoading(tipe) {
        this.setState({ loading: tipe == 0 ? false : true })
    }

    getDetailUser() {
        let userId = localStorage.getItem(Constant.USER)
        api.create().getDetailUser(userId).then((response) => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        this.setState({ userCompany: response.data.data.company, visibleTrue: false }, () => {
                            this.getCompanyActive()
                        })
                    }
                }
            }
        })
    }

    getCompanyActive() {
        api.create().getPerusahaanActive().then((response) => {
            if (response.data) {
                if (response.data.status === 'success') {
                    let data = response.data.data
                    let compActive = []
                    let userCompActive = []
                    this.state.userCompany.map((item, index) => {
                        let indeks = data.findIndex((val) => val.company_id == item)
                        if (indeks !== -1 && String(data[indeks].status).toLocaleLowerCase() == 'active'){
                            userCompActive.push(item)
                        }
                    })
                    data.map(( item, index ) => {
                        if (String(item.status).toLocaleLowerCase() == 'active') {
                            compActive.push(item)
                        }
                    })
                    if (compActive.length == userCompActive.length){
                        this.setState({ btnadd: true})
                    } else {
                        this.setState({ btnadd: false})
                    }
                    this.setState({ userCompActive, visibleTrue: true })
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
208
                    // console.log(userCompActive)
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', visibleTrue: true }, () => {
                        if (response.data.message.includes("Someone Logged In")) {
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listCompany: null, company: null, visibleTrue: true })
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
225
    render() {
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
226
        const loadingComponent = (
227
            <div style={{ position: 'absolute', zIndex: 1500, top: 0, left: 0, width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', background: 'rgba(255,255,255,0.8)' }}>
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
228 229 230 231 232 233 234 235
                <PropagateLoader
                    // css={override}
                    size={20}
                    color={"#274B80"}
                    loading={this.state.loading}
                />
            </div>
        );
Deni Rinaldi's avatar
Deni Rinaldi committed
236 237
        return (
            <div style={{ height: this.props.height, backgroundColor: '#f8f8f8' }}>
238
                {/* {this.props.load && ()} */}
Deni Rinaldi's avatar
Deni Rinaldi committed
239 240 241 242 243
                <Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
                    <Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
                        {this.state.messageAlert}
                    </Alert>
                </Snackbar>
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
244
                
Deni Rinaldi's avatar
Deni Rinaldi committed
245
                <div className={"main-color"} style={{ height: 78, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
246
                    <Typography style={{ fontSize: '16px', color: 'white' }}>Document Management</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
247 248
                </div>
                <div style={{ padding: 20 }}>
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
249
                {this.state.loading && loadingComponent}
Deni Rinaldi's avatar
Deni Rinaldi committed
250
                    <Paper style={{ padding: 20 }}>
251
                        <div style={{ display: 'flex', justifyContent: 'flex-end' }}>
252
                        {(this.state.btncreate) && <span>
253 254 255 256 257 258 259 260 261 262 263 264 265
                            <a data-tip={'Add'} data-for="add">
                                <div style={{ display: 'grid', justifyContent: 'flex-end' }}>
                                    <button
                                        type="button"
                                        onClick={() => this.setState({ visibleCreate: true, refresh: '' })}
                                        style={{ marginRight: 25, background: 'transparent' }}
                                    >
                                        <img src={Images.add} />
                                    </button>
                                </div>
                            </a>
                            <ReactTooltip border={true} id="add" place="bottom" type="light" effect="solid" />
                        </span>}
Deni Rinaldi's avatar
Deni Rinaldi committed
266
                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
267 268 269 270 271 272 273 274 275 276 277 278
                        <div style={{ display: 'flex' }}>
                            <Tabs
                                orientation="vertical"
                                variant="scrollable"
                                value={this.state.tab}
                                onChange={this.selectTab}
                                aria-label="simple tabs example"
                                style={{ width: 350 }}
                            >
                                {this.state.listData.map((item, index) => {
                                    return (
                                        <Tab
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
279
                                            onClick={() => this.setState({ name: item.value, id: item.setting_id, refresh: '', loadTable : false }, () => this.setState({loadTable: true}))}
Deni Rinaldi's avatar
Deni Rinaldi committed
280
                                            label={item.value}
Deni Rinaldi's avatar
Deni Rinaldi committed
281 282 283 284
                                        />
                                    )
                                })}
                            </Tabs>
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
285
                            {this.state.loadTable && this.state.visibleTrue && (
286 287 288 289 290 291 292
                                <AllDocument
                                    data={this.state.listData[this.state.tab]}
                                    refresh={this.state.refresh}
                                    btnedit={this.state.btnedit}
                                    btndelete={this.state.btndelete}
                                    load={this.state.load}
                                    setId={this.state.id}
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
293
                                    userCompActive={this.state.userCompActive}
294
                                    allsubcoEdit={this.state.btnadd}
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
295
                                    handleLoading={this.handleLoading.bind(this)}
296
                                    name={this.state.name}
297 298 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
                                />
                                // this.state.id === 68542 ?
                                //     <AuditTahunan
                                //         data={this.state.listData[this.state.tab]}
                                //         refresh={this.state.refresh}
                                //         btnedit={this.state.btnedit}
                                //         btndelete={this.state.btndelete}
                                //         load={this.state.load}
                                //     />
                                //     :
                                //     this.state.id === 68541 ?
                                //         <ManualBookTia
                                //             data={this.state.listData[this.state.tab]}
                                //             refresh={this.state.refresh}
                                //             btnedit={this.state.btnedit}
                                //             btndelete={this.state.btndelete}
                                //             load={this.state.load}
                                //         />
                                //         :
                                //         this.state.id === 68544 ?
                                //             <QReview
                                //                 data={this.state.listData[this.state.tab]}
                                //                 refresh={this.state.refresh}
                                //                 btnedit={this.state.btnedit}
                                //                 btndelete={this.state.btndelete}
                                //                 load={this.state.load}
                                //             />
                                //             :
                                //             this.state.id === 68543 ?
                                //                 <BOD
                                //                     data={this.state.listData[this.state.tab]}
                                //                     refresh={this.state.refresh}
                                //                     btnedit={this.state.btnedit}
                                //                     btndelete={this.state.btndelete}
                                //                     load={this.state.load}
                                //                 />
                                //                 // :
                                //                 // this.state.id === 68545 ?
                                //                 //     <ManualBookETMS
                                //                 //         data={this.state.listData[this.state.tab]}
                                //                 //         refresh={this.state.refresh}
                                //                 //     />
                                //                     :
                                //                     <span>Coming Soon</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
341 342 343 344 345 346

                            )}
                        </div>

                    </Paper>
                </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
347 348 349 350 351 352
                {this.state.konfirmasi && (
                    <PopUpKonfirmasi
                        onClickClosePopUp={() => this.setState({ konfirmasi: false })}
                        uploadDocId={this.createUploadDocument.bind(this)}
                    />
                )}
Deni Rinaldi's avatar
Deni Rinaldi committed
353 354 355
                {this.state.visibleCreate && (
                    <CreateManagementDoc
                        onClickClose={() => this.setState({ visibleCreate: false })}
Deni Rinaldi's avatar
Deni Rinaldi committed
356 357
                        // getDataDocument={this.getDataDocument.bind(this)}
                        createDocument={this.createDocument.bind(this)}
Deni Rinaldi's avatar
Deni Rinaldi committed
358
                        setting_id={this.state.id}
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
359
                        name={this.state.name}
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
360
                        handleLoading={this.handleLoading.bind(this)}
361
                        allsubcoCreate={this.state.btnadd}
Deni Rinaldi's avatar
Deni Rinaldi committed
362 363
                    />
                )}
Deni Rinaldi's avatar
Deni Rinaldi committed
364 365 366 367
            </div>
        )
    }
}