import React, { useEffect, useRef, useState } from 'react' import { MultiSelect } from 'react-multi-select-component' import { Col, Label, Row } from 'reactstrap' import Select from 'react-select' import { Button as ButtonP } from 'primereact/button' import { isObjEmpty } from '../../kytp/util' import jquery from 'jquery' import collect from 'collect.js' import { useDispatch, useSelector } from 'react-redux' import { setCqlFilterWilayah, setSelectedOpsi } from '../../kytp/store/PetaStore' import { matoaLayers } from '../layers/overlayLayers' import { useMap } from 'react-leaflet' const NipPerekam = ({ dataSend, setDataSend, activeTab, toast, setHiddenGraphMatoa, dataOpsi, setIsOpenPopUpWilayah, refFeatureBawah }) => { const map = useMap() const dispatch = useDispatch() const storeKpdl = useSelector((state) => state.kpdl) const base_url = '/engineN/' const [kanwil, setKanwil] = useState([]) const [kpp, setKpp] = useState([]) const [seksi, setSeksi] = useState([]) const [ar, setAr] = useState([]) const [kanwilSelected, setKanwilSelected] = useState(null) const [kppSelected, setKppSelected] = useState() const [seksiSelected, setSeksiSelected] = useState([]) const [arSelected, setArSelected] = useState([]) useEffect(() => { jquery.ajax({ url: base_url + 'kewilayahan/ref/kanwilPratama', method: 'GET', dataType: 'json', success: (data) => { setKanwil(data) } }) }, []) useEffect(() => { setKpp([]) setSeksi([]) setAr([]) setKppSelected(null) setSeksiSelected([]) setArSelected([]) if (kanwilSelected && !isObjEmpty(kanwilSelected)) { const kanwil = kanwilSelected.value jquery.ajax({ url: base_url + 'kewilayahan/ref/kppPratama', method: 'GET', dataType: 'json', data: { kanwil }, success: (data) => { setKpp(data) } }) } }, [kanwilSelected]) useEffect(() => { setSeksi([]) setAr([]) setSeksiSelected([]) setArSelected([]) if (kppSelected && !isObjEmpty(kppSelected)) { const kpp = kppSelected.value jquery.ajax({ url: base_url + 'kewilayahan/ref/seksi', method: 'GET', dataType: 'json', data: { kpp }, success: (data) => { setSeksi(data) } }) } }, [kppSelected]) useEffect(() => { setAr([]) setArSelected([]) const seksi = collect(seksiSelected).pluck('value').all() if (seksi.length && !isObjEmpty(seksiSelected)) { const kpp = kppSelected.value // const seksi = collect(seksiSelected).pluck("value").all() jquery.ajax({ url: base_url + 'kewilayahan/ref/ar', method: 'POST', dataType: 'json', data: { kpp, seksi }, success: (data) => { setAr(data) } }) } }, [seksiSelected]) const buttonProsesOnClick = () => { refFeatureBawah.current.clearLayers() const nip_ar_perekam = collect(arSelected).pluck('value').all() const nip_ar_perekam2 = collect(arSelected).pluck('value2').all() if (nip_ar_perekam.length) { dispatch(setSelectedOpsi(dataOpsi.perekam)) setDataSend({ opsiWilZona: dataOpsi.perekam.key, nip_ar_perekam }) const par_perekam = nip_ar_perekam2.join("','") const cq_filter_poi = "CREATED_BY in ('" + par_perekam + "')" dispatch(setCqlFilterWilayah(cq_filter_poi)) matoaLayers.poiMatoaNpwpLayer.setParams({ styles: 'poi_matoa_npwp', cql_filter: cq_filter_poi, minZoom: 4 }) matoaLayers.poiMatoaNpwpNullLayer.setParams({ styles: 'poi_matoa_npwp', cql_filter: cq_filter_poi, minZoom: 4 }) map.setZoom(8) setIsOpenPopUpWilayah(false) } else { toast.current.show({ severity: 'info', summary: 'Info', detail: 'AR Perekam harus dipilih' }) } } return ( <> { setKppSelected(e) }} onMenuOpen={() => { if (!kpp.length) { return } }} openMenuOnClick={() => { if (!kpp.length) { return } }} classNamePrefix="select" // defaultValue={kanwilSelected} value={kppSelected} isClearable={false} options={kpp} /> { setSeksiSelected(e) }} labelledBy="Pilih Seksi" overrideStrings={{ allItemsAreSelected: 'Semua dipilih', selectSomeItems: 'Pilih Seksi' }} /> { setArSelected(e) }} labelledBy="Pilih AR" overrideStrings={{ allItemsAreSelected: 'Semua dipilih', selectSomeItems: 'Pilih AR' }} /> buttonProsesOnClick()} label="Proses" severity="" rounded className="w-10rem text-white text-base" /> ) } export default NipPerekam