lint frontend
This commit is contained in:
parent
1628677222
commit
c53742d470
6 changed files with 217 additions and 207 deletions
|
|
@ -2,7 +2,7 @@ import { useForm } from 'react-hook-form';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { ModalContentProps } from '../../types';
|
import { ModalContentProps } from '../../types';
|
||||||
import { useToast } from '@/context/toasts';
|
import { useToast } from '../../context/toasts/useToast';
|
||||||
|
|
||||||
const listSchema = z.object({
|
const listSchema = z.object({
|
||||||
name: z
|
name: z
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import {
|
||||||
Checklist,
|
Checklist,
|
||||||
CommentWithUser,
|
CommentWithUser,
|
||||||
} from '../types/kanban';
|
} from '../types/kanban';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
baseURL: '/api',
|
baseURL: '/api',
|
||||||
|
|
@ -46,215 +47,224 @@ api.interceptors.response.use(
|
||||||
);
|
);
|
||||||
|
|
||||||
export function useApi() {
|
export function useApi() {
|
||||||
return {
|
return useMemo(
|
||||||
// Auth
|
() => ({
|
||||||
login: async (email: string, password: string): Promise<AuthResponse> => {
|
// Auth
|
||||||
const response = await api.post<AuthResponse>('/auth/login', {
|
login: async (email: string, password: string): Promise<AuthResponse> => {
|
||||||
email,
|
const response = await api.post<AuthResponse>('/auth/login', {
|
||||||
password,
|
email,
|
||||||
});
|
password,
|
||||||
return response.data;
|
});
|
||||||
},
|
return response.data;
|
||||||
register: async (userData: RegisterData): Promise<AuthResponse> => {
|
},
|
||||||
const response = await api.post<AuthResponse>('/auth/register', userData);
|
register: async (userData: RegisterData): Promise<AuthResponse> => {
|
||||||
return response.data;
|
const response = await api.post<AuthResponse>('/auth/register', userData);
|
||||||
},
|
return response.data;
|
||||||
getCurrentUser: async (): Promise<UserData> => {
|
},
|
||||||
const response = await api.get<UserData>('/users/me');
|
getCurrentUser: async (): Promise<UserData> => {
|
||||||
return response.data;
|
const response = await api.get<UserData>('/users/me');
|
||||||
},
|
return response.data;
|
||||||
|
},
|
||||||
|
|
||||||
// Products
|
// Products
|
||||||
getProducts: async (): Promise<ProductData[]> => {
|
getProducts: async (): Promise<ProductData[]> => {
|
||||||
const response = await api.get<ProductData[]>('/products');
|
const response = await api.get<ProductData[]>('/products');
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
getProduct: async (id: string): Promise<ProductData> => {
|
getProduct: async (id: string): Promise<ProductData> => {
|
||||||
const response = await api.get<ProductData>(`/products/${id}`);
|
const response = await api.get<ProductData>(`/products/${id}`);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
createProduct: async (productData: Omit<ProductData, 'id'>): Promise<ProductData> => {
|
createProduct: async (productData: Omit<ProductData, 'id'>): Promise<ProductData> => {
|
||||||
const response = await api.post<ProductData>('/products', productData);
|
const response = await api.post<ProductData>('/products', productData);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
updateProduct: async (id: string, productData: Partial<ProductData>): Promise<ProductData> => {
|
updateProduct: async (
|
||||||
const response = await api.put<ProductData>(`/products/${id}`, productData);
|
id: string,
|
||||||
return response.data;
|
productData: Partial<ProductData>
|
||||||
},
|
): Promise<ProductData> => {
|
||||||
deleteProduct: async (id: string): Promise<void> => {
|
const response = await api.put<ProductData>(`/products/${id}`, productData);
|
||||||
await api.delete(`/products/${id}`);
|
return response.data;
|
||||||
},
|
},
|
||||||
|
deleteProduct: async (id: string): Promise<void> => {
|
||||||
|
await api.delete(`/products/${id}`);
|
||||||
|
},
|
||||||
|
|
||||||
// Orders
|
// Orders
|
||||||
getOrders: async (): Promise<OrderData[]> => {
|
getOrders: async (): Promise<OrderData[]> => {
|
||||||
const response = await api.get<OrderData[]>('/orders');
|
const response = await api.get<OrderData[]>('/orders');
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
getOrder: async (id: string): Promise<OrderData> => {
|
getOrder: async (id: string): Promise<OrderData> => {
|
||||||
const response = await api.get<OrderData>(`/orders/${id}`);
|
const response = await api.get<OrderData>(`/orders/${id}`);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
createOrder: async (orderData: Omit<OrderData, 'id'>): Promise<OrderData> => {
|
createOrder: async (orderData: Omit<OrderData, 'id'>): Promise<OrderData> => {
|
||||||
const response = await api.post<OrderData>('/orders', orderData);
|
const response = await api.post<OrderData>('/orders', orderData);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Boards
|
// Boards
|
||||||
getBoards: async (): Promise<Board[]> => {
|
getBoards: async (): Promise<Board[]> => {
|
||||||
const response = await api.get<Board[]>('/boards');
|
const response = await api.get<Board[]>('/boards');
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
getBoard: async (id: number): Promise<BoardWithDetails> => {
|
getBoard: async (id: number): Promise<BoardWithDetails> => {
|
||||||
const response = await api.get<BoardWithDetails>(`/boards/${id}`);
|
const response = await api.get<BoardWithDetails>(`/boards/${id}`);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
createBoard: async (boardData: BoardCreate): Promise<Board> => {
|
createBoard: async (boardData: BoardCreate): Promise<Board> => {
|
||||||
const response = await api.post<Board>('/boards', boardData);
|
const response = await api.post<Board>('/boards', boardData);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
updateBoard: async (id: number, boardData: Partial<BoardCreate>): Promise<Board> => {
|
updateBoard: async (id: number, boardData: Partial<BoardCreate>): Promise<Board> => {
|
||||||
const response = await api.put<Board>(`/boards/${id}`, boardData);
|
const response = await api.put<Board>(`/boards/${id}`, boardData);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
deleteBoard: async (id: number): Promise<void> => {
|
deleteBoard: async (id: number): Promise<void> => {
|
||||||
await api.delete(`/boards/${id}`);
|
await api.delete(`/boards/${id}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Lists
|
// Lists
|
||||||
createList: async (boardId: number, listData: { name: string; pos: number }): Promise<List> => {
|
createList: async (
|
||||||
const response = await api.post<List>(`/boards/${boardId}/lists`, listData);
|
boardId: number,
|
||||||
return response.data;
|
listData: { name: string; pos: number }
|
||||||
},
|
): Promise<List> => {
|
||||||
updateList: async (
|
const response = await api.post<List>(`/boards/${boardId}/lists`, listData);
|
||||||
id: number,
|
return response.data;
|
||||||
listData: { name: string; pos: number; closed?: boolean }
|
},
|
||||||
): Promise<List> => {
|
updateList: async (
|
||||||
const response = await api.put<List>(`/lists/${id}`, listData);
|
id: number,
|
||||||
return response.data;
|
listData: { name: string; pos: number; closed?: boolean }
|
||||||
},
|
): Promise<List> => {
|
||||||
deleteList: async (id: number): Promise<void> => {
|
const response = await api.put<List>(`/lists/${id}`, listData);
|
||||||
await api.delete(`/lists/${id}`);
|
return response.data;
|
||||||
},
|
},
|
||||||
|
deleteList: async (id: number): Promise<void> => {
|
||||||
|
await api.delete(`/lists/${id}`);
|
||||||
|
},
|
||||||
|
|
||||||
// Cards
|
// Cards
|
||||||
createCard: async (
|
createCard: async (
|
||||||
listId: number,
|
listId: number,
|
||||||
cardData: {
|
cardData: {
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
pos: number;
|
pos: number;
|
||||||
due?: string | null;
|
due?: string | null;
|
||||||
due_complete?: boolean;
|
due_complete?: boolean;
|
||||||
badges?: Record<string, any>;
|
badges?: Record<string, any>;
|
||||||
cover?: Record<string, any>;
|
cover?: Record<string, any>;
|
||||||
desc_data?: Record<string, any>;
|
desc_data?: Record<string, any>;
|
||||||
}
|
}
|
||||||
): Promise<Card> => {
|
): Promise<Card> => {
|
||||||
const response = await api.post<Card>(`/lists/${listId}/cards`, cardData);
|
const response = await api.post<Card>(`/lists/${listId}/cards`, cardData);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
getCard: async (id: number): Promise<CardWithDetails> => {
|
getCard: async (id: number): Promise<CardWithDetails> => {
|
||||||
const response = await api.get<CardWithDetails>(`/cards/${id}`);
|
const response = await api.get<CardWithDetails>(`/cards/${id}`);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
updateCard: async (
|
updateCard: async (
|
||||||
id: number,
|
id: number,
|
||||||
cardData: {
|
cardData: {
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
pos: number;
|
pos: number;
|
||||||
due?: string | null;
|
due?: string | null;
|
||||||
due_complete?: boolean;
|
due_complete?: boolean;
|
||||||
closed?: boolean;
|
closed?: boolean;
|
||||||
list_id?: number;
|
list_id?: number;
|
||||||
badges?: Record<string, any>;
|
badges?: Record<string, any>;
|
||||||
cover?: Record<string, any>;
|
cover?: Record<string, any>;
|
||||||
desc_data?: Record<string, any>;
|
desc_data?: Record<string, any>;
|
||||||
}
|
}
|
||||||
): Promise<Card> => {
|
): Promise<Card> => {
|
||||||
const response = await api.put<Card>(`/cards/${id}`, cardData);
|
const response = await api.put<Card>(`/cards/${id}`, cardData);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
deleteCard: async (id: number): Promise<void> => {
|
deleteCard: async (id: number): Promise<void> => {
|
||||||
await api.delete(`/cards/${id}`);
|
await api.delete(`/cards/${id}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Labels
|
// Labels
|
||||||
getLabels: async (boardId: number): Promise<Label[]> => {
|
getLabels: async (boardId: number): Promise<Label[]> => {
|
||||||
const response = await api.get<Label[]>(`/boards/${boardId}/labels`);
|
const response = await api.get<Label[]>(`/boards/${boardId}/labels`);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
createLabel: async (
|
createLabel: async (
|
||||||
boardId: number,
|
boardId: number,
|
||||||
labelData: { name: string; color: string }
|
labelData: { name: string; color: string }
|
||||||
): Promise<Label> => {
|
): Promise<Label> => {
|
||||||
const response = await api.post<Label>(`/boards/${boardId}/labels`, labelData);
|
const response = await api.post<Label>(`/boards/${boardId}/labels`, labelData);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
addLabelToCard: async (cardId: number, labelId: number): Promise<any> => {
|
addLabelToCard: async (cardId: number, labelId: number): Promise<any> => {
|
||||||
const response = await api.post(`/cards/${cardId}/labels`, { label_id: labelId });
|
const response = await api.post(`/cards/${cardId}/labels`, { label_id: labelId });
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
removeLabelFromCard: async (cardId: number, labelId: number): Promise<void> => {
|
removeLabelFromCard: async (cardId: number, labelId: number): Promise<void> => {
|
||||||
await api.delete(`/cards/${cardId}/labels/${labelId}`);
|
await api.delete(`/cards/${cardId}/labels/${labelId}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Checklists
|
// Checklists
|
||||||
createChecklist: async (
|
createChecklist: async (
|
||||||
cardId: number,
|
cardId: number,
|
||||||
checklistData: { name: string; pos: number }
|
checklistData: { name: string; pos: number }
|
||||||
): Promise<Checklist> => {
|
): Promise<Checklist> => {
|
||||||
const response = await api.post<Checklist>(`/cards/${cardId}/checklists`, checklistData);
|
const response = await api.post<Checklist>(`/cards/${cardId}/checklists`, checklistData);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
deleteChecklist: async (id: number): Promise<void> => {
|
deleteChecklist: async (id: number): Promise<void> => {
|
||||||
await api.delete(`/checklists/${id}`);
|
await api.delete(`/checklists/${id}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Check Items
|
// Check Items
|
||||||
createCheckItem: async (
|
createCheckItem: async (
|
||||||
checklistId: number,
|
checklistId: number,
|
||||||
itemData: {
|
itemData: {
|
||||||
name: string;
|
name: string;
|
||||||
pos: number;
|
pos: number;
|
||||||
state: 'incomplete' | 'complete';
|
state: 'incomplete' | 'complete';
|
||||||
due?: string | null;
|
due?: string | null;
|
||||||
}
|
}
|
||||||
): Promise<any> => {
|
): Promise<any> => {
|
||||||
const response = await api.post(`/checklists/${checklistId}/items`, itemData);
|
const response = await api.post(`/checklists/${checklistId}/items`, itemData);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
updateCheckItem: async (
|
updateCheckItem: async (
|
||||||
id: number,
|
id: number,
|
||||||
itemData: {
|
itemData: {
|
||||||
name: string;
|
name: string;
|
||||||
pos: number;
|
pos: number;
|
||||||
state: 'incomplete' | 'complete';
|
state: 'incomplete' | 'complete';
|
||||||
due?: string | null;
|
due?: string | null;
|
||||||
}
|
}
|
||||||
): Promise<any> => {
|
): Promise<any> => {
|
||||||
const response = await api.put(`/check-items/${id}`, itemData);
|
const response = await api.put(`/check-items/${id}`, itemData);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
deleteCheckItem: async (id: number): Promise<void> => {
|
deleteCheckItem: async (id: number): Promise<void> => {
|
||||||
await api.delete(`/check-items/${id}`);
|
await api.delete(`/check-items/${id}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Comments
|
// Comments
|
||||||
getComments: async (cardId: number): Promise<CommentWithUser[]> => {
|
getComments: async (cardId: number): Promise<CommentWithUser[]> => {
|
||||||
const response = await api.get<CommentWithUser[]>(`/cards/${cardId}/comments`);
|
const response = await api.get<CommentWithUser[]>(`/cards/${cardId}/comments`);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
createComment: async (cardId: number, commentData: { text: string }): Promise<any> => {
|
createComment: async (cardId: number, commentData: { text: string }): Promise<any> => {
|
||||||
const response = await api.post(`/cards/${cardId}/comments`, commentData);
|
const response = await api.post(`/cards/${cardId}/comments`, commentData);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
updateComment: async (id: number, commentData: { text: string }): Promise<any> => {
|
updateComment: async (id: number, commentData: { text: string }): Promise<any> => {
|
||||||
const response = await api.put(`/comments/${id}`, commentData);
|
const response = await api.put(`/comments/${id}`, commentData);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
deleteComment: async (id: number): Promise<void> => {
|
deleteComment: async (id: number): Promise<void> => {
|
||||||
await api.delete(`/comments/${id}`);
|
await api.delete(`/comments/${id}`);
|
||||||
},
|
},
|
||||||
};
|
}),
|
||||||
|
[]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ export function useBoard(boardId: number) {
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}, [boardId, getBoard, withLoader, addNotification]);
|
}, [getBoard, boardId, withLoader, addNotification]);
|
||||||
|
|
||||||
const updateBoardData = (updatedBoard: BoardWithDetails) => {
|
const updateBoardData = (updatedBoard: BoardWithDetails) => {
|
||||||
setBoard(updatedBoard);
|
setBoard(updatedBoard);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { useNavigate, Link } from 'react-router-dom';
|
import { useNavigate, Link } from 'react-router-dom';
|
||||||
import { useBoards } from '../hooks/useBoards';
|
import { useBoards } from '../hooks/useBoards';
|
||||||
import { useToast } from '@/context/toasts';
|
import { useToast } from '../context/toasts/useToast';
|
||||||
|
|
||||||
const boardSchema = z.object({
|
const boardSchema = z.object({
|
||||||
name: z
|
name: z
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { useNavigate, Link, useParams } from 'react-router-dom';
|
||||||
import { useBoard } from '../hooks/useBoard';
|
import { useBoard } from '../hooks/useBoard';
|
||||||
import { useBoards } from '../hooks/useBoards';
|
import { useBoards } from '../hooks/useBoards';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useToast } from '@/context/toasts';
|
import { useToast } from '../context/toasts/useToast';
|
||||||
|
|
||||||
const boardSchema = z.object({
|
const boardSchema = z.object({
|
||||||
name: z
|
name: z
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { useAuth } from '../hooks/useAuth';
|
import { useAuth } from '../hooks/useAuth';
|
||||||
import { useToast } from '@/context/toasts';
|
import { useToast } from '../context/toasts/useToast';
|
||||||
|
|
||||||
export default function Login() {
|
export default function Login() {
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue