Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a53d9ac
feat: Show access code `errors` and `warnings` in `AccessCodeDetails`
xplato Jun 28, 2023
94b551c
Run format
seambot Jun 28, 2023
d28251c
fix: Filter out `is_access_code_error` except `failed_to_set_on_device`
xplato Jun 28, 2023
f6e9388
Merge branch 'add-access-code-errs-warns' of github.com:seamapi/react…
xplato Jun 28, 2023
08888cf
Run format
seambot Jun 28, 2023
f807880
fix: Remove top padding of `.seam-alerts-padded`
xplato Jun 28, 2023
aa549ca
Merge branch 'add-access-code-errs-warns' of github.com:seamapi/react…
xplato Jun 28, 2023
49d9165
fix: Adjust padding to match design spec
xplato Jun 28, 2023
aaf6b1d
fix: Update `Alert` style
xplato Jun 28, 2023
5ebf1c5
Run format
seambot Jun 28, 2023
f983d0a
fix: Revert `Alert` changes in favor of #244
xplato Jun 28, 2023
8e3ea34
Merge branch 'add-access-code-errs-warns' of github.com:seamapi/react…
xplato Jun 28, 2023
aa97aa0
Merge branch 'main' into add-access-code-errs-warns
xplato Jun 28, 2023
87fb781
Merge branch 'main' into add-access-code-errs-warns
xplato Jun 28, 2023
ea05f15
fix: Remove undefined operators for `errors`, `warnings`
xplato Jun 28, 2023
14c37a3
fix: Update condition style
xplato Jun 28, 2023
bc31547
Run format
seambot Jun 28, 2023
569e831
Merge branch 'main' into add-access-code-errs-warns
xplato Jun 28, 2023
7b8d5dc
fix: Update condition for linter happiness
xplato Jun 28, 2023
73b8a01
fix: Use `errorFilter`
xplato Jun 28, 2023
e7ba7c4
Merge branch 'add-access-code-errs-warns' of github.com:seamapi/react…
xplato Jun 28, 2023
adde876
Run format
seambot Jun 28, 2023
47cf976
fix: Move `errorFilter` to bottom of file
xplato Jun 28, 2023
30a24f8
Merge branch 'add-access-code-errs-warns' of github.com:seamapi/react…
xplato Jun 28, 2023
6d29cad
Run format
seambot Jun 28, 2023
563744b
fix: Update `is_access_code_error` condition
xplato Jun 28, 2023
4d3a058
fix: Update `account_disconnected` error properties
xplato Jun 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions .storybook/seed-fake.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,43 @@ export const seedFake = (db) => {
common_code_key: null,
type: 'ongoing',
status: 'set',
errors: [],
warnings: [],
errors: [
{
error_code: 'account_disconnected',
is_connected_account_error: true,
message:
'Seam has lost connection to a connected account. This may happen if the third-party provider triggered an access token to be revoked (e.g., after a password change). The account owner needs to reconnect the connected account with a new connect webview.',
created_at: '2023-06-27T22:50:19.440Z',
},
{
error_code: 'device_disconnected',
is_device_error: true,
message: 'Device Disconnected, you may need to reconnect the device.',
created_at: '2023-06-27T22:50:19.440Z',
},
{
error_code: 'failed_to_set_on_device',
is_access_code_error: true,
message:
'An access code with the same pin already exists on the device.',
created_at: '2023-06-27T06:01:11.885Z',
},
{
error_code: 'duplicate_code_on_device',
is_access_code_error: true,
message:
'An access code with the same pin already exists on the device.',
created_at: '2023-06-27T06:01:11.914Z',
},
],
warnings: [
{
warning_code: 'delay_in_setting_on_device',
message:
'There was an unusually long delay in programming the code onto the device. For time bound codes, this is sent when the code enters its active time. Note that this is a temporary warning and might be removed if the code is successfully set.',
created_at: '2023-06-27T06:01:11.885Z',
},
],
is_managed: true,
})

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"@tanstack/react-query": "^4.28.0",
"classnames": "^2.3.2",
"luxon": "^3.3.0",
"seamapi": "^6.14.3",
"seamapi": "^6.15.1",
"uuid": "^9.0.0"
},
"devDependencies": {
Expand Down
45 changes: 43 additions & 2 deletions src/lib/seam/components/AccessCodeDetails/AccessCodeDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import classNames from 'classnames'
import { DateTime } from 'luxon'
import { useState } from 'react'
import type { AccessCode } from 'seamapi'
import type {
AccessCode,
AccessCodeError,
ConnectedAccountError,
DeviceError,
} from 'seamapi'

import { useAccessCode } from 'lib/seam/access-codes/use-access-code.js'
import { AccessCodeDevice } from 'lib/seam/components/AccessCodeDetails/AccessCodeDevice.js'
import { DeviceDetails } from 'lib/seam/components/DeviceDetails/DeviceDetails.js'
import { Alerts } from 'lib/ui/Alert/Alerts.js'
import { ContentHeader } from 'lib/ui/layout/ContentHeader.js'
import { useIsDateInPast } from 'lib/ui/use-is-date-in-past.js'

Expand Down Expand Up @@ -41,18 +47,37 @@ export function AccessCodeDetails({
)
}

const alerts = [
...accessCode.errors.filter(errorFilter).map((error) => ({
variant: 'error' as const,
message: error.message,
})),
...accessCode.warnings.map((warning) => ({
variant: 'warning' as const,
message: warning.message,
})),
]

return (
<div className={classNames('seam-access-code-details', className)}>
<ContentHeader title='Access code' onBack={onBack} />
<div className='seam-summary'>
<div className='seam-top'>
<div
className={classNames(
'seam-top',
alerts.length > 0 && 'seam-top-has-alerts'
)}
>
<span className='seam-label'>{t.accessCode}</span>
<h5 className='seam-access-code-name'>{name}</h5>
<div className='seam-code'>{accessCode.code}</div>
<div className='seam-duration'>
<Duration accessCode={accessCode} />
</div>
</div>

<Alerts alerts={alerts} className='seam-alerts-padded' />

<AccessCodeDevice
deviceId={accessCode.device_id}
onSelectDevice={selectDevice}
Expand Down Expand Up @@ -157,6 +182,22 @@ function formatDate(date: string): string {
})
}

