set header for axios - set get api bank cards
This commit is contained in:
@@ -7,13 +7,12 @@ import { ErrorComponent } from "../common/error"
|
|||||||
import { yupResolver } from '@hookform/resolvers/yup'
|
import { yupResolver } from '@hookform/resolvers/yup'
|
||||||
import { useMutation } from "@tanstack/react-query"
|
import { useMutation } from "@tanstack/react-query"
|
||||||
import { loginMutation } from "../../services/api/auth"
|
import { loginMutation } from "../../services/api/auth"
|
||||||
import { useAuthStore } from "../../store/auth-token"
|
|
||||||
import { ButtonComponent } from "../common/button"
|
import { ButtonComponent } from "../common/button"
|
||||||
import toast from "react-hot-toast"
|
import toast from "react-hot-toast"
|
||||||
|
|
||||||
export const LoginForm = () => {
|
export const LoginForm = () => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { setToken: setLoginToken } = useAuthStore()
|
|
||||||
const { mutate, isPending } = useMutation({
|
const { mutate, isPending } = useMutation({
|
||||||
mutationFn: loginMutation
|
mutationFn: loginMutation
|
||||||
})
|
})
|
||||||
@@ -30,7 +29,7 @@ export const LoginForm = () => {
|
|||||||
remember_me: true
|
remember_me: true
|
||||||
}, {
|
}, {
|
||||||
onSuccess: (data: any) => {
|
onSuccess: (data: any) => {
|
||||||
setLoginToken(data?.data?.token)
|
window.localStorage.setItem("token", data?.data?.token)
|
||||||
toast.success("با موفقیت وارد شدین")
|
toast.success("با موفقیت وارد شدین")
|
||||||
navigate("/")
|
navigate("/")
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,18 +1,30 @@
|
|||||||
import { useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { BankCartInterface } from "../../types"
|
import { BankCartInterface } from "../../types"
|
||||||
import { bankCarts } from "../../utility/cart"
|
import { bankCarts } from "../../utility/cart"
|
||||||
import { BankCart } from "./bank-cart"
|
import { BankCart } from "./bank-cart"
|
||||||
import { CreateNewCart } from "./create-new-cart"
|
import { CreateNewCart } from "./create-new-cart"
|
||||||
import { AddNewCardDialog } from "./add-new-cart-dialog"
|
import { AddNewCardDialog } from "./add-new-cart-dialog"
|
||||||
import { DeleteCardDialog } from "./delete-card"
|
import { DeleteCardDialog } from "./delete-card"
|
||||||
|
import { useQuery } from "@tanstack/react-query"
|
||||||
|
import { getUserCardsList } from "../../services/api/bank-card"
|
||||||
|
|
||||||
export const ManagementBankAccounts = () => {
|
export const ManagementBankAccounts = () => {
|
||||||
|
const { data, isLoading } = useQuery({
|
||||||
|
queryKey: ["bank-card"],
|
||||||
|
queryFn: getUserCardsList
|
||||||
|
})
|
||||||
const [showDialog, setShowDialog] = useState<boolean>(false)
|
const [showDialog, setShowDialog] = useState<boolean>(false)
|
||||||
const handleCloseDialog = () => setShowDialog(false)
|
const handleCloseDialog = () => setShowDialog(false)
|
||||||
const handleOpenDialog = () => setShowDialog(true)
|
const handleOpenDialog = () => setShowDialog(true)
|
||||||
const [showDeleteDialog, setShowDeleteDialog] = useState<boolean>(false)
|
const [showDeleteDialog, setShowDeleteDialog] = useState<boolean>(false)
|
||||||
const handleOpenDeleteDialog = () => setShowDeleteDialog(true)
|
const handleOpenDeleteDialog = () => setShowDeleteDialog(true)
|
||||||
const handleCloseDeleteDialog = () => setShowDeleteDialog(false)
|
const handleCloseDeleteDialog = () => setShowDeleteDialog(false)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log("data =>", data)
|
||||||
|
}, [data])
|
||||||
|
|
||||||
|
if (isLoading) return <p>LOADING...</p>
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="w-full grid grid-cols-1 xl:grid-cols-2 2xl:grid-cols-3 gap-6">
|
<div className="w-full grid grid-cols-1 xl:grid-cols-2 2xl:grid-cols-3 gap-6">
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import { LoginFormInterface } from "../../types";
|
||||||
|
import { axiosInstance } from "../axios";
|
||||||
|
|
||||||
|
export const getUserCardsList = () => axiosInstance.get<LoginFormInterface>("/gps/bank-card")
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
import axios, { AxiosRequestConfig } from "axios";
|
import axios, { AxiosRequestConfig } from "axios";
|
||||||
|
|
||||||
const axiosParam: AxiosRequestConfig = {
|
const axiosParam: AxiosRequestConfig = {
|
||||||
baseURL: process.env.REACT_APP_API_Address
|
baseURL: process.env.REACT_APP_API_Address,
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${window.localStorage.getItem("token")}`,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const axiosInstance = axios.create(axiosParam)
|
export const axiosInstance = axios.create(axiosParam)
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import create from 'zustand';
|
|
||||||
|
|
||||||
interface AuthState {
|
|
||||||
token: string | null;
|
|
||||||
setToken: (token: string | null) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useAuthStore = create<AuthState>((set) => ({
|
|
||||||
token: null,
|
|
||||||
setToken: (token) => set({ token }),
|
|
||||||
}));
|
|
||||||
+7
-2
@@ -2,7 +2,12 @@ import React from "react"
|
|||||||
|
|
||||||
export interface LoginFormInterface {
|
export interface LoginFormInterface {
|
||||||
username: string,
|
username: string,
|
||||||
password: string
|
password: string,
|
||||||
|
remember_me?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LoginResponseInterface {
|
||||||
|
token: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ResetPasswordInterface {
|
export interface ResetPasswordInterface {
|
||||||
@@ -136,5 +141,5 @@ export interface SubscriptionReportInterface {
|
|||||||
renewal_type: string
|
renewal_type: string
|
||||||
amount: string
|
amount: string
|
||||||
contribution: string,
|
contribution: string,
|
||||||
percentage:string
|
percentage: string
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user