Skip to content

Commit e616d3f

Browse files
committed
create separate LockDeviceToggleLockButton
1 parent 4ab7e32 commit e616d3f

File tree

2 files changed

+50
-28
lines changed

2 files changed

+50
-28
lines changed

src/lib/seam/components/DeviceDetails/LockDeviceDetails.tsx

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { NestedAccessCodeTable } from 'lib/seam/components/AccessCodeTable/Acces
77
import type { NestedSpecificDeviceDetailsProps } from 'lib/seam/components/DeviceDetails/DeviceDetails.js'
88
import { DeviceInfo } from 'lib/seam/components/DeviceDetails/DeviceInfo.js'
99
import { DeviceModel } from 'lib/seam/components/DeviceDetails/DeviceModel.js'
10+
import { LockDeviceToggleLockButton } from 'lib/seam/components/DeviceDetails/LockDeviceToggleLockButton.js'
1011
import { deviceErrorFilter, deviceWarningFilter } from 'lib/seam/filters.js'
1112
import type { LockDevice } from 'lib/seam/locks/lock-device.js'
1213
import { useToggleLock } from 'lib/seam/locks/use-toggle-lock.js'
1314
import { Alerts } from 'lib/ui/Alert/Alerts.js'
14-
import { Button } from 'lib/ui/Button.js'
1515
import { BatteryStatusIndicator } from 'lib/ui/device/BatteryStatusIndicator.js'
1616
import { DeviceImage } from 'lib/ui/device/DeviceImage.js'
1717
import { EditableDeviceName } from 'lib/ui/device/EditableDeviceName.js'
@@ -59,9 +59,6 @@ export function LockDeviceDetails({
5959
},
6060
})
6161

62-
const lockStatus = device.properties.locked ? t.locked : t.unlocked
63-
const toggleLockLabel = device.properties.locked ? t.unlock : t.lock
64-
6562
const accessCodeCount = accessCodes?.length
6663

6764
if (accessCodes == null) {
@@ -164,25 +161,13 @@ export function LockDeviceDetails({
164161

165162
<div className='seam-box'>
166163
{device.properties.online && (
167-
<div className='seam-content seam-lock-status'>
168-
<div>
169-
<span className='seam-label'>{t.lockStatus}</span>
170-
<span className='seam-value'>{lockStatus}</span>
171-
</div>
172-
<div className='seam-right'>
173-
{!disableLockUnlock &&
174-
device.capabilities_supported.includes('lock') && (
175-
<Button
176-
size='small'
177-
onClick={() => {
178-
toggleLock.mutate(device)
179-
}}
180-
>
181-
{toggleLockLabel}
182-
</Button>
183-
)}
184-
</div>
185-
</div>
164+
<LockDeviceToggleLockButton
165+
onToggle={() => {
166+
toggleLock.mutate(device)
167+
}}
168+
device={device}
169+
disableLockUnlock={disableLockUnlock}
170+
/>
186171
)}
187172

188173
<AccessCodeLength
@@ -230,14 +215,9 @@ function AccessCodeLength(props: {
230215

231216
const t = {
232217
device: 'Device',
233-
unlock: 'Unlock',
234-
lock: 'Lock',
235-
locked: 'Locked',
236-
unlocked: 'Unlocked',
237218
accessCodes: 'access codes',
238219
codeLength: 'Code length',
239220
digits: 'digits',
240-
lockStatus: 'Lock status',
241221
status: 'Status',
242222
power: 'Power',
243223
successfullyUpdated: 'Lock status has been successfully updated',
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { LockDevice } from 'lib/seam/locks/lock-device.js'
2+
import { Button } from 'lib/ui/Button.js'
3+
4+
interface LockDeviceToggleLockButtonProps {
5+
device: LockDevice
6+
onToggle: () => void
7+
disableLockUnlock: boolean
8+
}
9+
10+
export function LockDeviceToggleLockButton({
11+
device,
12+
onToggle,
13+
disableLockUnlock,
14+
}: LockDeviceToggleLockButtonProps): JSX.Element {
15+
const lockStatus = device.properties.locked ? t.locked : t.unlocked
16+
const toggleLockLabel = device.properties.locked ? t.unlock : t.lock
17+
18+
return (
19+
<div className='seam-content seam-lock-status'>
20+
<div>
21+
<span className='seam-label'>{t.lockStatus}</span>
22+
<span className='seam-value'>{lockStatus}</span>
23+
</div>
24+
<div className='seam-right'>
25+
{!disableLockUnlock &&
26+
device.capabilities_supported.includes('lock') && (
27+
<Button size='small' onClick={onToggle}>
28+
{toggleLockLabel}
29+
</Button>
30+
)}
31+
</div>
32+
</div>
33+
)
34+
}
35+
36+
const t = {
37+
unlock: 'Unlock',
38+
lock: 'Lock',
39+
locked: 'Locked',
40+
unlocked: 'Unlocked',
41+
lockStatus: 'Lock status',
42+
}

0 commit comments

Comments
 (0)