Skip to content

Add error Snackbar to table components #505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7a43d64
Add `Snackbar` to `DeviceTable`
xplato Oct 2, 2023
6ab5169
Add `Snackbar` to `AccessCodeTable`
xplato Oct 2, 2023
fc6e2ca
Add `Snackbar` to `ClimateSettingScheduleTable`
xplato Oct 2, 2023
aacba97
ci: Format code
seambot Oct 2, 2023
b2b97a8
Update fallback string
xplato Oct 2, 2023
8d0fd15
Merge branch 'hook-up-snackbar' of github.com:seamapi/react into hook…
xplato Oct 2, 2023
e95dd20
Use `disableCloseButton`
xplato Oct 2, 2023
235bff8
Merge branch 'main' into hook-up-snackbar
xplato Oct 2, 2023
ba87057
Update error descriptions
xplato Oct 2, 2023
6ce3eb3
Lint fixes
xplato Oct 2, 2023
4d7925a
Use `t` for `AccessCodeTable`
xplato Oct 3, 2023
429dad8
Use `t` for `DeviceTable`
xplato Oct 3, 2023
6af9ee2
Use `t` for `ClimateSettingScheduleTable`
xplato Oct 3, 2023
41eafd4
Merge branch 'main' into hook-up-snackbar
xplato Oct 3, 2023
58fa3a2
Bump `fake-seam-connect`
xplato Oct 3, 2023
b025c47
Use new `Snackbar` API in `AccessCodeTable`
xplato Oct 3, 2023
5f3b55a
Use new `Snackbar` API in `ClimateSettingScheduleTable`
xplato Oct 3, 2023
5cc4bde
Use new `Snackbar` API in `DeviceTable`
xplato Oct 3, 2023
a9d472a
Add `ws3` for simulated outage
xplato Oct 3, 2023
314729c
Merge branch 'main' into hook-up-snackbar
xplato Oct 5, 2023
b7cc6f4
Update fake-seam-connect, fix error messages
xplato Oct 10, 2023
6d174de
Use `t.fallbackErrorMessage`
xplato Oct 10, 2023
8bd486a
Remove `error`
xplato Oct 10, 2023
843bf08
ci: Format code
seambot Oct 10, 2023
fc67022
Format
xplato Oct 10, 2023
fd70f02
Merge branch 'hook-up-snackbar' of github.com:seamapi/react into hook…
xplato Oct 10, 2023
9eadaa0
Merge branch 'main' into hook-up-snackbar
xplato Oct 10, 2023
c73d3e1
Merge branch 'main' into hook-up-snackbar
xplato Oct 10, 2023
cc1f10b
Merge branch 'main' into hook-up-snackbar
xplato Oct 12, 2023
8d13e87
Merge branch 'main' into hook-up-snackbar
xplato Oct 23, 2023
af89c2a
Amend date
xplato Oct 23, 2023
3b9510c
Merge branch 'main' into hook-up-snackbar
xplato Oct 23, 2023
5998fb2
Remove `onClose`
xplato Oct 23, 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
24 changes: 15 additions & 9 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,34 @@ const preview: Preview = {
},
},
decorators: [
(
Story,
{
(Story, context) => {
const {
globals: {
publishableKey,
userIdentifierKey,
seamEndpoint,
simulatedOutage,
},
}
) => {
} = context

const usableKey =
simulatedOutage === 'outage' ? 'seam_pk_3' : publishableKey

return (
<SeamProvider
publishableKey={
simulatedOutage === 'outage' ? 'seam_pk_3' : publishableKey
}
publishableKey={usableKey}
userIdentifierKey={userIdentifierKey}
endpoint={seamEndpoint}
disableCssInjection
disableFontInjection
>
<Story />
<Story
{...context}
globals={{
...context.globals,
publishableKey: usableKey,
}}
/>
</SeamProvider>
)
},
Expand Down
21 changes: 16 additions & 5 deletions src/lib/seam/components/AccessCodeTable/AccessCodeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function AccessCodeTable({
}: AccessCodeTableProps): JSX.Element {
useComponentTelemetry('AccessCodeTable')

const { accessCodes, isInitialLoading, isError, error } = useAccessCodes({
const { accessCodes, isInitialLoading, isError, refetch } = useAccessCodes({
device_id: deviceId,
})

Expand Down Expand Up @@ -208,10 +208,6 @@ export function AccessCodeTable({
)
}

if (isError) {
return <p className={className}>{error?.message}</p>
}

return (
<>
<Snackbar
Expand Down Expand Up @@ -268,6 +264,19 @@ export function AccessCodeTable({
disableDeleteAccessCode={disableDeleteAccessCode}
/>
</TableBody>

<Snackbar
variant='error'
visible={isError}
message={t.fallbackErrorMessage}
action={{
label: t.tryAgain,
onClick: () => {
void refetch()
},
}}
disableCloseButton
/>
</div>
</>
)
Expand Down Expand Up @@ -338,4 +347,6 @@ const t = {
loading: 'Loading access codes',
accesCodeUpdated: 'Access code updated',
accesCodeCreated: 'Access code created',
tryAgain: 'Try again',
fallbackErrorMessage: 'Access codes could not be loaded',
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from 'lib/seam/thermostats/climate-setting-schedules/use-climate-setting-schedules.js'
import { ContentHeader } from 'lib/ui/layout/ContentHeader.js'
import { LoadingToast } from 'lib/ui/LoadingToast/LoadingToast.js'
import { Snackbar } from 'lib/ui/Snackbar/Snackbar.js'
import { EmptyPlaceholder } from 'lib/ui/Table/EmptyPlaceholder.js'
import { TableBody } from 'lib/ui/Table/TableBody.js'
import { TableHeader } from 'lib/ui/Table/TableHeader.js'
Expand Down Expand Up @@ -72,7 +73,7 @@ export function ClimateSettingScheduleTable({
}: ClimateSettingScheduleTableProps): JSX.Element {
useComponentTelemetry('ClimateSettingScheduleTable')

const { climateSettingSchedules, isInitialLoading, isError, error } =
const { climateSettingSchedules, isInitialLoading, isError, refetch } =
useClimateSettingSchedules({
device_id: deviceId,
})
Expand Down Expand Up @@ -128,10 +129,6 @@ export function ClimateSettingScheduleTable({
)
}

if (isError) {
return <p className={className}>{error?.message}</p>
}

return (
<div className={classNames('seam-table', className)}>
<ContentHeader onBack={onBack} />
Expand Down Expand Up @@ -165,6 +162,19 @@ export function ClimateSettingScheduleTable({
onClimateSettingScheduleClick={handleClimateSettingScheduleClick}
/>
</TableBody>

<Snackbar
variant='error'
visible={isError}
message={t.fallbackErrorMessage}
action={{
label: t.tryAgain,
onClick: () => {
void refetch()
},
}}
disableCloseButton
/>
</div>
)
}
Expand Down Expand Up @@ -201,4 +211,6 @@ const t = {
noClimateSettingSchedulesMessage:
'Sorry, no climate setting schedules were found',
loading: 'Loading schedules',
tryAgain: 'Try again',
fallbackErrorMessage: 'Climate settings could not be loaded',
}
22 changes: 17 additions & 5 deletions src/lib/seam/components/DeviceTable/DeviceTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from 'lib/seam/devices/use-devices.js'
import { ContentHeader } from 'lib/ui/layout/ContentHeader.js'
import { LoadingToast } from 'lib/ui/LoadingToast/LoadingToast.js'
import { Snackbar } from 'lib/ui/Snackbar/Snackbar.js'
import { EmptyPlaceholder } from 'lib/ui/Table/EmptyPlaceholder.js'
import { TableBody } from 'lib/ui/Table/TableBody.js'
import { TableHeader } from 'lib/ui/Table/TableHeader.js'
Expand Down Expand Up @@ -77,7 +78,7 @@ export function DeviceTable({
}: DeviceTableProps = {}): JSX.Element {
useComponentTelemetry('DeviceTable')

const { devices, isInitialLoading, isError, error } = useDevices({
const { devices, isInitialLoading, isError, refetch } = useDevices({
device_ids: deviceIds,
connected_account_ids: connectedAccountIds,
})
Expand Down Expand Up @@ -120,10 +121,6 @@ export function DeviceTable({
)
}

if (isError) {
return <p className={className}>{error?.message}</p>
}

return (
<div className={classNames('seam-device-table', className)}>
<ContentHeader onBack={onBack} />
Expand Down Expand Up @@ -154,6 +151,19 @@ export function DeviceTable({
<TableBody>
<Content devices={filteredDevices} onDeviceClick={handleDeviceClick} />
</TableBody>

<Snackbar
variant='error'
visible={isError}
message={t.fallbackErrorMessage}
action={{
label: t.tryAgain,
onClick: () => {
void refetch()
},
}}
disableCloseButton
/>
</div>
)
}
Expand Down Expand Up @@ -216,4 +226,6 @@ const t = {
devices: 'Devices',
noDevicesMessage: 'Sorry, no devices were found',
loading: 'Loading devices',
tryAgain: 'Try again',
fallbackErrorMessage: 'Devices could not be loaded',
}