From 38a4c3961b3872a8610ce98483cdb4e1b7bd6136 Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Sat, 28 Sep 2024 16:06:46 -0300 Subject: [PATCH] chore: fix lint issues --- client/src/api-service/api.ts | 13 ++++++++++--- client/src/components/Footer/index.tsx | 2 +- client/src/views/Task/index.tsx | 13 ------------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/client/src/api-service/api.ts b/client/src/api-service/api.ts index a8fa7be..774c01a 100644 --- a/client/src/api-service/api.ts +++ b/client/src/api-service/api.ts @@ -10,18 +10,25 @@ function getToken(): string { return tokenState ?? ''; } +/** + * Retrieves all the headers for the app. + * + * @returns {Headers} the headers. + */ function getHeaders(): Headers { - const csrfToken = document.cookie.split('; ').find(row => row.startsWith('XSRF-TOKEN='))?.split('=')[1]; + const csrfToken = document.cookie.split('; ').find((row: string) => row.startsWith('XSRF-TOKEN='))?.split('=')[1]; return new Headers({ 'Content-Type': 'application/json', - 'Authorization': `Bearer ${getToken()}`, + Authorization: `Bearer ${getToken()}`, 'X-XSRF-TOKEN': csrfToken || '' }); } /** + * Handle errors for the AJAX HTTPS requests. * + * @param {number} httpStatusCode The HTTP response status code. */ function handleError(httpStatusCode: number) { if (httpStatusCode === 400) { @@ -92,7 +99,7 @@ const api = { method: 'DELETE', mode: 'cors', credentials: 'include', - headers: getHeaders(), + headers: getHeaders() }); if (response.status === 204) { return true; diff --git a/client/src/components/Footer/index.tsx b/client/src/components/Footer/index.tsx index 80547bd..205e38d 100644 --- a/client/src/components/Footer/index.tsx +++ b/client/src/components/Footer/index.tsx @@ -2,10 +2,10 @@ import React, { useContext } from 'react'; import { Button, Col, Container, Row } from 'react-bootstrap'; +import { useNavigate } from 'react-router-dom'; import { env } from '../../env'; import AuthContext from '../../context/AuthContext'; import './style.css'; -import { useNavigate } from 'react-router-dom'; /** * Footer component. diff --git a/client/src/views/Task/index.tsx b/client/src/views/Task/index.tsx index ec9b31a..0489c4f 100644 --- a/client/src/views/Task/index.tsx +++ b/client/src/views/Task/index.tsx @@ -16,7 +16,6 @@ function Task(): JSX.Element { const [formInvalid, setFormInvalid] = useState(false); const [errorMessage, setErrorMessage] = useState(''); const [tasks, setTasks] = useState([]); - const [csrfToken, setCsrfToken] = useState(''); const handleError = (e: unknown): void => { if (typeof e === 'string') { @@ -37,18 +36,6 @@ function Task(): JSX.Element { } }; - const getCsrfToken = async (): Promise => { - try { - const response = await api.getJSON(ApiConfig.csrfTokenUrl); - console.log('response token obj', response); - console.log('response token value', response.token); - console.log('response date', new Date()); - setCsrfToken(response.token); - } catch (e) { - handleError(e) - } - }; - const addTask = async (desc: string, url?: string): Promise => { const payload: TaskNoteRequest = { description: desc,