Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
448 changes: 78 additions & 370 deletions frontend/package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
"@chakra-ui/react": "2.8.2",
"@emotion/react": "11.11.3",
"@emotion/styled": "11.11.0",
"@tanstack/react-query": "^5.28.14",
"@tanstack/react-query-devtools": "^5.28.14",
"@tanstack/react-router": "1.19.1",
"axios": "1.6.2",
"form-data": "4.0.0",
"framer-motion": "10.16.16",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "7.49.3",
"react-icons": "5.0.1",
"react-query": "3.39.3"
"react-icons": "5.0.1"
},
"devDependencies": {
"@biomejs/biome": "1.6.1",
Expand Down
33 changes: 16 additions & 17 deletions frontend/src/components/Admin/AddUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
ModalOverlay,
} from "@chakra-ui/react"
import { type SubmitHandler, useForm } from "react-hook-form"
import { useMutation, useQueryClient } from "react-query"
import { useMutation, useQueryClient } from "@tanstack/react-query"

import { type UserCreate, UsersService } from "../../client"
import type { ApiError } from "../../client/core/ApiError"
Expand Down Expand Up @@ -53,23 +53,22 @@ const AddUser = ({ isOpen, onClose }: AddUserProps) => {
},
})

const mutation = useMutation(
(data: UserCreate) => UsersService.createUser({ requestBody: data }),
{
onSuccess: () => {
showToast("Success!", "User created successfully.", "success")
reset()
onClose()
},
onError: (err: ApiError) => {
const errDetail = (err.body as any)?.detail
showToast("Something went wrong.", `${errDetail}`, "error")
},
onSettled: () => {
queryClient.invalidateQueries("users")
},
const mutation = useMutation({
mutationFn: (data: UserCreate) =>
UsersService.createUser({ requestBody: data }),
onSuccess: () => {
showToast("Success!", "User created successfully.", "success")
reset()
onClose()
},
)
onError: (err: ApiError) => {
const errDetail = (err.body as any)?.detail
showToast("Something went wrong.", `${errDetail}`, "error")
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ["users"] })
},
})

const onSubmit: SubmitHandler<UserCreateForm> = (data) => {
mutation.mutate(data)
Expand Down
30 changes: 14 additions & 16 deletions frontend/src/components/Admin/EditUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
ModalOverlay,
} from "@chakra-ui/react"
import { type SubmitHandler, useForm } from "react-hook-form"
import { useMutation, useQueryClient } from "react-query"
import { useMutation, useQueryClient } from "@tanstack/react-query"

import {
type ApiError,
Expand Down Expand Up @@ -52,23 +52,21 @@ const EditUser = ({ user, isOpen, onClose }: EditUserProps) => {
defaultValues: user,
})

const mutation = useMutation(
(data: UserUpdateForm) =>
const mutation = useMutation({
mutationFn: (data: UserUpdateForm) =>
UsersService.updateUser({ userId: user.id, requestBody: data }),
{
onSuccess: () => {
showToast("Success!", "User updated successfully.", "success")
onClose()
},
onError: (err: ApiError) => {
const errDetail = (err.body as any)?.detail
showToast("Something went wrong.", `${errDetail}`, "error")
},
onSettled: () => {
queryClient.invalidateQueries("users")
},
onSuccess: () => {
showToast("Success!", "User updated successfully.", "success")
onClose()
},
)
onError: (err: ApiError) => {
const errDetail = (err.body as any)?.detail
showToast("Something went wrong.", `${errDetail}`, "error")
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ["users"] })
},
})

