import React from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { useTranslation } from 'react-i18next'; import { Dialog, DialogTitle, DialogContent, TextField, DialogActions, Button, MenuItem } from '@material-ui/core'; import { getEnvironment } from '../../features/general'; import { createSupply, updateSupply } from '../../features/supply'; import { IDeviceWithSupply } from '../../types'; import { SupplyStatus } from '../../pages/SupplyTablePage'; interface IProps { showModal: boolean; setShowModal: (value: React.SetStateAction) => void; entity: IDeviceWithSupply; setEntity: (value: React.SetStateAction) => void; } export function UpdateSupplyModal(props: IProps) { const { showModal, setShowModal, entity, setEntity } = props; const { t } = useTranslation(); const environment = useSelector(getEnvironment); const issuerId = environment?.ISSUER_ID; const dispatch = useDispatch(); function requestAutoSupply() { const { active = false, price = 0, supplyId } = entity; if (!entity.supplyCreated) { const deviceId = entity.externalDeviceIds.find((id) => id.type === issuerId).id; dispatch(createSupply({ deviceId, active, price })); } else { dispatch(updateSupply({ supplyId, supplyData: { active, price } })); } setShowModal(false); } return ( {t('exchange.supply.updateSupply')} setEntity({ ...entity, price: Number(e.target.value) }) } fullWidth /> setEntity({ ...entity, active: e.target.value === SupplyStatus.Active }) } select > {t('exchange.supply.active')} {t('exchange.supply.paused')} ); }