const errorFilter = (
error: AccessCodeError | DeviceError | ConnectedAccountError
): boolean => {
if ('is_access_code_error' in error && !error.is_access_code_error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. This makes me think we need to add type guards to the SDK for the different error types like we have for managed and unmanaged devices.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's a good idea!

return true

if (
error.error_code === 'failed_to_set_on_device' ||
error.error_code === 'failed_to_remove_on_device'
) {
return true
}

return false
}

const t = {
accessCode: 'Access code',
fallbackName: 'Code',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const Content: Story = {
{
error_code: 'account_disconnected',
message: 'Device account has been disconnected.',
is_connected_account_error: true,
},
],
warnings: [
Expand Down Expand Up @@ -77,6 +78,7 @@ export const Content: Story = {
{
error_code: 'account_disconnected',
message: 'Device account has been disconnected.',
is_connected_account_error: true,
},
],
warnings: [
Expand Down
4 changes: 4 additions & 0 deletions src/styles/_access-code-details.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
> .seam-top {
padding: 24px 16px;

&.seam-top-has-alerts {
padding-bottom: 8px;
}

> .seam-label {
font-weight: 600;
font-size: 14px;
Expand Down
4 changes: 4 additions & 0 deletions src/styles/_alert.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
&.seam-alerts-space-top {
margin-top: 16px;
}

&.seam-alerts-padded {
padding: 0 16px 24px;
}
}

// Alert
Expand Down