♻️ Refactor and tweaks, rename UserCreateOpen to UserRegister and others (#1143)

This commit is contained in:
Alejandra
2024-04-01 22:53:33 -05:00
committed by GitHub
parent aed4db7521
commit 4239d93ea6
45 changed files with 537 additions and 518 deletions

View File

@@ -73,7 +73,7 @@ function Admin() {
<Tbody>
{users.data.map((user) => (
<Tr key={user.id}>
<Td color={!user.full_name ? "gray.400" : "inherit"}>
<Td color={!user.full_name ? "ui.dim" : "inherit"}>
{user.full_name || "N/A"}
{currentUser?.id === user.id && (
<Badge ml="1" colorScheme="teal">

View File

@@ -70,7 +70,7 @@ function Items() {
<Tr key={item.id}>
<Td>{item.id}</Td>
<Td>{item.title}</Td>
<Td color={!item.description ? "gray.400" : "inherit"}>
<Td color={!item.description ? "ui.dim" : "inherit"}>
{item.description || "N/A"}
</Td>
<Td>

View File

@@ -18,11 +18,9 @@ import {
createFileRoute,
redirect,
} from "@tanstack/react-router"
import React from "react"
import { type SubmitHandler, useForm } from "react-hook-form"
import Logo from "../assets/images/fastapi-logo.svg"
import type { ApiError } from "../client"
import type { Body_login_login_access_token as AccessToken } from "../client/models/Body_login_login_access_token"
import useAuth, { isLoggedIn } from "../hooks/useAuth"
import { emailPattern } from "../utils"
@@ -40,8 +38,7 @@ export const Route = createFileRoute("/login")({
function Login() {
const [show, setShow] = useBoolean()
const { login } = useAuth()
const [error, setError] = React.useState<string | null>(null)
const { loginMutation, error } = useAuth()
const {
register,
handleSubmit,
@@ -56,12 +53,7 @@ function Login() {
})
const onSubmit: SubmitHandler<AccessToken> = async (data) => {
try {
await login(data)
} catch (err) {
const errDetail = (err as ApiError).body.detail
setError(errDetail)
}
loginMutation.mutate(data)
}
return (
@@ -105,7 +97,7 @@ function Login() {
placeholder="Password"
/>
<InputRightElement
color="gray.400"
color="ui.dim"
_hover={{
cursor: "pointer",
}}

View File

@@ -15,6 +15,7 @@ import { useMutation } from "react-query"
import { type ApiError, LoginService, type NewPassword } from "../client"
import { isLoggedIn } from "../hooks/useAuth"
import useCustomToast from "../hooks/useCustomToast"
import { confirmPasswordRules, passwordRules } from "../utils"
interface NewPasswordForm extends NewPassword {
confirm_password: string
@@ -93,13 +94,7 @@ function ResetPassword() {
<FormLabel htmlFor="password">Set Password</FormLabel>
<Input
id="password"
{...register("new_password", {
required: "Password is required",
minLength: {
value: 8,
message: "Password must be at least 8 characters",
},
})}
{...register("new_password", passwordRules())}
placeholder="Password"
type="password"
/>
@@ -111,12 +106,7 @@ function ResetPassword() {
<FormLabel htmlFor="confirm_password">Confirm Password</FormLabel>
<Input
id="confirm_password"
{...register("confirm_password", {
required: "Please confirm your password",
validate: (value) =>
value === getValues().new_password ||
"The passwords do not match",
})}
{...register("confirm_password", confirmPasswordRules(getValues))}
placeholder="Password"
type="password"
/>