Skip to content

Commit ab5f160

Browse files
committed
refactor: Move error to UsersPage component
1 parent fa5eae5 commit ab5f160

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

site/src/pages/UsersPage/UsersPage.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useActor } from "@xstate/react"
22
import React, { useContext, useEffect } from "react"
33
import { useNavigate } from "react-router"
44
import { ConfirmDialog } from "../../components/ConfirmDialog/ConfirmDialog"
5-
import { ErrorSummary } from "../../components/ErrorSummary/ErrorSummary"
65
import { FullScreenLoader } from "../../components/Loader/FullScreenLoader"
76
import { XServiceContext } from "../../xServices/StateContext"
87
import { UsersPageView } from "./UsersPageView"
@@ -26,10 +25,6 @@ export const UsersPage: React.FC = () => {
2625
usersSend("GET_USERS")
2726
}, [usersSend])
2827

29-
if (usersState.matches("error")) {
30-
return <ErrorSummary error={getUsersError} />
31-
}
32-
3328
if (!users) {
3429
return <FullScreenLoader />
3530
} else {
@@ -43,6 +38,7 @@ export const UsersPage: React.FC = () => {
4338
onSuspendUser={(user) => {
4439
usersSend({ type: "SUSPEND_USER", userId: user.id })
4540
}}
41+
error={getUsersError}
4642
/>
4743

4844
<ConfirmDialog

site/src/pages/UsersPage/UsersPageView.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Paper from "@material-ui/core/Paper"
22
import { makeStyles } from "@material-ui/core/styles"
33
import React from "react"
44
import { UserResponse } from "../../api/types"
5+
import { ErrorSummary } from "../../components/ErrorSummary/ErrorSummary"
56
import { Header } from "../../components/Header/Header"
67
import { UsersTable } from "../../components/UsersTable/UsersTable"
78

@@ -14,16 +15,22 @@ export interface UsersPageViewProps {
1415
users: UserResponse[]
1516
openUserCreationDialog: () => void
1617
onSuspendUser: (user: UserResponse) => void
18+
error?: unknown
1719
}
1820

19-
export const UsersPageView: React.FC<UsersPageViewProps> = ({ users, openUserCreationDialog, onSuspendUser }) => {
21+
export const UsersPageView: React.FC<UsersPageViewProps> = ({
22+
users,
23+
openUserCreationDialog,
24+
onSuspendUser,
25+
error,
26+
}) => {
2027
const styles = useStyles()
2128

2229
return (
2330
<div className={styles.flexColumn}>
2431
<Header title={Language.pageTitle} action={{ text: Language.newUserButton, onClick: openUserCreationDialog }} />
2532
<Paper style={{ maxWidth: "1380px", margin: "1em auto", width: "100%" }}>
26-
<UsersTable users={users} onSuspendUser={onSuspendUser} />
33+
{error ? <ErrorSummary error={error} /> : <UsersTable users={users} onSuspendUser={onSuspendUser} />}
2734
</Paper>
2835
</div>
2936
)

0 commit comments

Comments
 (0)