1+
12import {
23 type CommonProps ,
34 withRequiredCommonProps ,
@@ -9,19 +10,18 @@ import { useDevice } from 'lib/seam/devices/use-device.js'
910import { isLockDevice } from 'lib/seam/locks/lock-device.js'
1011import { isNoiseSensorDevice } from 'lib/seam/noise-sensors/noise-sensor-device.js'
1112import { isThermostatDevice } from 'lib/seam/thermostats/thermostat-device.js'
13+ import { useSeamClient } from 'lib/seam/use-seam-client.js'
1214import { useComponentTelemetry } from 'lib/telemetry/index.js'
1315
1416export interface DeviceDetailsProps extends CommonProps {
1517 deviceId : string
1618}
1719
1820export const NestedDeviceDetails = withRequiredCommonProps ( DeviceDetails )
19-
2021export interface NestedSpecificDeviceDetailsProps
2122 extends Required < Omit < CommonProps , 'onBack' | 'className' > > {
2223 onBack : ( ( ) => void ) | undefined
2324 className : string | undefined
24- onEditName ?: ( newName : string ) => void
2525}
2626
2727export function DeviceDetails ( {
@@ -39,10 +39,24 @@ export function DeviceDetails({
3939} : DeviceDetailsProps ) : JSX . Element | null {
4040 useComponentTelemetry ( 'DeviceDetails' )
4141
42- const { device } = useDevice ( {
42+ const { client } = useSeamClient ( ) ;
43+ const { device, refetch : refetchDevice } = useDevice ( {
4344 device_id : deviceId ,
4445 } )
4546
47+
48+ const updateDeviceName = async ( newName : string ) : Promise < void > => {
49+ if ( client == null ) return ;
50+
51+ client . devices . update ( {
52+ device_id : deviceId ,
53+ name : newName ,
54+ } )
55+ . then ( async ( ) => await refetchDevice ( ) )
56+ . catch ( ( error ) => { console . error ( error ) ; } )
57+
58+ }
59+
4660 if ( device == null ) {
4761 return null
4862 }
@@ -64,7 +78,7 @@ export function DeviceDetails({
6478 return (
6579 < LockDeviceDetails
6680 device = { device }
67- onEditName = { props . onEditName }
81+ onEditName = { updateDeviceName }
6882 { ...props }
6983 />
7084 )
@@ -74,7 +88,7 @@ export function DeviceDetails({
7488 return (
7589 < ThermostatDeviceDetails
7690 device = { device }
77- onEditName = { props . onEditName }
91+ onEditName = { updateDeviceName }
7892 { ...props }
7993 />
8094 )
@@ -84,7 +98,7 @@ export function DeviceDetails({
8498 return (
8599 < NoiseSensorDeviceDetails
86100 device = { device }
87- onEditName = { props . onEditName }
101+ onEditName = { updateDeviceName }
88102 { ...props }
89103 />
90104 )
0 commit comments