import React, { Component } from "react"; import { Link, RouteComponentProps } from "react-router-dom"; import { Space, Breadcrumb, Card, PageHeader } from "antd"; import { Tenant } from "@chirpstack/chirpstack-api-grpc-web/api/tenant_pb"; import { Application } from "@chirpstack/chirpstack-api-grpc-web/api/application_pb"; import { CreateDeviceRequest, Device } from "@chirpstack/chirpstack-api-grpc-web/api/device_pb"; import { GetDeviceProfileRequest, GetDeviceProfileResponse, } from "@chirpstack/chirpstack-api-grpc-web/api/device_profile_pb"; import DeviceForm from "./DeviceForm"; import DeviceStore from "../../stores/DeviceStore"; import DeviceProfileStore from "../../stores/DeviceProfileStore"; interface IProps extends RouteComponentProps { tenant: Tenant; application: Application; } class CreateDevice extends Component { onFinish = (obj: Device) => { obj.setApplicationId(this.props.application.getId()); let req = new CreateDeviceRequest(); req.setDevice(obj); DeviceStore.create(req, () => { let req = new GetDeviceProfileRequest(); req.setId(obj.getDeviceProfileId()); DeviceProfileStore.get(req, (resp: GetDeviceProfileResponse) => { let dp = resp.getDeviceProfile()!; if (dp.getSupportsOtaa()) { this.props.history.push( `/tenants/${this.props.tenant.getId()}/applications/${this.props.application.getId()}/devices/${obj.getDevEui()}/keys`, ); } else { this.props.history.push( `/tenants/${this.props.tenant.getId()}/applications/${this.props.application.getId()}/devices/${obj.getDevEui()}`, ); } }); }); }; render() { let device = new Device(); device.setApplicationId(this.props.application.getId()); return ( ( Tenants {this.props.tenant.getName()} Applications {this.props.application.getName()} Add device )} title="Add device" /> ); } } export default CreateDevice;