Skip to content
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

🎨 Format with Biome #1097

Merged
merged 1 commit into from
Mar 17, 2024
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
8 changes: 4 additions & 4 deletions frontend/modify-openapi-operationids.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as fs from 'fs'
import * as fs from "node:fs"

async function modifyOpenAPIFile(filePath) {
try {
Expand Down Expand Up @@ -26,11 +26,11 @@ async function modifyOpenAPIFile(filePath) {
filePath,
JSON.stringify(openapiContent, null, 2),
)
console.log('File successfully modified')
console.log("File successfully modified")
} catch (err) {
console.error('Error:', err)
console.error("Error:", err)
}
}

const filePath = './openapi.json'
const filePath = "./openapi.json"
modifyOpenAPIFile(filePath)
58 changes: 29 additions & 29 deletions frontend/src/components/Admin/AddUser.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import {
Button,
Checkbox,
Expand All @@ -14,13 +13,14 @@ import {
ModalFooter,
ModalHeader,
ModalOverlay,
} from '@chakra-ui/react'
import { SubmitHandler, useForm } from 'react-hook-form'
import { useMutation, useQueryClient } from 'react-query'
} from "@chakra-ui/react"
import type React from "react"
import { type SubmitHandler, useForm } from "react-hook-form"
import { useMutation, useQueryClient } from "react-query"

import { UserCreate, UsersService } from '../../client'
import { ApiError } from '../../client/core/ApiError'
import useCustomToast from '../../hooks/useCustomToast'
import { type UserCreate, UsersService } from "../../client"
import type { ApiError } from "../../client/core/ApiError"
import useCustomToast from "../../hooks/useCustomToast"

