Skip to content

Commit

Permalink
Fix api
Browse files Browse the repository at this point in the history
  • Loading branch information
Notsmartname committed May 13, 2024
1 parent 733e909 commit 3b37135
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
13 changes: 8 additions & 5 deletions src/modules/AboutShelter/AboutShelter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@ import EditIcon from '../../images/EditIcon/EditIcon';
import DeleteIcon from '../../images/DeleteIcon/DeleteIcon';
import ShelterOwnerStatistics from '../ShelterOwnerStatistics/ShelterOwnerStatistics';
import petLogo from '../../images/pet.jpg';
import setPayment from './api';
import { setPayment } from './api';

// TODO переделать названия классов (объединить?), не совсем понятно, по какому принципу about-shelter, shelter-info

const AboutShelter = () => {
const { shelter, isOwner, isLoading } = useOutletContext();
console.log(shelter);
if (isLoading) {
return null;
}

// TODO подключить рероутер на редактирование инфо о приюте (6.2.1.4 в фигме)
// TODO сделать попап при удалении приюта (6.2.1.3 в фигме)

const handleSetPayment = () => {
// let token = localStorage.getItem('access');
setPayment(localStorage.getItem('access'));
const handleSetPayment = async () => {
try {
const paymentConfirmUrl = await setPayment();
window.open(paymentConfirmUrl, '_blank');
} catch (error) {
throw new Error(error.message);
}
};

return (
Expand Down
38 changes: 20 additions & 18 deletions src/modules/AboutShelter/api.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { baseUrl } from '../../utils/constants';
import { baseUrl, apiHeaders } from '../../utils/constants';

const setPayment = async (token) => {
// Перенаправить на страницу OAuth-сервера ЮKassa
const response = await fetch(`${baseUrl}/v1/payments/get-partner-link/`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
authorization: `Bearer ${token}`,
},
redirect: 'follow'
}).then(
console.log('OK')
);
// eslint-disable-next-line
export const setPayment = async (id, amount) => {
try {
if (localStorage.getItem('access')) {
const token = localStorage.getItem('access');
apiHeaders.authorization = `Bearer ${token}`;
}
const response = await fetch(`${baseUrl}/v1/payments/get-partner-link/`, {
method: 'GET',
headers: apiHeaders,
});

if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
if (response.ok) {
const data = await response.json();
delete apiHeaders.authorization;
return data.partner_link;
}
throw new Error('Ошибка при отправке запроса');
} catch (error) {
throw new Error('Ошибка:', error);
}

};
export default setPayment;

0 comments on commit 3b37135

Please sign in to comment.