From f989a0c041dd565e3d8c48cb987138f48404dd42 Mon Sep 17 00:00:00 2001 From: cue Date: Wed, 3 Apr 2024 01:33:01 +0300 Subject: [PATCH] Merge branch 'main' of https://github.com/Central-University-IT-prod/PROD-Animulichki-SkillHub --- .../components/pages/SkillTree/SkillTree.tsx | 7 ++--- .../src/components/widgets/Header/AuthAPI.ts | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/pages/SkillTree/SkillTree.tsx b/frontend/src/components/pages/SkillTree/SkillTree.tsx index e045191..15408ec 100644 --- a/frontend/src/components/pages/SkillTree/SkillTree.tsx +++ b/frontend/src/components/pages/SkillTree/SkillTree.tsx @@ -1,10 +1,9 @@ import { Input } from "../../ui/input"; -import VacancyCard from "../../entities/VacancyCard/VacancyCard"; import { Textarea } from "../../shared/ui/textarea"; import { Button } from "../../shared/ui/button"; import less from "./SkillTree.module.less" import { Switch } from "../../shared/ui/switch"; -import { addEvent, submitRegister } from "../../widgets/Header/AuthAPI"; +import { addEvent, deleteEvent, submitRegister } from "../../widgets/Header/AuthAPI"; import { Card, CardContent, @@ -62,8 +61,8 @@ const SkillTree = () => { {event.title} Дата начала: {event.start_date} - {false && ( - + {true && ( + )} diff --git a/frontend/src/components/widgets/Header/AuthAPI.ts b/frontend/src/components/widgets/Header/AuthAPI.ts index d27fcd9..fa6b506 100644 --- a/frontend/src/components/widgets/Header/AuthAPI.ts +++ b/frontend/src/components/widgets/Header/AuthAPI.ts @@ -105,3 +105,31 @@ export const addEvent = (e: FormEvent) => { console.error('Возникла ошибка с регой:', error); }); } +export const deleteEvent = (id:string) => { + + fetch(`${API_BASE}${API_EVENT}${id}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json" + }, + }) + .then(response => { + console.log(response.status); + if (response.ok) { + console.log('Удален:', response.headers.get('Location')); + window.location.reload(); + return response.json(); + } else { + return response.text().then(errorMessage => { + throw new Error('Код ошибки: ' + response.status + '. ' + errorMessage + '. Дата ошибки: ' + response.headers.get('Date')); + }); + } + }) + .then(data => { + console.log('Успешно:', data); + }) + .catch(error => { + console.error('Возникла ошибка с удалением:', error); + }); +} +