const onSubmit: SubmitHandler<UserUpdateForm> = async (data) => {
if (data.password === "") {
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/components/Common/DeleteAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@chakra-ui/react"
import React from "react"
import { useForm } from "react-hook-form"
import { useMutation, useQueryClient } from "react-query"
import { useMutation, useQueryClient } from "@tanstack/react-query"

import { ItemsService, UsersService } from "../../client"
import useCustomToast from "../../hooks/useCustomToast"
Expand Down Expand Up @@ -40,7 +40,8 @@ const Delete = ({ type, id, isOpen, onClose }: DeleteProps) => {
}
}

const mutation = useMutation(deleteEntity, {
const mutation = useMutation({
mutationFn: deleteEntity,
onSuccess: () => {
showToast(
"Success",
Expand All @@ -57,7 +58,9 @@ const Delete = ({ type, id, isOpen, onClose }: DeleteProps) => {
)
},
onSettled: () => {
queryClient.invalidateQueries(type === "Item" ? "items" : "users")
queryClient.invalidateQueries({
queryKey: [type === "Item" ? "items" : "users"],
})
},
})

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Common/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
useDisclosure,
} from "@chakra-ui/react"
import { FiLogOut, FiMenu } from "react-icons/fi"
import { useQueryClient } from "react-query"
import { useQueryClient } from "@tanstack/react-query"

import Logo from "../../assets/images/fastapi-logo.svg"
import type { UserOut } from "../../client"
Expand All @@ -25,7 +25,7 @@ const Sidebar = () => {
const bgColor = useColorModeValue("ui.light", "ui.dark")
const textColor = useColorModeValue("ui.dark", "ui.light")
const secBgColor = useColorModeValue("ui.secondary", "ui.darkSlate")
const currentUser = queryClient.getQueryData<UserOut>("currentUser")
const currentUser = queryClient.getQueryData<UserOut>(["currentUser"])
const { isOpen, onOpen, onClose } = useDisclosure()
const { logout } = useAuth()

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Common/SidebarItems.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box, Flex, Icon, Text, useColorModeValue } from "@chakra-ui/react"
import { Link } from "@tanstack/react-router"
import { FiBriefcase, FiHome, FiSettings, FiUsers } from "react-icons/fi"
import { useQueryClient } from "react-query"
import { useQueryClient } from "@tanstack/react-query"

import type { UserOut } from "../../client"

Expand All @@ -19,7 +19,7 @@ const SidebarItems = ({ onClose }: SidebarItemsProps) => {
const queryClient = useQueryClient()
const textColor = useColorModeValue("ui.main", "ui.light")
const bgActive = useColorModeValue("#E2E8F0", "#4A5568")
const currentUser = queryClient.getQueryData<UserOut>("currentUser")
const currentUser = queryClient.getQueryData<UserOut>(["currentUser"])

const finalItems = currentUser?.is_superuser
? [...items, { icon: FiUsers, title: "Admin", path: "/admin" }]
Expand Down
33 changes: 16 additions & 17 deletions frontend/src/components/Items/AddItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ModalOverlay,
} from "@chakra-ui/react"
import { type SubmitHandler, useForm } from "react-hook-form"
import { useMutation, useQueryClient } from "react-query"
import { useMutation, useQueryClient } from "@tanstack/react-query"

import { type ApiError, type ItemCreate, ItemsService } from "../../client"
import useCustomToast from "../../hooks/useCustomToast"
Expand All @@ -40,23 +40,22 @@ const AddItem = ({ isOpen, onClose }: AddItemProps) => {
},
})

const mutation = useMutation(
(data: ItemCreate) => ItemsService.createItem({ requestBody: data }),
{
onSuccess: () => {
showToast("Success!", "Item created successfully.", "success")
reset()
onClose()
},
onError: (err: ApiError) => {
const errDetail = (err.body as any)?.detail
showToast("Something went wrong.", `${errDetail}`, "error")
},
onSettled: () => {
queryClient.invalidateQueries("items")
},
const mutation = useMutation({
mutationFn: (data: ItemCreate) =>
ItemsService.createItem({ requestBody: data }),
onSuccess: () => {
showToast("Success!", "Item created successfully.", "success")
reset()
onClose()
},
)
onError: (err: ApiError) => {
const errDetail = (err.body as any)?.detail
showToast("Something went wrong.", `${errDetail}`, "error")
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ["items"] })
},
})

const onSubmit: SubmitHandler<ItemCreate> = (data) => {
mutation.mutate(data)
Expand Down
30 changes: 14 additions & 16 deletions frontend/src/components/Items/EditItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ModalOverlay,
} from "@chakra-ui/react"
import { type SubmitHandler, useForm } from "react-hook-form"
import { useMutation, useQueryClient } from "react-query"
import { useMutation, useQueryClient } from "@tanstack/react-query"

