Merge branch 'main' of github.com:Central-University-IT-prod/PROD-Animulichki-SkillHub
This commit is contained in:
@@ -10,6 +10,7 @@ import { ToastAction } from "../../shared/ui/toast";
|
||||
import { useToast } from "../../shared/ui/use-toast";
|
||||
import { buttonVariants } from "../../ui/button";
|
||||
import { addEvent, submitRegister } from "../../widgets/Header/AuthAPI";
|
||||
import { addEvent, deleteEvent, submitRegister } from "../../widgets/Header/AuthAPI";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
@@ -133,3 +134,54 @@ const SkillTree = () => {
|
||||
);
|
||||
};
|
||||
export default SkillTree;
|
||||
|
||||
useEffect(() => {
|
||||
eventList()
|
||||
.then((data) => {
|
||||
setEvents(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Возникла ошибка с получением:", error);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={less["general"]}>
|
||||
<div className={less["left"]}>
|
||||
<form className={less["input-form"]} onSubmit={(event) => addEvent(event)}>
|
||||
<Input type="text" name="title" placeholder="Event name" />
|
||||
<Input type="text" name="description" placeholder="Last name" />
|
||||
<Input type="date" name="start_date" placeholder="Start date" />
|
||||
<Input type="date" name="end_date" placeholder="End date" />
|
||||
<Textarea name="description" placeholder="Description" />
|
||||
<Switch/>
|
||||
<Button>{t("buttonLoginInSystem")}</Button>
|
||||
</form>
|
||||
</div>
|
||||
<div className={less["right"]}>
|
||||
{events.map((event) => (
|
||||
<Card className={`${less["card"]} flex flex-row `}>
|
||||
<div className="flex flex-col">
|
||||
<CardHeader className={less["header"]}>
|
||||
<div className={less["up"]}>
|
||||
<CardTitle className="p-0">{event.title}</CardTitle>
|
||||
<CardDescription>Дата начала: {event.start_date}</CardDescription>
|
||||
</div>
|
||||
{true && (
|
||||
<Button size="icon" variant="ghost" onClick={() => {deleteEvent(event.id)}}><TrashIcon /></Button>
|
||||
)}
|
||||
</CardHeader>
|
||||
<CardContent className="p-0 mt-4" >
|
||||
<p>{event.description}</p>
|
||||
</CardContent>
|
||||
<Button> <Link to={`../admin/${event.id}`}>Event Management</Link></Button>
|
||||
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default SkillTree;
|
||||
|
||||
@@ -105,3 +105,31 @@ export const addEvent = (e: FormEvent<HTMLFormElement>) => {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user