34 });
35
36 const response = await fetch(`/api/search?${params}`);
37 const data = await response.json();
38
52 const loadChatRooms = async () => {
53 try {
54 const response = await fetch('/api/chat/rooms');
55 const data = await response.json();
56 if (data.success) {
65 setLoading(true);
66 try {
67 const response = await fetch(`/api/chat/applications/${applicationId}/messages`);
68 const data = await response.json();
69 if (data.success) {
115 setSending(true);
116 try {
117 const response = await fetch(`/api/chat/applications/${currentRoom.application_id}/messages`, {
118 method: 'POST',
119 headers: { 'Content-Type': 'application/json' },
24
25 try {
26 const response = await fetch('/api/jobs', {
27 method: 'POST',
28 headers: { 'Content-Type': 'application/json' },
28 try {
29 if (showApplications && user.type === 'jobseeker') {
30 const response = await fetch('/api/jobs/my/applications');
31 const data = await response.json();
32 if (data.success) {
34 }
35 } else if (showMyJobs && user.type === 'employer') {
36 const response = await fetch('/api/jobs/my/posted');
37 const data = await response.json();
38 if (data.success) {
41 } else {
42 const url = searchQuery ? `/api/jobs?search=${encodeURIComponent(searchQuery)}` : '/api/jobs';
43 const response = await fetch(url);
44 const data = await response.json();
45 if (data.success) {
66 setApplying(true);
67 try {
68 const response = await fetch(`/api/jobs/${job.id}/apply`, {
69 method: 'POST',
70 headers: { 'Content-Type': 'application/json' },
90 const loadJobApplications = async (jobId: number) => {
91 try {
92 const response = await fetch(`/api/jobs/${jobId}/applications`);
93 const data = await response.json();
94 if (data.success) {
102 const updateApplicationStatus = async (applicationId: number, status: string) => {
103 try {
104 const response = await fetch(`/api/jobs/applications/${applicationId}/status`, {
105 method: 'PATCH',
106 headers: { 'Content-Type': 'application/json' },
31 : formData;
32
33 const response = await fetch(endpoint, {
34 method: 'POST',
35 headers: { 'Content-Type': 'application/json' },
22 const checkAuth = async () => {
23 try {
24 const response = await fetch('/api/auth/me');
25 const data = await response.json();
26 if (data.success && data.user) {
40 const handleLogout = async () => {
41 try {
42 await fetch('/api/auth/logout', { method: 'POST' });
43 setUser(null);
44 setCurrentView('jobs');
19 } catch (error) {
20 console.error("Get chat rooms error:", error);
21 return c.json<ApiResponse>({ success: false, error: "Failed to fetch chat rooms" }, 500);
22 }
23});
47 } catch (error) {
48 console.error("Get chat messages error:", error);
49 return c.json<ApiResponse>({ success: false, error: "Failed to fetch messages" }, 500);
50 }
51});
64 const loadCarriers = async () => {
65 try {
66 const response = await fetch('/api/routes/carriers');
67 const result = await response.json();
68 if (result.success) {
80
81 try {
82 const response = await fetch('/api/routes/rates', {
83 method: 'POST',
84 headers: { 'Content-Type': 'application/json' },
153 setLoading(true);
154 try {
155 const response = await fetch('/api/shipments', {
156 method: 'POST',
157 headers: { 'Content-Type': 'application/json' },
32 } catch (error) {
33 console.error("Get jobs error:", error);
34 return c.json<ApiResponse>({ success: false, error: "Failed to fetch jobs" }, 500);
35 }
36});
49 } catch (error) {
50 console.error("Get job error:", error);
51 return c.json<ApiResponse>({ success: false, error: "Failed to fetch job" }, 500);
52 }
53});
89 } catch (error) {
90 console.error("Get employer jobs error:", error);
91 return c.json<ApiResponse>({ success: false, error: "Failed to fetch jobs" }, 500);
92 }
93});
145 } catch (error) {
146 console.error("Get applications error:", error);
147 return c.json<ApiResponse>({ success: false, error: "Failed to fetch applications" }, 500);
148 }
149});
162 } catch (error) {
163 console.error("Get user applications error:", error);
164 return c.json<ApiResponse>({ success: false, error: "Failed to fetch applications" }, 500);
165 }
166});
21
22 useEffect(() => {
23 // Use initial data if available, otherwise fetch
24 if (window.__INITIAL_DATA__?.businesses) {
25 setBusinesses(window.__INITIAL_DATA__.businesses);
26 } else {
27 fetchBusinesses();
28 }
29 }, []);
30
31 const fetchBusinesses = async (params?: { q?: string; category?: string }) => {
32 setLoading(true);
33 try {
36 if (params?.category) searchParams.append('category', params.category);
37
38 const response = await fetch(`/api/businesses?${searchParams}`);
39 const result = await response.json();
40 if (result.success) {
42 }
43 } catch (error) {
44 console.error("Failed to fetch businesses:", error);
45 } finally {
46 setLoading(false);
49
50 const handleSearch = () => {
51 fetchBusinesses({
52 q: searchTerm || undefined,
53 category: selectedCategory || undefined