import {
type ApiError,
Expand Down Expand Up @@ -43,23 +43,21 @@ const EditItem = ({ item, isOpen, onClose }: EditItemProps) => {
defaultValues: item,
})

const mutation = useMutation(
(data: ItemUpdate) =>
const mutation = useMutation({
mutationFn: (data: ItemUpdate) =>
ItemsService.updateItem({ id: item.id, requestBody: data }),
{
onSuccess: () => {
showToast("Success!", "Item updated successfully.", "success")
onClose()
},
onError: (err: ApiError) => {
const errDetail = (err.body as any)?.detail
showToast("Something went wrong.", `${errDetail}`, "error")
},
onSettled: () => {
queryClient.invalidateQueries("items")
},
onSuccess: () => {
showToast("Success!", "Item updated successfully.", "success")
onClose()
},
)
onError: (err: ApiError) => {
const errDetail = (err.body as any)?.detail
showToast("Something went wrong.", `${errDetail}`, "error")
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ["items"] })
},
})

const onSubmit: SubmitHandler<ItemUpdate> = async (data) => {
mutation.mutate(data)
Expand Down
24 changes: 11 additions & 13 deletions frontend/src/components/UserSettings/ChangePassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
useColorModeValue,
} from "@chakra-ui/react"
import { type SubmitHandler, useForm } from "react-hook-form"
import { useMutation } from "react-query"
import { useMutation } from "@tanstack/react-query"

import { type ApiError, type UpdatePassword, UsersService } from "../../client"
import useCustomToast from "../../hooks/useCustomToast"
Expand All @@ -34,20 +34,18 @@ const ChangePassword = () => {
criteriaMode: "all",
})

const mutation = useMutation(
(data: UpdatePassword) =>
const mutation = useMutation({
mutationFn: (data: UpdatePassword) =>
UsersService.updatePasswordMe({ requestBody: data }),
{
onSuccess: () => {
showToast("Success!", "Password updated.", "success")
reset()
},
onError: (err: ApiError) => {
const errDetail = (err.body as any)?.detail
showToast("Something went wrong.", `${errDetail}`, "error")
},
onSuccess: () => {
showToast("Success!", "Password updated.", "success")
reset()
},
)
onError: (err: ApiError) => {
const errDetail = (err.body as any)?.detail
showToast("Something went wrong.", `${errDetail}`, "error")
},
})

const onSubmit: SubmitHandler<UpdatePasswordForm> = async (data) => {
mutation.mutate(data)
Expand Down
42 changes: 20 additions & 22 deletions frontend/src/components/UserSettings/DeleteConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@chakra-ui/react"
import React from "react"
import { useForm } from "react-hook-form"
import { useMutation, useQueryClient } from "react-query"
import { useMutation, useQueryClient } from "@tanstack/react-query"

import { type ApiError, type UserOut, UsersService } from "../../client"
import useAuth from "../../hooks/useAuth"
Expand All @@ -28,30 +28,28 @@ const DeleteConfirmation = ({ isOpen, onClose }: DeleteProps) => {
handleSubmit,
formState: { isSubmitting },
} = useForm()
const currentUser = queryClient.getQueryData<UserOut>("currentUser")
const currentUser = queryClient.getQueryData<UserOut>(["currentUser"])
const { logout } = useAuth()

const mutation = useMutation(
(id: number) => UsersService.deleteUser({ userId: id }),
{
onSuccess: () => {
showToast(
"Success",
"Your account has been successfully deleted.",
"success",
)
logout()
onClose()
},
onError: (err: ApiError) => {
const errDetail = (err.body as any)?.detail
showToast("Something went wrong.", `${errDetail}`, "error")
},
onSettled: () => {
queryClient.invalidateQueries("currentUser")
},
const mutation = useMutation({
mutationFn: (id: number) => UsersService.deleteUser({ userId: id }),
onSuccess: () => {
showToast(
"Success",
"Your account has been successfully deleted.",
"success",
)
logout()
onClose()
},
)
onError: (err: ApiError) => {
const errDetail = (err.body as any)?.detail
showToast("Something went wrong.", `${errDetail}`, "error")
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ["currentUser"] })
},
})

const onSubmit = async () => {
mutation.mutate(currentUser!.id)
Expand Down
Loading