interface AddUserProps {
isOpen: boolean
Expand All @@ -41,13 +41,13 @@ const AddUser: React.FC<AddUserProps> = ({ isOpen, onClose }) => {
getValues,
formState: { errors, isSubmitting },
} = useForm<UserCreateForm>({
mode: 'onBlur',
criteriaMode: 'all',
mode: "onBlur",
criteriaMode: "all",
defaultValues: {
email: '',
full_name: '',
password: '',
confirm_password: '',
email: "",
full_name: "",
password: "",
confirm_password: "",
is_superuser: false,
is_active: false,
},
Expand All @@ -59,16 +59,16 @@ const AddUser: React.FC<AddUserProps> = ({ isOpen, onClose }) => {

const mutation = useMutation(addUser, {
onSuccess: () => {
showToast('Success!', 'User created successfully.', 'success')
showToast("Success!", "User created successfully.", "success")
reset()
onClose()
},
onError: (err: ApiError) => {
const errDetail = err.body?.detail
showToast('Something went wrong.', `${errDetail}`, 'error')
showToast("Something went wrong.", `${errDetail}`, "error")
},
onSettled: () => {
queryClient.invalidateQueries('users')
queryClient.invalidateQueries("users")
},
})

Expand All @@ -81,7 +81,7 @@ const AddUser: React.FC<AddUserProps> = ({ isOpen, onClose }) => {
<Modal
isOpen={isOpen}
onClose={onClose}
size={{ base: 'sm', md: 'md' }}
size={{ base: "sm", md: "md" }}
isCentered
>
<ModalOverlay />
Expand All @@ -93,11 +93,11 @@ const AddUser: React.FC<AddUserProps> = ({ isOpen, onClose }) => {
<FormLabel htmlFor="email">Email</FormLabel>
<Input
id="email"
{...register('email', {
required: 'Email is required',
{...register("email", {
required: "Email is required",
pattern: {
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
message: 'Invalid email address',
message: "Invalid email address",
},
})}
placeholder="Email"
Expand All @@ -111,7 +111,7 @@ const AddUser: React.FC<AddUserProps> = ({ isOpen, onClose }) => {
<FormLabel htmlFor="name">Full name</FormLabel>
<Input
id="name"
{...register('full_name')}
{...register("full_name")}
placeholder="Full name"
type="text"
/>
Expand All @@ -123,11 +123,11 @@ const AddUser: React.FC<AddUserProps> = ({ isOpen, onClose }) => {
<FormLabel htmlFor="password">Set Password</FormLabel>
<Input
id="password"
{...register('password', {
required: 'Password is required',
{...register("password", {
required: "Password is required",
minLength: {
value: 8,
message: 'Password must be at least 8 characters',
message: "Password must be at least 8 characters",
},
})}
placeholder="Password"
Expand All @@ -145,11 +145,11 @@ const AddUser: React.FC<AddUserProps> = ({ isOpen, onClose }) => {
<FormLabel htmlFor="confirm_password">Confirm Password</FormLabel>
<Input
id="confirm_password"
{...register('confirm_password', {
required: 'Please confirm your password',
{...register("confirm_password", {
required: "Please confirm your password",
validate: (value) =>
value === getValues().password ||
'The passwords do not match',
"The passwords do not match",
})}
placeholder="Password"
type="password"
Expand All @@ -162,12 +162,12 @@ const AddUser: React.FC<AddUserProps> = ({ isOpen, onClose }) => {
</FormControl>
<Flex mt={4}>
<FormControl>
<Checkbox {...register('is_superuser')} colorScheme="teal">
<Checkbox {...register("is_superuser")} colorScheme="teal">
Is superuser?
</Checkbox>
</FormControl>
<FormControl>
<Checkbox {...register('is_active')} colorScheme="teal">
<Checkbox {...register("is_active")} colorScheme="teal">
Is active?
</Checkbox>
</FormControl>
Expand Down
51 changes: 28 additions & 23 deletions frontend/src/components/Admin/EditUser.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import {
Button,
Checkbox,
Expand All @@ -14,12 +13,18 @@ import {
ModalFooter,
ModalHeader,
ModalOverlay,
} from '@chakra-ui/react'
import { SubmitHandler, useForm } from 'react-hook-form'
import { useMutation, useQueryClient } from 'react-query'
} from "@chakra-ui/react"
import type React from "react"
import { type SubmitHandler, useForm } from "react-hook-form"
import { useMutation, useQueryClient } from "react-query"

import { ApiError, UserOut, UserUpdate, UsersService } from '../../client'
import useCustomToast from '../../hooks/useCustomToast'
import {
type ApiError,
type UserOut,
type UserUpdate,
UsersService,
} from "../../client"
import useCustomToast from "../../hooks/useCustomToast"

interface EditUserProps {
user: UserOut
Expand All @@ -42,8 +47,8 @@ const EditUser: React.FC<EditUserProps> = ({ user, isOpen, onClose }) => {
getValues,
formState: { errors, isSubmitting, isDirty },
} = useForm<UserUpdateForm>({
mode: 'onBlur',
criteriaMode: 'all',
mode: "onBlur",
criteriaMode: "all",
defaultValues: user,
})

Expand All @@ -53,20 +58,20 @@ const EditUser: React.FC<EditUserProps> = ({ user, isOpen, onClose }) => {

const mutation = useMutation(updateUser, {
onSuccess: () => {
showToast('Success!', 'User updated successfully.', 'success')
showToast("Success!", "User updated successfully.", "success")
onClose()
},
onError: (err: ApiError) => {
const errDetail = err.body?.detail
showToast('Something went wrong.', `${errDetail}`, 'error')
showToast("Something went wrong.", `${errDetail}`, "error")
},
onSettled: () => {
queryClient.invalidateQueries('users')
queryClient.invalidateQueries("users")
},
})

const onSubmit: SubmitHandler<UserUpdateForm> = async (data) => {
if (data.password === '') {
if (data.password === "") {
data.password = undefined
}
mutation.mutate(data)
Expand All @@ -82,7 +87,7 @@ const EditUser: React.FC<EditUserProps> = ({ user, isOpen, onClose }) => {
<Modal
isOpen={isOpen}
onClose={onClose}
size={{ base: 'sm', md: 'md' }}
size={{ base: "sm", md: "md" }}
isCentered
>
<ModalOverlay />
Expand All @@ -94,11 +99,11 @@ const EditUser: React.FC<EditUserProps> = ({ user, isOpen, onClose }) => {
<FormLabel htmlFor="email">Email</FormLabel>
<Input
id="email"
{...register('email', {
required: 'Email is required',
{...register("email", {
required: "Email is required",
pattern: {
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
message: 'Invalid email address',
message: "Invalid email address",
},
})}
placeholder="Email"
Expand All @@ -110,16 +115,16 @@ const EditUser: React.FC<EditUserProps> = ({ user, isOpen, onClose }) => {
</FormControl>
<FormControl mt={4}>
<FormLabel htmlFor="name">Full name</FormLabel>
<Input id="name" {...register('full_name')} type="text" />
<Input id="name" {...register("full_name")} type="text" />
</FormControl>
<FormControl mt={4} isInvalid={!!errors.password}>
<FormLabel htmlFor="password">Set Password</FormLabel>
<Input
id="password"
{...register('password', {
{...register("password", {
minLength: {
value: 8,
message: 'Password must be at least 8 characters',
message: "Password must be at least 8 characters",
},
})}
placeholder="Password"
Expand All @@ -133,10 +138,10 @@ const EditUser: React.FC<EditUserProps> = ({ user, isOpen, onClose }) => {
<FormLabel htmlFor="confirm_password">Confirm Password</FormLabel>
<Input
id="confirm_password"
{...register('confirm_password', {
{...register("confirm_password", {
validate: (value) =>
value === getValues().password ||
'The passwords do not match',
"The passwords do not match",
})}
placeholder="Password"
type="password"
Expand All @@ -149,12 +154,12 @@ const EditUser: React.FC<EditUserProps> = ({ user, isOpen, onClose }) => {
</FormControl>
<Flex>
<FormControl mt={4}>
<Checkbox {...register('is_superuser')} colorScheme="teal">
<Checkbox {...register("is_superuser")} colorScheme="teal">
Is superuser?
</Checkbox>
</FormControl>
<FormControl mt={4}>
<Checkbox {...register('is_active')} colorScheme="teal">
<Checkbox {...register("is_active")} colorScheme="teal">
Is active?
</Checkbox>
</FormControl>
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/components/Common/ActionsMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import React from 'react'
import {
Button,
Menu,
MenuButton,
MenuItem,
MenuList,
useDisclosure,
} from '@chakra-ui/react'
import { BsThreeDotsVertical } from 'react-icons/bs'
import { FiEdit, FiTrash } from 'react-icons/fi'
} from "@chakra-ui/react"
import type React from "react"
import { BsThreeDotsVertical } from "react-icons/bs"
import { FiEdit, FiTrash } from "react-icons/fi"

import EditUser from '../Admin/EditUser'
import EditItem from '../Items/EditItem'
import Delete from './DeleteAlert'
import { ItemOut, UserOut } from '../../client'
import type { ItemOut, UserOut } from "../../client"
import EditUser from "../Admin/EditUser"
import EditItem from "../Items/EditItem"
import Delete from "./DeleteAlert"

interface ActionsMenuProps {
type: string
Expand Down Expand Up @@ -49,7 +49,7 @@ const ActionsMenu: React.FC<ActionsMenuProps> = ({ type, value, disabled }) => {
Delete {type}
</MenuItem>
</MenuList>
{type === 'User' ? (
{type === "User" ? (
<EditUser
user={value as UserOut}
isOpen={editUserModal.isOpen}
Expand Down
Loading