add lint js
This commit is contained in:
@@ -6,8 +6,8 @@ import React, {
|
||||
useContext,
|
||||
useEffect,
|
||||
useState
|
||||
} from "react";
|
||||
import axios from "axios";
|
||||
} from "react"
|
||||
import axios from "axios"
|
||||
|
||||
const AuthUserContext = createContext<AuthUserProps|undefined>(undefined)
|
||||
|
||||
@@ -28,7 +28,7 @@ export const AuthUserProvider = ({children}: PropsWithChildren) => {
|
||||
const res = await axios.get('/api/user')
|
||||
setAuthUser(res.data)
|
||||
} catch (e) {
|
||||
// @ts-ignore
|
||||
// @ts-expect-error check axios response status
|
||||
if (e.response.status === 401) {
|
||||
console.info('no user login')
|
||||
if (window.location.pathname !== '/connexion') {
|
||||
@@ -44,7 +44,7 @@ export const AuthUserProvider = ({children}: PropsWithChildren) => {
|
||||
const logout = async () => {
|
||||
try {
|
||||
setLoadingAuthUser(false)
|
||||
const res = await axios.delete('/api/logout')
|
||||
await axios.delete('/api/logout')
|
||||
setAuthUser(null)
|
||||
window.location.replace('/')
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,29 +1,31 @@
|
||||
import {useState} from "react";
|
||||
import axios from "axios";
|
||||
import React from "react";
|
||||
import {cleanErrorsForm, displayFormErrors} from "../utilities/form";
|
||||
import {useState} from "react"
|
||||
import axios, {AxiosError} from "axios"
|
||||
import React from "react"
|
||||
import {cleanErrorsForm, displayFormErrors, ValidationErrors} from "../utilities/form"
|
||||
|
||||
const useAxiosTools = () => {
|
||||
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState<string|null>(null)
|
||||
const [error, setError] = useState<string|null|undefined>(null)
|
||||
|
||||
const axiosGet = axios.get
|
||||
const axiosPost = axios.post
|
||||
const axiosPut = axios.put
|
||||
const axiosDelete = axios.delete
|
||||
|
||||
const errorCatch = (error: any) => {
|
||||
if (error.response && error.response.status === 422) {
|
||||
displayFormErrors(error)
|
||||
} else {
|
||||
setError(error.response?.data.message || error.message)
|
||||
const errorCatch = (error: Error|AxiosError|unknown) => {
|
||||
if (axios.isAxiosError(error)) {
|
||||
(error.response?.status === 422)
|
||||
? displayFormErrors(error)
|
||||
: setError(error.response?.data.message || error.message)
|
||||
} else if (error instanceof Error) {
|
||||
setError(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
const errorLabel = () => {
|
||||
|
||||
return error ? <div className="bg-red-600 rounded m-2 text-center text-white px-2 py-1 mx-auto">{error}</div>: null
|
||||
return error ? <div className="m-2 mx-auto rounded bg-red-600 px-2 py-1 text-center text-white">{error}</div>: null
|
||||
}
|
||||
|
||||
const cleanErrors = () => {
|
||||
|
||||
@@ -4,12 +4,13 @@ const useDimension = () => {
|
||||
|
||||
const RESET_TIMEOUT = 300
|
||||
let movement_timer: number|undefined = undefined
|
||||
const targetRef = useRef<any>()
|
||||
const targetRef = useRef<HTMLDivElement>()
|
||||
const [dimensions, setDimensions] = useState({ width:0, height: 0 })
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener('resize', ()=>{
|
||||
clearInterval(movement_timer)
|
||||
// @ts-expect-error setTimeout defined in var
|
||||
movement_timer = setTimeout(testDimensions, RESET_TIMEOUT)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user