commit 034a5be6a73c467c7ec2275e4242b8dd9603adea Author: GherilArofani1 Date: Thu Aug 8 14:23:21 2024 +0700 dashboard diff --git a/dashboard b/dashboard new file mode 100644 index 0000000..11ec616 --- /dev/null +++ b/dashboard @@ -0,0 +1,2083 @@ +/* eslint-disable react-hooks/exhaustive-deps */ +import { + View, + Image, + Switch, + TouchableOpacity, + RefreshControl, + Modal, +} from 'react-native'; +import React, {useState, useEffect, useCallback, useRef} from 'react'; +import moment from 'moment'; +import { StyleSheet } from 'react-native'; +import Icons from 'react-native-vector-icons/Ionicons'; +import {useSelector, useDispatch} from 'react-redux'; +import { + IconArrowNarrowLeft, + IconArrowNarrowRight, + IconCheckupList, + IconClipboardData, + IconCoin, + IconCpu2, + IconDatabaseSearch, + IconDots, + IconDropletHalf, + IconEdit, + IconFlag3, + IconInfoCircle, + IconMapPin, + IconMapPinFilled, + IconPlug, + IconTexture, + IconTrophy, + IconCirclePlus, + IconCaretDownFilled, + IconTrash, + IconPower, +} from 'tabler-icons-react-native'; +import {addEventListener} from '@react-native-community/netinfo'; +import { + getPlantsFertils, + browseCultivationByQuery, + browseLocationByQuery, + addRSC, + editCultivation, +} from '../../redux/actions/farms'; +import KelanaStatusBar from '../../components/statusbars'; +import KelanaNavbar from '../../components/navbars'; +import tw from '../../utils/tailwind'; +import { + ContainerScrollView, + ModalBasic, + TextBasic, +} from '../../components/main'; +import {CardBasic} from '../../components/cards'; +import {TextInputBasic,TextAreaTypeA, TextInputTypeA} from '../../components/fields'; +import {useBle, bleManager} from '../../utils/useBle'; +import {setGlobalAlert} from '../../redux/reducers/globalSlice'; +import {ButtonCircle, ButtonRegular,ButtonParent} from '../../components/buttons'; +import { + setConnectedDevice, + setSensorDevices, +} from '../../redux/reducers/farmSlice'; +import {Constants} from '../../utils/constants'; +import DateTimePickerModal from 'react-native-modal-datetime-picker'; +import MQTT from 'sp-react-native-mqtt'; +import { Table, Row, Rows } from 'react-native-table-component'; +const CustomCardA = ({ + title, + titleStyle, + content = null, + onPressInfo, + onPress, + onPressShow, + headerStyle, + isContentShow = false, + isButtonAdd = true, +}) => { + return ( + + + + + {title} + + + + + + {isContentShow ? ( + content ? ( + content + ) : ( + + + {'Klik tambah untuk menambah item.'} + + + ) + ) : null} + + ); +}; + + +const styles = StyleSheet.create({ + tableHeader: { + height: 40, + backgroundColor: '#f1f8ff' + }, + tableHeaderText: { + TextAlign: 'center', + fontWeight: 'bold', + fontSize: 14 + }, + tableRow: { + height: 40 + }, + tableRowText: { + TextAlign: 'center', + fontSize: 12 + } +}); + +const FarmDetail = ({navigation, route}) => { + const {detailFarm} = route.params; + const dispatch = useDispatch(); + const {user} = useSelector(state => state.user); + const { + loadingRSC, + plants, + cultivations, + locations, + sensorDevices, + connectedDevice, + } = useSelector(state => state.farm); + let connectedDeviceParse = connectedDevice + ? JSON.parse(connectedDevice) + : null; + const {token} = useSelector(state => state.auth); + const [refreshing, setRefreshing] = useState(false); + const [modalVisible, setModalVisible] = useState(false); + const [modalMenu, setModalMenu] = useState('message'); + const optionFarm = [ + { + label: 'Ubah Kebun', + color: '#333', + icon: 'create', + navigation: 'FarmAddEdit', + }, + ]; + const [datePickerVisible, setDatePickerVisible] = useState(false); + const [timePickerVisible1, settimePickerVisible1] = useState(false); + const [timePickerVisible2, settimePickerVisible2] = useState(false); + const [scheduleOneTime, setscheduleOneTime] = useState({ + mode: '', + Waktumulai: null, + Waktuselesai: null, + Tanggal:null, + Gate:'', + SetiapHari:'', + }); + + const Gantitanggal = ({ md, wm, ws, tgl, sh, gt }) => { + setscheduleOneTime(prevState => { + if (md !== undefined) { + prevState.mode = md; + } + if (wm !== undefined) { + prevState.Waktumulai = wm; + } + if (ws !== undefined) { + prevState.Waktuselesai = ws; + } + if (tgl !== undefined) { + prevState.Tanggal = tgl; + } + if (gt !== undefined) { + prevState.Gate = gt; + } + if (sh !== undefined) { + prevState.SetiapHari = sh; + } + return { ...prevState }; + }); + }; + let client; + + const [Air,setAir] = useState(); + const [Temp,setTemp] = useState(); + const [Humidity,setHumidity] = useState(); + const [Gerbang,setGerbang] = useState(); + const [Status,setStatus] = useState(); + const [Wflow, setWflow] = useState(); + const [Automatic, setAutomatic] = useState(); + const [Mode, setMode] = useState(); + function connectAndPublish(topic, message, subscribeTopic) { + if (!client) { + MQTT.createClient({ uri: 'mqtt://habibigarden.com:1883', clientId: 'gheril' }) + .then(function (createdClient) { + client = createdClient; + + client.on('closed', function () { + console.log('mqtt.event.closed'); + }); + + client.on('error', function (msg) { + console.log('mqtt.event.error', msg); + }); + + client.on('message', function (topic, message) { + console.log( topic); + const payload = JSON.stringify(topic); + const data = JSON.parse(payload); + const paring = JSON.parse(data.data); + // const data = payload.data; + console.log('ini parsingan',payload); + console.log(data); + // console.log(data.info.Air); + setAir(paring.info.distance); + console.log(paring.info.distance); + setTemp(paring.info.Temp); + setHumidity(paring.info.Humidity); + setWflow(paring.info.WFlow); + setGerbang(paring.info.Gerbang); + setStatus(paring.info.Hallefect); + setAutomatic(paring.info.Automatic); + setMode(paring.info.Mode); + setIsOn(Mode === 'OFF' ? isOn : !isOn); + }); + + client.on('connect', function () { + console.log('connected'); + client.publish(topic, message, 0, false); + if (subscribeTopic) { + client.subscribe(subscribeTopic, 0); + client.subscribe('Irigate/Ultrasonik', 0); + } + if(subscribeTopic === 'Irigate/SNalat'){ + console.log('subscribe'); + console.log(message); + } + if(subscribeTopic === 'Irigate/Ultrasonik'){ + console.log('subscribe'); + console.log(message); + } + }); + + client.connect(); + }) + .catch(function (err) { + console.log(err); + }); + } else { + client.publish(topic, message, 0, false); + } +} + + + const [selectedOption, setSelectedOption] = useState(null); + const [isPickerVisible, setPickerVisible] = useState(false); + const [buttonOnPress, setButtonOnPress] = useState(() => {}); + const [publishValue, setPublishValue] = useState(null); + const handleOptionSelect = (option) => { + setSelectedOption(option); + setPickerVisible(false); + + + switch (option) { + case '25%': + setPublishValue('1'); + break; + case '50%': + setPublishValue('2'); + break; + case '75%': + setPublishValue('3'); + break; + case '100%': + setPublishValue('4'); + break; + default: + setButtonOnPress(() => {}); + break; + } + }; + const handleButtonPress = () => { + if (publishValue) { + connectAndPublish('Irigate/relay', publishValue); + setPublishValue(null); + } + }; + const [selectedDays, setSelectedDays] = useState([]); + const days = ['Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab', 'Min', 'All']; + const dayValues = { + Sen: 1, + Sel: 2, + Rab: 3, + Kam: 4, + Jum: 5, + Sab: 6, + Min: 0, + }; + const toggleDay = (day) => { + if (day === 'All') { + if (selectedDays.length === Object.values(dayValues).filter((value) => !selectedDays.includes(value)).length) { + setSelectedDays([]); + } else { + setSelectedDays(Object.values(dayValues)); + } + } else { + setSelectedDays((prevSelectedDays) => { + if (prevSelectedDays.includes(dayValues[day])) { + return prevSelectedDays.filter((selectedDay) => selectedDay !== dayValues[day]); + } else { + if (prevSelectedDays.includes(dayValues.All)) { + return [...prevSelectedDays.filter((selectedDay) => selectedDay !== dayValues.All), dayValues[day]]; + } else { + return [...prevSelectedDays, dayValues[day]]; + } + } + }); + } + }; + const [isHariVisible, setIsHariVisible] = useState(true); + const [isTanggalVisible, setIsTanggalVisible] = useState(false); + const handleSekaliButtonPress = () => { + setIsHariVisible(false); + Gantitanggal({ md: 'OT' }); + setIsTanggalVisible(true); + }; + const handleUlangiButtonPress = () => { + setIsHariVisible(true); + Gantitanggal({ md: 'SH' }); + setIsTanggalVisible(false); + }; + const [isJadwalAdded, setIsJadwalAdded] = useState(false); + + const [isOn, setIsOn] = useState(false); + + + // cultivation parameter + const [cultivationQueue, setCultivationQueue] = useState(0); + const [cultivationList, setCultivationList] = useState([]); + + // rsc parameter + const [formRSC, setFormRSC] = useState({ + locationId: null, + locationName: null, + mode: 'Auto', + }); + const [isRscConnected, setIsRscConnected] = useState(false); + const [dataRSC, setDataRSC] = useState({ + ...sensorDevices, + date: moment().format(), + }); + // schedule parameter + const [schedule, ] = useState({ + time: moment().format('HH:mm'), + date: moment().format('YYYY-MM-DD'), + + }); + // ble parameter + const { + requestPermissions, + checkStatusBLE, + scanDevicesBLE, + connectDevice, + requestDataDevice, + disconnectDevice, + } = useBle(dispatch, connectedDeviceParse); + const [scannedDevices, setScannedDevices] = useState([]); + + const reqCultivations = useCallback(async () => { + let query = {farmId: detailFarm._id}; + await browseCultivationByQuery(dispatch, token, query, result => { + if (result) { + let tmpCultivation = result.filter( + item => item.farmId === detailFarm._id && item.endedAt === null, + ); + + setCultivationList(tmpCultivation); + setRefreshing(false); + } + }); + }, [dispatch, token, detailFarm._id]); + + const reqPlantsFertils = useCallback(async () => { + await getPlantsFertils(dispatch).then(() => { + setRefreshing(false); + }); + }, [dispatch]); + + const reqGetLocations = useCallback( + async cultivationId => { + await browseLocationByQuery(dispatch, token, cultivationId); + }, + [dispatch, token], + ); + + useEffect(() => { + const unsubscribe = navigation.addListener('focus', () => { + reqCultivations(); + if (plants.length === 0) { + reqPlantsFertils(); + } + }); + return unsubscribe; + }, []); + + useEffect(() => { + const unsubscribe2 = navigation.addListener('beforeRemove', () => { + if (connectedDevice) { + disconnectDevice(); + setIsRscConnected(false); + dispatch(setConnectedDevice({connectedDevice: null})); + } + }); + + return unsubscribe2; + }, [navigation, connectedDevice, disconnectDevice, dispatch]); + + /** + * Lists action + * place all action button here + */ + const onRefresh = () => { + setRefreshing(true); + reqPlantsFertils(); + reqCultivations(); + }; + + const onUpdateSensor = (key, value) => { + setDataRSC(current => { + return {...current, [key]: value}; + }); + }; + + const onShowModal = (menu, visible) => { + setModalMenu(menu); + setModalVisible(visible); + }; + + const onSubmitData = async second => { + setModalVisible(false); + let params = { + locationId: formRSC.locationId, + n: formRSC.mode === 'Auto' ? sensorDevices.n : dataRSC.n, + p: formRSC.mode === 'Auto' ? sensorDevices.p : dataRSC.p, + k: formRSC.mode === 'Auto' ? sensorDevices.k : dataRSC.k, + ph: formRSC.mode === 'Auto' ? sensorDevices.ph : dataRSC.ph, + rh: formRSC.mode === 'Auto' ? sensorDevices.rh : dataRSC.rh, + tds: formRSC.mode === 'Auto' ? sensorDevices.tds : dataRSC.tds, + temp: formRSC.mode === 'Auto' ? sensorDevices.temp : dataRSC.temp, + createdAt: moment().valueOf(), + updatedAt: moment().valueOf(), + }; + await addRSC(dispatch, token, params); + }; + + const onHarvest = () => { + let params = {endedAt: moment().valueOf()}; + editCultivation( + dispatch, + token, + cultivationList[cultivationQueue]?._id, + params, + ).then(async () => { + reqCultivations(); + }); + }; + + // ble action + const onConnectingToDevice = () => { + requestPermissions().then(result => { + if (result) { + const checkStatusBT = bleManager.onStateChange(state => { + if (state === 'PoweredOn') { + checkStatusBT.remove(); + + scanDevicesBLE(resScanDevices => { + if ( + !isRscConnected && + resScanDevices && + resScanDevices.length >= 1 + ) { + setScannedDevices(resScanDevices); + setModalMenu('devicesBLE'); + setModalVisible(true); + } else { + dispatch( + setGlobalAlert({ + isVisible: true, + status: 'error', + title: 'Proses Gagal', + subtitle: + 'Perangkat tidak terdeteksi, coba beberapa saat lagi.', + }), + ); + } + }); + } + + if (state === 'PoweredOff') { + dispatch( + setGlobalAlert({ + isVisible: true, + status: 'error', + title: 'Aplikasi memerlukan penggunaan bluetooth.', + subtitle: 'Silahkan nyalakan bluetooth terlebih dahulu.', + }), + ); + checkStatusBT.remove(); + } + }, true); + } + }); + }; + + /** + * Lists of render UI + * place all render below + */ + const renderHeader = () => { + return ( + + <> + + {detailFarm.img ? ( + + ) : ( + + )} + + + {detailFarm?.name} + + + + + {detailFarm?.city} + + + {detailFarm?.area ? ( + + + + {detailFarm?.area} ha + + + ) : null} + + onShowModal('optionFarm', true)} + style={tw`items-center mx-2`}> + + + + + + {detailFarm?.note ? ( + <> + + + Catatan + + {detailFarm?.note} + + + ) : null} + + + + + navigation.navigate('CultivationAddEdit', { + farmId: detailFarm._id, + }) + } + /> + + navigation.navigate('CultivationHistory', { + farmId: detailFarm._id, + }) + } + /> + + + + ); + }; + + const renderCultivation = () => { + return ( + + + + Informasi Budidaya + + { + navigation.navigate('CultivationAddEdit', { + farmId: detailFarm._id, + detailCultivation: cultivationList[cultivationQueue], + }); + }} + style={tw`ml-2`}> + + + + + + {cultivationList[cultivationQueue]?.note ? ( + + + {cultivationList[cultivationQueue]?.name} + + + {cultivationList[cultivationQueue]?.note} + + + ) : ( + + + {cultivationList[cultivationQueue]?.name} + + + )} + + + + item.id === cultivationList[cultivationQueue]?.plantId, + )?.image + }`, + }} + style={tw`rounded-full h-20 w-20 bg-toscaB items-center justify-center mr-3 border`} + /> + + + + Tanaman: + + + {(cultivationList.length && + plants.find( + item => + item.id === cultivationList[cultivationQueue]?.plantId, + )?.plants_name) || + 'Belum ada tanaman'} + + + + + HST: + + {cultivationList.length + ? moment().diff( + moment(cultivationList[cultivationQueue].startedAt), + 'days', + ) + + 2 + + ' Hari' + : '-'} + + + + + + Populasi: + + + {cultivationList.length + ? cultivationList[cultivationQueue].population + : '-'} + + + + {/* + Fase: + + - + + */} + + + + + + + NPK Rekomendasi + + + + + + + + + + + {cultivationList.length > 1 ? ( + + setCultivationQueue(prev => prev - 1)}> + onPress={() => + setCultivationQueue( + cultivationQueue === 0 + ? cultivationList.length - 1 + : prev => prev - 1, + ) + }> + + + Kembali + + + + { + setCultivationQueue( + cultivationQueue + 1 === cultivationList.length + ? 0 + : prev => prev + 1, + ); + }}> + + Lanjut + + + + + ) : null} + + + + + Menu Budidaya + + + } + onPress={() => + navigation.navigate('LocationsBread', { + breadType: 'add', + cultivationId: cultivationList[cultivationQueue]._id, + }) + } + label={'Lokasi'} + /> + } + label={'Laporan'} + onPress={() => + navigation.navigate('FarmReport', { + cultivationId: cultivationList[cultivationQueue]._id, + farmId: detailFarm._id, + }) + } + /> + } + label={'Keuangan'} + onPress={() => + navigation.navigate('FarmFinance', { + cultivationId: cultivationList[cultivationQueue]._id, + }) + } + /> + } + label={'Pupuk'} + onPress={() => { + navigation.navigate('Fertilizer', { + farmId: detailFarm._id, + cultivationId: cultivationList[cultivationQueue]._id, + activeFertilizer: + cultivationList[cultivationQueue]?.fertilizer, + }); + }} + /> + + + + { + setModalMenu('harvest'); + setModalVisible(true); + }} + style={tw`flex-1 flex-row bg-toscaB rounded-5 items-center justify-center py-4`}> + + + Panen / Selesai Budidaya + + + + + + ); + }; + + const renderRSC = () => { + return ( + + + + Rapid Soil Check (RSC) + + console.log('Setting Farm')} + style={tw`ml-2`}> + + + + + + + + + + Serial Number: + + + {connectedDeviceParse + ? connectedDeviceParse.name.split('_')[2] + : '-'} + + Status: + + {isRscConnected ? 'Terhubung' : 'Belum Terhubung'} + + + + + + + + + Update Terakhir + + - + + + + { + if (isRscConnected) { + disconnectDevice(); + setIsRscConnected(false); + dispatch(setConnectedDevice({connectedDevice: null})); + } else { + onConnectingToDevice(); + } + }} + value={isRscConnected} + /> + + + + + + + + Menu RSC + + + + } + label={'History'} + // beta={true} + betaStyle={tw`font-metroSB Text-red-600 absolute -top-1 right-5`} + onPress={() => + navigation.navigate('DataHistory', { + cultivationId: cultivationList[cultivationQueue]._id, + }) + } + /> + } + label={'Analisis'} + beta={true} + betaStyle={tw`font-metroSB Text-red-600 absolute -top-1 right-5`} + /> + + + + + + Sampling RSC + + + {/* step 1 */} + + + + + 1 + + + + Pilih Lokasi + + { + const locationList = locations.filter( + v => + v.cultivationId === + cultivationList[cultivationQueue]._id, + ); + if (!locationList.length) { + reqGetLocations(cultivationList[cultivationQueue]._id); + } + onShowModal('optionLocation', true); + }} + style={tw`flex-1 flex-row bg-${ + formRSC?.locationId ? 'toscaSS' : 'mainSB' + } rounded-4 items-center px-5 h-13`}> + + {formRSC?.locationName + ? formRSC?.locationName + : 'Pilih lokasi'} + + + + + + + {/* step 2 */} + + + + + 2 + + + + Pilih Mode + + { + setFormRSC(prev => ({ + ...prev, + mode: prev.mode === 'Auto' ? 'Manual' : 'Auto', + })); + }} + style={tw`flex-1 bg-${ + formRSC?.mode ? 'toscaSS' : 'mainSB' + } rounded-4 items-center justify-center px-5 h-13`}> + + {formRSC.mode === 'Auto' + ? 'RSC / Auto' + : 'Input ' + formRSC.mode} + + + + + + + {/* step 3 */} + + + + + 3 + + + { + if (formRSC.mode === 'Auto') { + if (isRscConnected) { + // init loading and value sensorDevices + dispatch(setSensorDevices({sensorDevices: {}})); + dispatch( + setGlobalAlert({ + isVisible: true, + status: 'loading', + title: 'Request data ke RSC', + }), + ); + + // request data from RSC + requestDataDevice(); + } else { + return dispatch( + setGlobalAlert({ + isVisible: true, + status: 'error', + title: 'HP belum terhubung ke RSC!', + subtitle: + 'Hubungkan terlebih dahulu perangkat HP dengan RSC.', + }), + ); + } + } else { + setDataRSC(prev => ({...prev, ...sensorDevices})); + } + setModalMenu('formRSC'); + setModalVisible(true); + }}> + {formRSC.mode === 'Auto' ? ( + + ) : null} + + {formRSC.mode === 'Auto' ? 'Scan RSC' : 'Mulai Input Data'} + + + + + + + + ); + }; + + /** + * Lists of render UI Modal + * place all render modal below + */ + const renderModalListDevices = () => { + return ( + + + Pilih perangkat + + + Pilih salah satu device kelana dibawah ini + + + {scannedDevices && + scannedDevices.map((device, index) => ( + { + let params = {device, isRscConnected}; + connectDevice(params, (res, err) => { + if (err) { + throw Error(err); + } + setIsRscConnected(res.switchStatus); + setModalVisible(false); + }); + }}> + + + + + Serial Number + + {device?.name ? device.name.split('_')[2] : '-'} + + + + ))} + + ); + }; + + const renderModalOptionFarm = () => { + let optionFarmTmp = [...optionFarm]; + if ( + Constants.ROLES[user.status] === 'ADMIN' || + Constants.ROLES[user.status] === 'AGRONOMIST' + ) { + optionFarmTmp.push({ + label: 'Kelola Pengguna', + color: '#1d9da6', + icon: 'people-circle-outline', + navigation: 'FarmManageMembers', + }); + } + + return ( + + + Opsi Kebun + + + Pilih salah satu opsi kebun dibawah ini + + + {optionFarmTmp.map((item, index) => ( + { + setModalVisible(false); + if (item.navigation === 'FarmAddEdit') { + navigation.navigate('FarmAddEdit', { + farmsId: detailFarm._id, + }); + } + if (item.navigation === 'FarmManageMembers') { + navigation.navigate('FarmManageMembers', { + // detailFarm, + farmsId: detailFarm._id, + }); + } + }}> + + + {item.label} + + + ))} + + ); + }; + + const renderModalFormRSC = () => { + return ( + + + {formRSC.mode === 'Auto' ? 'Hasil Scan RSC' : 'Input RSC Manual'} + + + {formRSC.mode === 'Auto' + ? 'Berikut nilai sensor hasil scan dari RSC' + : 'Lengkapi seluruh form dibawah ini'} + + + + + + Temperature (°C) + + onUpdateSensor('temp', val)} + /> + + + + RH (%) + + Kelembaban relatif + + + onUpdateSensor('rh', val)} + /> + + + + pH + + Derajat keasaman + + + onUpdateSensor('ph', val)} + /> + + + + + TDS (ppm) + + + Jumlah zat terlarut + + + onUpdateSensor('tds', val)} + /> + + + + + N / Nitrogen + + + (mg/kg) + + + onUpdateSensor('n', val)} + /> + + + + + P / Fosfor + + + (mg/kg) + + + onUpdateSensor('p', val)} + /> + + + + + K / Kalium + + + (mg/kg) + + + onUpdateSensor('k', val)} + /> + + + + + + Simpan Data + + + + ); + }; + + const renderModalOptionLocation = () => { + return ( + + + Pilih Lokasi + + + {locations.length + ? 'Pilih salah satu lokasi dibawah ini' + : 'Belum ada lokasi, silahkan tambah terlebih dahulu dengan menekan tombol dibawah ini.'} + + + {locations.length ? ( + locations.map((item, index) => ( + { + setFormRSC(prev => ({ + ...prev, + locationName: item.name, + locationId: item._id, + })); + setModalVisible(false); + }} + style={[ + tw`flex-row items-center p-4 py-4 border border-mainB border-t${ + index === 0 ? '' : '-0' + } rounded-t-${index === 0 ? '5' : 'none'} rounded-b-${ + locations.length - 1 === index ? '5' : 'none' + }`, + ]}> + + + + + + {item.name} + + + Sample Ke {index + 1} + + + + )) + ) : ( + { + setModalVisible(false); + navigation.navigate('LocationsBread', { + breadType: 'add', + cultivationId: cultivationList[cultivationQueue]._id, + }); + }} + style={tw`flex-row bg-toscaB rounded-5 items-center justify-center py-4`}> + + Tambah Lokasi + + + )} + + ); + }; + + const renderModalHarvest = () => { + return ( + + + Panen / Selesai Budidaya + + + { + 'Apakah anda yakin untuk panen / menyelesaikan budidaya ?\n\nJika "YA", klik tombol dibawah ini.' + } + + + { + setModalVisible(false); + onHarvest(); + }} + style={tw`flex-row bg-toscaB rounded-5 items-center justify-center py-4`}> + + Selesaikan Budidaya / Panen + + + + ); + }; + + const renderModalSchedule = () => { + const ButtonCircle = ({ customText, isSelected, onPress }) => { + const circleStyle = isSelected + ? { backgroundColor: '#055B66' } + : { backgroundColor: 'gray' }; + + return ( + + {customText} + + ); + }; + + return ( + + + Pilih Jadwal + + + Pilih salah satu jadwal dibawah ini + + + + + + + + {isHariVisible && ( + + + Pilih Hari + + + {days.map((day, index) => ( + value !== 'x').length : selectedDays.includes(dayValues[day])} + onPress={() => toggleDay(day)} + /> + ))} + + + )} + + {isTanggalVisible && ( + + + Pilih Tanggal + + + setDatePickerVisible(true)} + style={tw`flex-1 bg-mainSB border-gray-200 py-4.5 flex-row items-center`}> + + {scheduleOneTime?.Tanggal + ? moment(scheduleOneTime?.Tanggal).format('D MMMM YYYY') + : 'Pilih tanggal tanam'} + + + + + + )} + + + settimePickerVisible1(true)} + style={tw`flex-1 bg-mainSB border-gray-200 py-4.5 flex-row items-center`}> + + {scheduleOneTime?.Waktumulai + ? moment(scheduleOneTime?.Waktumulai).format('HH:mm') + : 'Waktu mulai'} + + + + settimePickerVisible2(true)} + style={tw`flex-1 bg-mainSB border-gray-200 py-4.5 flex-row items-center`}> + + {scheduleOneTime?.Waktuselesai + ? moment(scheduleOneTime?.Waktuselesai).format('HH:mm') + : 'Waktu Selesai'} + + + + + + + setPickerVisible(true)} + style={tw`flex-1 bg-mainSB border-gray-200 py-4.5 flex-row items-center`} + > + + {selectedOption ? selectedOption : 'Pilih Tinggi Gerbang'} + + + + + + + handleOptionSelect(null)} + style={tw`bg-white py-4 px-6 border-b border-gray-200`} + > + Tinggi Gerbang + + { + Gantitanggal({ gt: '1' }) + setPickerVisible(false); + }} + style={tw`bg-white py-4 px-6 border-b border-gray-200`} + > + 25% + + { + Gantitanggal({ gt: '2' }) + setPickerVisible(false); + }} + style={tw`bg-white py-4 px-6 border-b border-gray-200`} + > + 50% + + { + Gantitanggal({ gt: '3' }) + setPickerVisible(false); + }} + style={tw`bg-white py-4 px-6 border-b border-gray-200`} + > + 75% + + { + Gantitanggal({ gt: '4' }) + setPickerVisible(false); + }} + style={tw`bg-white py-4 px-6`} + > + 100% + + + + + + { + setIsJadwalAdded(true); + if (scheduleOneTime.mode === 'OT') { + const time1 = `${scheduleOneTime.mode}${moment(scheduleOneTime.Waktumulai).format('HHmm')}${moment(scheduleOneTime.Waktuselesai).format('HHmm')}${moment(scheduleOneTime.Tanggal).format('DDMMYYYY')}${scheduleOneTime.Gate}`; + connectAndPublish('Irigate/time1', time1); + } else if (scheduleOneTime.mode === 'SH') { + console.log(scheduleOneTime.SetiapHari); + Gantitanggal({ sh: selectedDays }); + const time2 = `${scheduleOneTime.mode}${moment(scheduleOneTime.Waktumulai).format('HHmm')}${moment(scheduleOneTime.Waktuselesai).format('HHmm')}${scheduleOneTime.SetiapHari.join('')}${scheduleOneTime.Gate}`; + console.log ({time2}); + connectAndPublish('Irigate/time2', time2); + } + }} + style={tw`flex-row bg-toscaB rounded-5 items-center justify-center py-4`}> + + Tambah Jadwal + + + + {isJadwalAdded && ( + // + // mode : {scheduleOneTime.mode} + // Waktumulai : {moment(scheduleOneTime.Waktumulai).format('HH:mm')} + // Waktuselesai : {moment(scheduleOneTime.Waktuselesai).format('HH:mm')} + // Tanggal : {moment(scheduleOneTime.tgl).format('DD-MM-YYYY')} + // TinggiGerbang : {scheduleOneTime.Gate} + // + { + setModalMenu('hasil_penjualan'); + setModalVisible(true); + }} + onPressShow={() => + setContentVisible(prevState => { + return { + ...prevState, + hasilPenjualan: !prevState.hasilPenjualan, + }; + }) + } + isContentShow={scheduleOneTime && scheduleOneTime.mode} + content={ + + {/* list item */} + + + + {scheduleOneTime.mode} + + Harga {'Rp 20.000'} + Qty {'5197.50'} Kg + + + Total Harga ={' '} + + {'Rp 103.950.000'} + + + + + + {/* total */} + + + + {'Mode :'} + + + {scheduleOneTime.mode} + + + + + {'Waktu Mulai :'} + + + {moment(scheduleOneTime.Waktumulai).format('HH:mm')} + + + + + {'Waktu Selesai :'} + + + {moment(scheduleOneTime.Waktuselesai).format('HH:mm')} + + + + + {'Tanggal :'} + + + {moment(scheduleOneTime.Tanggal).format('DD-MM-YYYY')} + + + + + {'Tinggi Gerbang :'} + + + {scheduleOneTime.Gate} + + + + + } + /> + )} + + ); + }; + + const renderIrigate = () => { + + return ( + + + + Smart Irrigate + + + + + + + + + + + + + + + Nilai Sensor + + + + + + + + + {/* { } */} + + {/* + + + + + */} + + + + {/* + Nilai Sensor + } + */} + + + + Mode Otomatis + + + { + setIsOn(!isOn); + const mode = isOn ? 'OFF' : 'ON'; + connectAndPublish('Irigate/AutoMode', mode, 'Irigate/Information'); + }} + style={tw`flex-1 py-4.3 flex-row items-center mr-1 bg-${ + isOn ? 'redSS border-0' : 'blueSB border-0' + }`} + > + + + {isOn ? 'OFF' : 'ON'} + + + + + + Mode Manual + + + setPickerVisible(true)} + style={tw`flex-1 bg-mainSB border-gray-200 py-4.5 flex-row items-center`} + > + + {selectedOption ? selectedOption : 'Pilih Tinggi Gerbang'} + + + + + + + handleOptionSelect(null)} + style={tw`bg-white py-4 px-6 border-b border-gray-200`} + > + Pilih Tinggi Gerbang + + handleOptionSelect('25%')} + style={tw`bg-white py-4 px-6 border-b border-gray-200`} + > + 25%/12,5 cm + + handleOptionSelect('50%')} + style={tw`bg-white py-4 px-6 border-b border-gray-200`} + > + 50%/25 cm + + handleOptionSelect('75%')} + style={tw`bg-white py-4 px-6 border-b border-gray-200`} + > + 75%/37,5 cm + + handleOptionSelect('100%')} + style={tw`bg-white py-4 px-6`} + > + 100%/50 cm + + + + + + + + {/* console.log('STOP')} + /> */} + connectAndPublish('Irigate/relay', '0')} + /> + + + {/* {cultivationList.length ? ( + + + + { + setModalMenu("schedule"); + renderModalSchedule(); + setModalVisible(true); + }} + style={tw`flex-1 flex-row bg-mainSB rounded-4 items-center px-5 h-13`}> + + { 'Set-up Schedule'} + + + + + + ) : null} */} + + + + ); + + }; + + + return ( + + + + + + } + childrenStyle={tw`px-0`} + header={renderHeader()}> + + {cultivationList.length ? renderCultivation() : null} + {cultivationList.length ? renderRSC() : null} + {/* {renderPlantInfo()} */} + {/* {renderFarmInfo()} */} + {/* {renderSampling()} */} + {cultivationList.length ? renderIrigate() : null} + + + + + { + setDatePickerVisible(false); + Gantitanggal({ tgl: moment(date).valueOf() }); + }} + onCancel={() => setDatePickerVisible(false)} + /> + { + settimePickerVisible1(false); + Gantitanggal({wm: moment(time).valueOf() }); + }} + onCancel={() => settimePickerVisible1(false)} + /> + { + settimePickerVisible2(false); + Gantitanggal({ws: moment(time).valueOf() }); + }} + onCancel={() => settimePickerVisible2(false)} + /> + setModalVisible(prevState => !prevState)} + onSwipeComplete={() => setModalVisible(prevState => !prevState)} + swipeDirection={['down']} + style={tw`justify-end m-0`}> + + {modalMenu === 'optionFarm' ? renderModalOptionFarm() : null} + {modalMenu === 'optionLocation' ? renderModalOptionLocation() : null} + {modalMenu === 'formRSC' ? renderModalFormRSC() : null} + {modalMenu === 'devicesBLE' ? renderModalListDevices() : null} + {modalMenu === 'harvest' ? renderModalHarvest() : null} + {modalMenu === 'schedule' ? renderModalSchedule() : null} + + + + {/* {modalMenu === 'samplingType' ? renderModalSamplingType() : null} */} + {/* {modalMenu === 'phaseGrowth' ? renderModalPhaseGrowth() : null} */} + + + + ); +}; + +export default FarmDetail;