Skip to content

Commit 735189f

Browse files
committed
refactor: tweaks in frontend
Includes pagination in admin, improve skeleton in admin, format and improvements in UI.
1 parent 9deace7 commit 735189f

File tree

14 files changed

+193
-126
lines changed

14 files changed

+193
-126
lines changed

frontend/src/components/Admin/AddUser.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { type SubmitHandler, useForm } from "react-hook-form"
2020
import { type UserCreate, UsersService } from "../../client"
2121
import type { ApiError } from "../../client/core/ApiError"
2222
import useCustomToast from "../../hooks/useCustomToast"
23-
import { emailPattern } from "../../utils"
23+
import { emailPattern, handleError } from "../../utils"
2424

2525
interface AddUserProps {
2626
isOpen: boolean
@@ -62,8 +62,7 @@ const AddUser = ({ isOpen, onClose }: AddUserProps) => {
6262
onClose()
6363
},
6464
onError: (err: ApiError) => {
65-
const errDetail = (err.body as any)?.detail
66-
showToast("Something went wrong.", `${errDetail}`, "error")
65+
handleError(err, showToast)
6766
},
6867
onSettled: () => {
6968
queryClient.invalidateQueries({ queryKey: ["users"] })

frontend/src/components/Admin/EditUser.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
UsersService,
2525
} from "../../client"
2626
import useCustomToast from "../../hooks/useCustomToast"
27-
import { emailPattern } from "../../utils"
27+
import { emailPattern, handleError } from "../../utils"
2828

2929
interface EditUserProps {
3030
user: UserPublic
@@ -60,8 +60,7 @@ const EditUser = ({ user, isOpen, onClose }: EditUserProps) => {
6060
onClose()
6161
},
6262
onError: (err: ApiError) => {
63-
const errDetail = (err.body as any)?.detail
64-
showToast("Something went wrong.", `${errDetail}`, "error")
63+
handleError(err, showToast)
6564
},
6665
onSettled: () => {
6766
queryClient.invalidateQueries({ queryKey: ["users"] })

frontend/src/components/Items/AddItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { type SubmitHandler, useForm } from "react-hook-form"
1717

1818
import { type ApiError, type ItemCreate, ItemsService } from "../../client"
1919
import useCustomToast from "../../hooks/useCustomToast"
20+
import { handleError } from "../../utils"
2021

2122
interface AddItemProps {
2223
isOpen: boolean
@@ -49,8 +50,7 @@ const AddItem = ({ isOpen, onClose }: AddItemProps) => {
4950
onClose()
5051
},
5152
onError: (err: ApiError) => {
52-
const errDetail = (err.body as any)?.detail
53-
showToast("Something went wrong.", `${errDetail}`, "error")
53+
handleError(err, showToast)
5454
},
5555
onSettled: () => {
5656
queryClient.invalidateQueries({ queryKey: ["items"] })

frontend/src/components/Items/EditItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
ItemsService,
2323
} from "../../client"
2424
import useCustomToast from "../../hooks/useCustomToast"
25+
import { handleError } from "../../utils"
2526

2627
interface EditItemProps {
2728
item: ItemPublic
@@ -51,8 +52,7 @@ const EditItem = ({ item, isOpen, onClose }: EditItemProps) => {
5152
onClose()
5253
},
5354
onError: (err: ApiError) => {
54-
const errDetail = (err.body as any)?.detail
55-
showToast("Something went wrong.", `${errDetail}`, "error")
55+
handleError(err, showToast)
5656
},
5757
onSettled: () => {
5858
queryClient.invalidateQueries({ queryKey: ["items"] })

frontend/src/components/UserSettings/ChangePassword.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { type SubmitHandler, useForm } from "react-hook-form"
1414

1515
import { type ApiError, type UpdatePassword, UsersService } from "../../client"
1616
import useCustomToast from "../../hooks/useCustomToast"
17-
import { confirmPasswordRules, passwordRules } from "../../utils"
17+
import { confirmPasswordRules, handleError, passwordRules } from "../../utils"
1818

1919
interface UpdatePasswordForm extends UpdatePassword {
2020
confirm_password: string
@@ -42,8 +42,7 @@ const ChangePassword = () => {
4242
reset()
4343
},
4444
onError: (err: ApiError) => {
45-
const errDetail = (err.body as any)?.detail
46-
showToast("Something went wrong.", `${errDetail}`, "error")
45+
handleError(err, showToast)
4746
},
4847
})
4948

frontend/src/components/UserSettings/DeleteConfirmation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useForm } from "react-hook-form"
1414
import { type ApiError, UsersService } from "../../client"
1515
import useAuth from "../../hooks/useAuth"
1616
import useCustomToast from "../../hooks/useCustomToast"
17+
import { handleError } from "../../utils"
1718

1819
interface DeleteProps {
1920
isOpen: boolean
@@ -42,8 +43,7 @@ const DeleteConfirmation = ({ isOpen, onClose }: DeleteProps) => {
4243
onClose()
4344
},
4445
onError: (err: ApiError) => {
45-
const errDetail = (err.body as any)?.detail
46-
showToast("Something went wrong.", `${errDetail}`, "error")
46+
handleError(err, showToast)
4747
},
4848
onSettled: () => {
4949
queryClient.invalidateQueries({ queryKey: ["currentUser"] })

frontend/src/components/UserSettings/UserInformation.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from "../../client"
2424
import useAuth from "../../hooks/useAuth"
2525
import useCustomToast from "../../hooks/useCustomToast"
26-
import { emailPattern } from "../../utils"
26+
import { emailPattern, handleError } from "../../utils"
2727

2828
const UserInformation = () => {
2929
const queryClient = useQueryClient()
@@ -57,13 +57,10 @@ const UserInformation = () => {
5757
showToast("Success!", "User updated successfully.", "success")
5858
},
5959
onError: (err: ApiError) => {
60-
const errDetail = (err.body as any)?.detail
61-
showToast("Something went wrong.", `${errDetail}`, "error")
60+
handleError(err, showToast)
6261
},
6362
onSettled: () => {
64-
// TODO: can we do just one call now?
65-
queryClient.invalidateQueries({ queryKey: ["users"] })
66-
queryClient.invalidateQueries({ queryKey: ["currentUser"] })
63+
queryClient.invalidateQueries()
6764
},
6865
})
6966

@@ -104,6 +101,8 @@ const UserInformation = () => {
104101
size="md"
105102
py={2}
106103
color={!currentUser?.full_name ? "ui.dim" : "inherit"}
104+
isTruncated
105+
maxWidth="250px"
107106
>
108107
{currentUser?.full_name || "N/A"}
109108
</Text>
@@ -125,7 +124,7 @@ const UserInformation = () => {
125124
w="auto"
126125
/>
127126
) : (
128-
<Text size="md" py={2}>
127+
<Text size="md" py={2} isTruncated maxWidth="250px">
129128
{currentUser?.email}
130129
</Text>
131130
)}

frontend/src/hooks/useAuth.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ const useAuth = () => {
3434

3535
onSuccess: () => {
3636
navigate({ to: "/login" })
37-
showToast("Account created.", "Your account has been created successfully.", "success")
37+
showToast(
38+
"Account created.",
39+
"Your account has been created successfully.",
40+
"success",
41+
)
3842
},
3943
onError: (err: ApiError) => {
4044
let errDetail = (err.body as any)?.detail
@@ -43,7 +47,7 @@ const useAuth = () => {
4347
errDetail = err.message
4448
}
4549

46-
showToast("Something went wrong.", `${errDetail}`, "error")
50+
showToast("Something went wrong.", errDetail, "error")
4751
},
4852
onSettled: () => {
4953
queryClient.invalidateQueries({ queryKey: ["users"] })

0 commit comments

Comments
 (0)