added refresh token
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useCallback } from 'react';
|
||||
import { API_URL } from '../config/authConstants';
|
||||
import { apiFetch } from '../api/apiClient';
|
||||
|
||||
/**
|
||||
* Хук для изменения статуса поста (ACTIVE/CLOSED).
|
||||
@@ -9,21 +10,13 @@ export function usePostStatus() {
|
||||
/**
|
||||
* Изменяет статус поста на CLOSED (вещь найдена).
|
||||
* @param {number} postId - ID поста
|
||||
* @param {string} token - JWT токен авторизации
|
||||
* @returns {Promise<boolean>} - true если операция успешна
|
||||
*/
|
||||
const markAsFound = useCallback(async (postId, token) => {
|
||||
if (!token) {
|
||||
console.warn('Cannot mark post as found: no token');
|
||||
return false;
|
||||
}
|
||||
|
||||
const markAsFound = useCallback(async (postId) => {
|
||||
try {
|
||||
// Используем PATCH endpoint для обновления статуса
|
||||
const response = await fetch(`${API_URL}/api/v1/posts/${postId}/status`, {
|
||||
const response = await apiFetch(`${API_URL}/api/v1/posts/${postId}/status`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ status: 'CLOSED' }),
|
||||
@@ -43,20 +36,13 @@ export function usePostStatus() {
|
||||
/**
|
||||
* Возвращает статус поста в ACTIVE (если нужно reopen).
|
||||
* @param {number} postId - ID поста
|
||||
* @param {string} token - JWT токен авторизации
|
||||
* @returns {Promise<boolean>} - true если операция успешна
|
||||
*/
|
||||
const reopenPost = useCallback(async (postId, token) => {
|
||||
if (!token) {
|
||||
console.warn('Cannot reopen post: no token');
|
||||
return false;
|
||||
}
|
||||
|
||||
const reopenPost = useCallback(async (postId) => {
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/api/v1/posts/${postId}/status`, {
|
||||
const response = await apiFetch(`${API_URL}/api/v1/posts/${postId}/status`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ status: 'ACTIVE' }),
|
||||
@@ -77,4 +63,4 @@ export function usePostStatus() {
|
||||
markAsFound,
|
||||
reopenPost,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user