Renamed hooks on frontend and started working on shop registration

This commit is contained in:
Thastertyn committed 2025-03-13 15:41:44 +01:00
1 parent 3b42ea6914
commit 9c2b88b103
35 files changed
+180 -37

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
import { useToast } from "@/hooks/use-toast";
import { useToast } from "@/hooks/useToast";
import {
Toast,
ToastClose,
View File
Whitespace-only changes.
+77
View File
@@ -0,0 +1,77 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
import { useNavigate } from "@tanstack/react-router"
import { useState } from "react"
import {
type BodyLoginLoginAccessToken as AccessToken,
type ApiError,
LoginService,
type UserPublic,
type UserRegister,
UsersService,
} from "@/client"
import { handleError } from "@/utils"
const isLoggedIn = () => {
return localStorage.getItem("access_token") !== null
}
const useAuth = () => {
const [error, setError] = useState<string | null>(null)
const navigate = useNavigate()
const queryClient = useQueryClient()
const { data: user } = useQuery<UserPublic | null, Error>({
queryKey: ["currentUser"],
queryFn: UsersService.readUserMe,
enabled: isLoggedIn(),
})
const signUpMutation = useMutation({
mutationFn: (data: UserRegister) =>
UsersService.registerUser({ requestBody: data }),
onSuccess: () => {
navigate({ to: "/login" })
},
onError: (err: ApiError) => {
handleError(err)
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ["users"] })
},
})
const login = async (data: AccessToken) => {
const response = await LoginService.loginAccessToken({
formData: data,
})
localStorage.setItem("access_token", response.access_token)
}
const loginMutation = useMutation({
mutationFn: login,
onSuccess: () => {
navigate({ to: "/" })
},
onError: (err: ApiError) => {
handleError(err)
},
})
const logout = () => {
localStorage.removeItem("access_token")
navigate({ to: "/login" })
}
return {
signUpMutation,
loginMutation,
logout,
user,
error,
resetError: () => setError(null),
}
}
export { isLoggedIn }
export default useAuth
File renamed without changes.
File renamed without changes.
+1 -1
View File
@@ -9,7 +9,7 @@ import {
import { RouterProvider, createRouter } from "@tanstack/react-router";
import { useAuthStore } from "@/stores/authStore";
import { handleServerError } from "@/utils/handle-server-error";
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
import { FontProvider } from "./context/font-context";
import { ThemeProvider } from "./context/theme-context";
import "./index.css";
@@ -4,7 +4,7 @@ import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useNavigate } from "@tanstack/react-router";
import { cn } from "@/lib/utils";
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
import { Button } from "@/components/ui/button";
import {
Form,
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import { IconCheck, IconX } from "@tabler/icons-react";
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import {
@@ -4,7 +4,7 @@ import { useForm } from "react-hook-form";
import { CalendarIcon, CaretSortIcon, CheckIcon } from "@radix-ui/react-icons";
import { zodResolver } from "@hookform/resolvers/zod";
import { cn } from "@/lib/utils";
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
import { Button } from "@/components/ui/button";
import { Calendar } from "@/components/ui/calendar";
import {
@@ -6,7 +6,7 @@ import { fonts } from "@/config/fonts";
import { cn } from "@/lib/utils";
import { useFont } from "@/context/font-context";
import { useTheme } from "@/context/theme-context";
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
import { Button, buttonVariants } from "@/components/ui/button";
import {
Form,
@@ -1,7 +1,7 @@
import { z } from "zod";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import {
@@ -2,7 +2,7 @@ import { z } from "zod";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { Link } from "@tanstack/react-router";
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import {
@@ -3,7 +3,7 @@ import { useFieldArray, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { Link } from "@tanstack/react-router";
import { cn } from "@/lib/utils";
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
import { Button } from "@/components/ui/button";
import {
Form,
@@ -1,4 +1,4 @@
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
import { ConfirmDialog } from "@/components/confirm-dialog";
import { useTasks } from "../context/tasks-context";
import { TasksImportDialog } from "./tasks-import-dialog";
@@ -1,7 +1,7 @@
import { z } from "zod";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
import { Button } from "@/components/ui/button";
import {
Dialog,
@@ -1,7 +1,7 @@
import { z } from "zod";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
import { Button } from "@/components/ui/button";
import {
Form,
@@ -1,5 +1,5 @@
import React, { useState } from "react";
import useDialogState from "@/hooks/use-dialog-state";
import useDialogState from "@/hooks/useDialogState";
import { Task } from "../data/schema";
type TasksDialogType = "create" | "update" | "delete" | "import";
@@ -3,7 +3,7 @@
import { z } from "zod";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
import { Button } from "@/components/ui/button";
import {
Dialog,
@@ -2,7 +2,7 @@
import { useState } from "react";
import { IconAlertTriangle } from "@tabler/icons-react";
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
@@ -2,7 +2,7 @@ import { z } from "zod";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { IconMailPlus, IconSend } from "@tabler/icons-react";
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
import { Button } from "@/components/ui/button";
import {
Dialog,
@@ -1,5 +1,5 @@
import React, { useState } from "react";
import useDialogState from "@/hooks/use-dialog-state";
import useDialogState from "@/hooks/useDialogState";
import { User } from "../data/schema";
type UsersDialogType = "invite" | "add" | "edit" | "delete";
+1 -1
View File
@@ -1,5 +1,5 @@
import { AxiosError } from "axios";
import { toast } from "@/hooks/use-toast";
import { toast } from "@/hooks/useToast";
export function handleServerError(error: unknown) {
// eslint-disable-next-line no-console