'use client'; import { useMutation, useQuery } from 'react-query'; import { deleteJob, fetchJobs, updateJob } from '../../../api/api'; import { Card, Spin, Alert, Button, notification } from 'antd'; import { ExtendedJobData } from '@/types/types'; import { queryClient } from '@/fsd/app/provider/QueryClient'; import { useRouter } from 'next/navigation'; import style from './ViewVacansy.module.scss'; const ViewVacansy = () => { const router = useRouter(); const { data, error, isLoading } = useQuery( 'jobs', fetchJobs, { refetchOnWindowFocus: false, retry: false, } ); const mutation = useMutation(deleteJob, { onSuccess: () => { // Обновление списка вакансий после удаления queryClient.invalidateQueries('jobs'); }, }); const archiveMutation = useMutation( (job: ExtendedJobData) => updateJob(job.JobID, { ...job, Archive: !job.Archive, Hardskills: [], }), { onSuccess: () => { queryClient.invalidateQueries('jobs'); }, onError: () => { notification.error({ message: 'Ошибка', description: 'Не удалось снять вакансию с публикации', }); }, } ); const handleArchive = (job: ExtendedJobData) => { archiveMutation.mutate(job); }; const handleDelete = (id: number) => { mutation.mutate(id); }; const handleClick = (id: number) => { router.push(`/resume/${id}`); }; const handleEdit = (id: number) => { router.push(`/editvacansy/${id}`); }; if (isLoading) return ; if (error) { return
Нет доступных вакансий
; } // Разделение данных на активные и архивные вакансии const activeJobs = data?.filter(job => !job.Archive); const archivedJobs = data?.filter(job => job.Archive); console.log(activeJobs); return (

Активные вакансии:

{activeJobs?.map((job, index) => ( {/* Контент вакансии */}

Название компании: {job.Company_name}

Курс: {job.Year}

Квалификация:{' '} {job.Qualification ? 'Нужна' : 'Не нужна'}

Занятость (часов в неделю):{' '} {job.Time.length > 1 ? job.Time.join(', ') : job.Time[0]}

Оклад: {job.Salary} ₽

Email: {job.Email}

Обязанности: {job.Responsibilities}

))}

Архив:

{archivedJobs?.map((job, index) => ( {/* Контент вакансии */}

Курс: {job.Year}

Квалификация: {job.Qualification ? 'Yes' : 'No'}

Занятость:{' '} {job.Time.length > 1 ? job.Time.join(', ') : job.Time[0]}

Оклад: ${job.Salary}

Email: {job.Email}

Archive: {job.Archive ? 'Yes' : 'No'}

Обязанности: {job.Responsibilities}

))}
); }; export default ViewVacansy;