This commit is contained in:
Iliyan Angelov
2025-10-07 22:10:27 +03:00
parent 3f5bcfad68
commit d48c54e2c5
3221 changed files with 40187 additions and 92575 deletions

View File

@@ -0,0 +1,95 @@
import { useState, useEffect } from 'react';
import { careerService, JobPosition } from '../api/careerService';
/**
* Custom hook to fetch all job positions
*/
export const useJobs = () => {
const [jobs, setJobs] = useState<JobPosition[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const fetchJobs = async () => {
try {
setLoading(true);
const data = await careerService.getAllJobs();
setJobs(data);
setError(null);
} catch (err) {
setError(err instanceof Error ? err.message : 'An error occurred');
console.error('Error fetching jobs:', err);
} finally {
setLoading(false);
}
};
fetchJobs();
}, []);
return { jobs, loading, error };
};
/**
* Custom hook to fetch a single job by slug
*/
export const useJob = (slug: string) => {
const [job, setJob] = useState<JobPosition | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (!slug) {
setLoading(false);
return;
}
const fetchJob = async () => {
try {
setLoading(true);
const data = await careerService.getJobBySlug(slug);
setJob(data);
setError(null);
} catch (err) {
setError(err instanceof Error ? err.message : 'An error occurred');
console.error('Error fetching job:', err);
} finally {
setLoading(false);
}
};
fetchJob();
}, [slug]);
return { job, loading, error };
};
/**
* Custom hook to fetch featured jobs
*/
export const useFeaturedJobs = () => {
const [jobs, setJobs] = useState<JobPosition[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const fetchFeaturedJobs = async () => {
try {
setLoading(true);
const data = await careerService.getFeaturedJobs();
setJobs(data);
setError(null);
} catch (err) {
setError(err instanceof Error ? err.message : 'An error occurred');
console.error('Error fetching featured jobs:', err);
} finally {
setLoading(false);
}
};
fetchFeaturedJobs();
}, []);
return { jobs, loading, error };
};